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

Move cursor to end of text area when text is changed #823

Merged
merged 3 commits into from
Jan 14, 2025
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion masonry/src/widget/text_area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,9 @@ impl<const EDITABLE: bool> TextArea<EDITABLE> {
}
this.widget.editor.set_text(new_text);

let (fctx, lctx) = this.ctx.text_contexts();
this.widget.editor.driver(fctx, lctx).move_to_text_end();

this.ctx.request_layout();
}

Expand Down Expand Up @@ -826,7 +829,13 @@ impl<const EDITABLE: bool> Widget for TextArea<EDITABLE> {

fn update(&mut self, ctx: &mut UpdateCtx, event: &Update) {
match event {
Update::FocusChanged(_) => {
Update::FocusChanged(focus) => {
// If we lose focus, set the selection up so that next time
// we get focus, selection will be at the end of the text.
if !*focus {
let (fctx, lctx) = ctx.text_contexts();
self.editor.driver(fctx, lctx).move_to_text_end();
}
ctx.request_render();
}
Update::DisabledChanged(_) => {
Expand Down
Loading