Skip to content

Fix: Text input selection paint size#944

Open
charlescgs wants to merge 3 commits intolapce:mainfrom
charlescgs:text_input
Open

Fix: Text input selection paint size#944
charlescgs wants to merge 3 commits intolapce:mainfrom
charlescgs:text_input

Conversation

@charlescgs
Copy link
Contributor

@charlescgs charlescgs commented Oct 26, 2025

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

@jrmoulton
Copy link
Collaborator

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

@charlescgs
Copy link
Contributor Author

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

@jrmoulton
Copy link
Collaborator

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

@charlescgs
Copy link
Contributor Author

charlescgs commented Oct 27, 2025

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.

@jrmoulton
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants