add adjust selection method to TextBehavior
@@ -412,6 +412,8 @@ impl TextBehaviorState {
// handles focus changed event
fn focused_changed(&self, ctx: &mut Context) {
+ self.adjust_selection(ctx);
+
if *TextBehavior::select_all_on_focus_ref(&ctx.widget()) {
self.select_all(ctx);
}
@@ -575,20 +577,15 @@ impl TextBehaviorState {
ctx.get_widget(self.target).update(false);
}
- fn force_update(&mut self, ctx: &mut Context) {
- let self_update = self.self_update;
- self.self_update = false;
+ fn adjust_selection(&self, ctx: &mut Context) {
+ let mut selection = self.selection(ctx);
+ let len = self.len(ctx);
- if self_update {
+ if selection.start() <= len || selection.end() <= len {
return;
}
- let mut selection = self.selection(ctx);
- let len = self.len(ctx);
-
- if selection.start() > len || selection.end() > len {
selection.set(len);
- }
TextBehavior::selection_set(&mut ctx.widget(), selection);
@@ -596,6 +593,17 @@ impl TextBehaviorState {
self.update_focused_state(ctx);
return;
}
+ }
+
+ fn force_update(&mut self, ctx: &mut Context) {
+ let self_update = self.self_update;
+ self.self_update = false;
+
+ if self_update {
+ return;
+ }
+
+ self.adjust_selection(ctx);
if self.len(ctx) == 0 {
ctx.get_widget(self.target)
