to reproduce, run `echo て`, then select just the て character. it doesn't copy automatically. a related issue shows up with 'x̊x'.
seems to be a mismatch between how the Selection object counts chars and how hterm.Terminal.prototype.getSelectionText counts chars. specifically, Selection counts UTF-16 codeunits (so 'て'.length == 1 and '𠦝'.length == 2), while hterm.Terminal.prototype.getSelectionText operates on display columns. this translation is mostly handled by walking the nodes and adding up their widths (see the "offset += hterm.TextAttributes.nodeWidth(node)" while loops), but there is a mismatch here:
// End offset measures from the end of the line.
var endOffset = (hterm.TextAttributes.nodeWidth(selection.endNode) -
selection.endOffset);
in the case of the wide char above, selection.endOffset will be 1 as in one codeunit, but we're using it in a calculation that returns the number of columns (2 here). the final calculation is:
return lib.wc.substring(rv, startOffset, lib.wc.strWidth(rv) - endOffset);
which collapses down to:
return lib.wc.substring('て', 0, 2 - 1);
which returns and empty string. and the copy buffer ends up doing nothing.
when using combining characters like 'x̊', selection.endOffset will be 2 (since there are two codeunits here), which means we end up calculating past the point and sucking up an extra column after the selection. e.g. if the row was 'x̊x', instead of copying 'x̊', it'd over extend and get 'x̊x'. if that trailing 'x' wasn't there, then our intermediate endOffset calculation would have started off at -1. add more combining characters and it throws things off even more.
the startOffset has the same problems in that selection.startOffset is in codeunits, but we later add column counts to it. this issue doesn't seem to come up because Chrome doesn't allow selections in the middle of graphemes, so the starting point is always at a "good" place. if Chrome did offer a method (like being able to select the combining character in 'x̊' but not the 'x' itself), then this would fall apart.
Comment 1 by sheriffbot@chromium.org
, Oct 26Status: Untriaged (was: Available)