Skip to content

Commit

Permalink
Tweak what text is selected when focus is regained.
Browse files Browse the repository at this point in the history
  • Loading branch information
PoignardAzur committed Sep 16, 2024
1 parent 362bb58 commit 80a84e2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions masonry/src/text/selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,15 @@ impl<T: Selectable> TextWithSelection<T> {
}
}

/// 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;
Expand Down
1 change: 1 addition & 0 deletions masonry/src/widget/textbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 80a84e2

Please sign in to comment.