From 5abfa95580f3e174aa7f7c4771095b2e8188dfc8 Mon Sep 17 00:00:00 2001 From: Andrey Kabylin Date: Sat, 3 Oct 2020 12:36:33 +0700 Subject: [PATCH 1/3] Fix #1124, #1125 --- CHANGELOG.md | 2 ++ druid/src/widget/textbox.rs | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 425f03a991..c730876c94 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -98,6 +98,8 @@ You can find its changes [documented below](#060---2020-06-01). - Windows: fix crash on resize from incompatible resources ([#1191 by [@raphlinus]]) - GTK: Related dependencies are now optional, facilitating a pure X11 build. ([#1241] by [@finnerale]) - `widget::Image` now computes the layout correctly when unbound in one direction. ([#1189] by [@JAicewizard]) +- TextBox doesn't reset position after unfocused. ([#todo] by [@sysint64]) +- Able to select text in multiple TextBoxes at once. ([#todo] by [@sysint64]) ### Visual diff --git a/druid/src/widget/textbox.rs b/druid/src/widget/textbox.rs index 651ac5b8e5..23d941034c 100644 --- a/druid/src/widget/textbox.rs +++ b/druid/src/widget/textbox.rs @@ -182,7 +182,7 @@ impl TextBox { } /// Edit a selection using a `Movement`. - fn move_selection(&mut self, mvmnt: Movement, text: &mut String, modify: bool) { + fn move_selection(&mut self, mvmnt: Movement, text: &String, modify: bool) { // This movement function should ensure all movements are legit. // If they aren't, that's a problem with the movement function. self.selection = movement(mvmnt, self.selection, text, modify); @@ -379,8 +379,11 @@ impl Widget for TextBox { ctx.register_for_focus(); self.text.set_text(data.as_str().into()); } - LifeCycle::FocusChanged(true) => { - self.reset_cursor_blink(ctx.request_timer(CURSOR_BLINK_DURATION)) + LifeCycle::FocusChanged(_) => { + self.move_selection(Movement::StartOfDocument, data, false); + self.update_hscroll(); + self.reset_cursor_blink(ctx.request_timer(CURSOR_BLINK_DURATION)); + ctx.request_paint(); } _ => (), } From 63ab0ddd85d0a9069a14bf69befeae9c64109c76 Mon Sep 17 00:00:00 2001 From: Andrey Kabylin Date: Sat, 3 Oct 2020 12:42:25 +0700 Subject: [PATCH 2/3] fix clippy --- druid/src/widget/textbox.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/druid/src/widget/textbox.rs b/druid/src/widget/textbox.rs index 23d941034c..dd05a97848 100644 --- a/druid/src/widget/textbox.rs +++ b/druid/src/widget/textbox.rs @@ -182,7 +182,7 @@ impl TextBox { } /// Edit a selection using a `Movement`. - fn move_selection(&mut self, mvmnt: Movement, text: &String, modify: bool) { + fn move_selection(&mut self, mvmnt: Movement, text: &impl EditableText, modify: bool) { // This movement function should ensure all movements are legit. // If they aren't, that's a problem with the movement function. self.selection = movement(mvmnt, self.selection, text, modify); From b60e71441843525944d08408f3259a83419ee82b Mon Sep 17 00:00:00 2001 From: Andrey Kabylin Date: Sat, 3 Oct 2020 12:43:31 +0700 Subject: [PATCH 3/3] update CHANGELOG.md --- CHANGELOG.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c730876c94..2ef9b67441 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -98,8 +98,8 @@ You can find its changes [documented below](#060---2020-06-01). - Windows: fix crash on resize from incompatible resources ([#1191 by [@raphlinus]]) - GTK: Related dependencies are now optional, facilitating a pure X11 build. ([#1241] by [@finnerale]) - `widget::Image` now computes the layout correctly when unbound in one direction. ([#1189] by [@JAicewizard]) -- TextBox doesn't reset position after unfocused. ([#todo] by [@sysint64]) -- Able to select text in multiple TextBoxes at once. ([#todo] by [@sysint64]) +- TextBox doesn't reset position after unfocused. ([#1276] by [@sysint64]) +- Able to select text in multiple TextBoxes at once. ([#1276] by [@sysint64]) ### Visual @@ -486,6 +486,7 @@ Last release without a changelog :( [#1251]: https://github.com/linebender/druid/pull/1251 [#1252]: https://github.com/linebender/druid/pull/1252 [#1255]: https://github.com/linebender/druid/pull/1255 +[#1276]: https://github.com/linebender/druid/pull/1276 [Unreleased]: https://github.com/linebender/druid/compare/v0.6.0...master [0.6.0]: https://github.com/linebender/druid/compare/v0.5.0...v0.6.0