Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Text selection highlighting bugs #232

Open
Aloso opened this issue Aug 3, 2021 · 5 comments
Open

Text selection highlighting bugs #232

Aloso opened this issue Aug 3, 2021 · 5 comments
Labels
appearance Concerns visuals bug A current feature is not working correctly easy Good first issue

Comments

@Aloso
Copy link

Aloso commented Aug 3, 2021

Text selection isn't rendered correctly when text is justified:

kas selection

Or when it contains tab stops:

kas-selection-2

@dhardy
Copy link
Collaborator

dhardy commented Aug 3, 2021

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.

@nyanpasu64
Copy link
Contributor

I was playing around with right-to-left selection, and got the text and selection colors to desync. Is this a known bug?

Screenshot_20210929_002236_Widget Gallery

@dhardy
Copy link
Collaborator

dhardy commented Sep 29, 2021

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.)

@dhardy dhardy added the low priority Not a near-term goal / not easily achievable label Sep 29, 2021
@dhardy
Copy link
Collaborator

dhardy commented Sep 29, 2021

To illustrate a bit more, this selection rectangle is correct due to bidirection text not always being contiguous:
selection-1
This, however, is not (only the white glyphs within the rectangle are selected):
selection-2

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:
selection-3

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).

@dhardy dhardy changed the title Text selection bugs Text selection highlighting bugs Sep 29, 2021
@dhardy dhardy added appearance Concerns visuals bug A current feature is not working correctly easy Good first issue and removed low priority Not a near-term goal / not easily achievable labels Feb 23, 2022
@dhardy
Copy link
Collaborator

dhardy commented Jul 16, 2022

kas-gui/kas-text#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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
appearance Concerns visuals bug A current feature is not working correctly easy Good first issue
Projects
None yet
Development

No branches or pull requests

3 participants