Open Aloso opened 3 years ago
That's a known issue, except the part which crosses the screen on the left. It's to do with highlight_runs.
As for tab stops, those are zero-width glyphs, thus there's nothing to highlight. Some workaround is needed.
There's a similar problem with glyphs from a different script like Arabic; the selection rect height is wrong since the glyph height doesn't match the primary font's line height.
I was playing around with right-to-left selection, and got the text and selection colors to desync. Is this a known bug?
I'd guess it's the same bug (or at least, bugs in the same rectangle generation logic).
By the way, I don't consider fixing this a priority since most of the time it's usable enough, and fixing it properly will require more substantial changes to kas-text: (1) tab stops and the extra gaps between words used for justified text are not actual characters, (2) glyphs from different fonts may have different line heights at the same size, (3) bidirectional text support implies that the lexical start/end of a line isn't always at a (geometric) end of the line.
That said, fixing at least some parts of this issue probably isn't so hard (e.g. merging selection rectangles where there is no other items between them).
(In retrospect, I'm not sure whether supporting bidirectional text already was worth it: more bugs/complexity and I guess most early users don't care much for it. But it's there now.)
To illustrate a bit more, this selection rectangle is correct due to bidirection text not always being contiguous: This, however, is not (only the white glyphs within the rectangle are selected):
Notice the differing block height? This is because text sizing uses the font's "Em size" (width of M
in font units, which are convertible to points, which are convertible to pixels), not line-height, thus the latter may not match. The base font's line height is used for the space and full-stop while another font is used for the Arabic glyphs:
The second example here is probably not hard to fix, while the solution in the latter case is less obvious (the simplest would be to size fonts based on the line height instead of M
size, I guess).
https://github.com/kas-gui/kas-text/pull/67 fixed an issue apparently not mentioned here: the vertical offset of highlights when text is vertically aligned.
Other issues may or may not be fixed. The gaps in first/last line of justified text is definitely not. The highlight box escaping far to the left hopefully is.
Text selection isn't rendered correctly when text is justified:
Or when it contains tab stops: