floem icon indicating copy to clipboard operation
floem copied to clipboard

Fix: Text input selection paint size

Open charlescgs opened this issue 3 months ago • 5 comments

This PR is adjusting text input selection paint size to cover better selected text and avoid clipping left edge of the selection:

Examples

Ex. 1 Ex. 2 Ex. 3 Ex. 4
Before 1 1 1 2 1 3 1 4
After 2 1 2 2 2 3 2 4

charlescgs avatar Oct 26 '25 10:10 charlescgs

Does the text layout provide any other information that we should be using to better position the selection? just inflating the rect feels like a solution that will cause as many problems as it solves

jrmoulton avatar Oct 26 '25 20:10 jrmoulton

Hmm, this also seems to work:

let selection_rect = self
    .get_selection_rect(&node_layout, padding_left + 1.)
    .to_rounded_rect(border_radius);
cx.save();
// cx.clip(&self.id
//     .get_size()
//     .unwrap_or(Size::new(selection_rect.width(), selection_rect.height()))
//     .to_rect()
// );
cx.fill(&selection_rect, &cursor_color, 0.0);
cx.restore();

Clip does appear to do nothing here though.. 🤔

charlescgs avatar Oct 26 '25 21:10 charlescgs

It makes sense to have the clip in case there are rounded corners or some case where it would clip.

I think we do want to actually fix this properly using info from the TextLayout

jrmoulton avatar Oct 27 '25 00:10 jrmoulton

Copy that, but I don't feel competent enough to do that, have looked briefly there and have no idea what is going on :D

One note on the side; this change affects only text_input widget, but not the editor, so scope for anything going wrong is very limited, I have tested this change quite extensively on every case I could think of and did not see any regress.

charlescgs avatar Oct 27 '25 00:10 charlescgs

I think it used to have an inflate on it and I removed it some time ago because it was causing problems

jrmoulton avatar Oct 27 '25 01:10 jrmoulton