From 80a84e2ac0cc611fe0f8ace6b0c871c571cbe0a8 Mon Sep 17 00:00:00 2001 From: Olivier FAURE Date: Mon, 16 Sep 2024 17:25:40 +0200 Subject: [PATCH] Tweak what text is selected when focus is regained. --- masonry/src/text/selection.rs | 9 +++++++++ masonry/src/widget/textbox.rs | 1 + 2 files changed, 10 insertions(+) diff --git a/masonry/src/text/selection.rs b/masonry/src/text/selection.rs index 66864e7cf..a449fe2ed 100644 --- a/masonry/src/text/selection.rs +++ b/masonry/src/text/selection.rs @@ -204,6 +204,15 @@ impl TextWithSelection { } } + /// Call when this widget becomes focused + pub fn focus_gained(&mut self) { + if self.selection.is_none() { + // TODO - We need to have some "memory" of the text selected instead. + self.selection = Some(Selection::caret(self.text().len(), Affinity::Downstream)); + } + self.needs_selection_update = true; + } + /// Call when another widget becomes focused pub fn focus_lost(&mut self) { self.selection = None; diff --git a/masonry/src/widget/textbox.rs b/masonry/src/widget/textbox.rs index fd9e32610..65022b2ca 100644 --- a/masonry/src/widget/textbox.rs +++ b/masonry/src/widget/textbox.rs @@ -235,6 +235,7 @@ impl Widget for Textbox { // TODO: Stop focusing on any links } StatusChange::FocusChanged(true) => { + self.editor.focus_gained(); // TODO: Focus on first link ctx.request_layout(); }