Przeglądaj źródła

app: editor optimize selecting text and moving cursor on android. only update drawing on actual change

darkfi 9 miesięcy temu
rodzic
commit
48be7e056c
1 zmienionych plików z 8 dodań i 3 usunięć
  1. 8 3
      bin/app/src/ui/edit/mod.rs

+ 8 - 3
bin/app/src/ui/edit/mod.rs

@@ -69,7 +69,7 @@ const HOLD_ENABLE_TIME: u128 = 500;
 const VERT_SCROLL_UPDATE_INC: f32 = 1.;
 
 /// How often to update the scrolling selection with mouse.
-const SELECT_TASK_UPDATE_TIME: u64 = 100;
+const SELECT_TASK_UPDATE_TIME: u64 = 500;
 // Should be a property
 const SELECT_SCROLL_TRAVEL_SPEED: f32 = 1.;
 
@@ -935,8 +935,8 @@ impl BaseEdit {
             //let mut drv = editor.driver(&mut txt_ctx).unwrap();
             //drv.extend_selection_to_point(clip_mouse_pos.x, clip_mouse_pos.y);
             let layout = editor.layout();
-            let sel =
-                editor.selection().extend_to_point(layout, clip_mouse_pos.x, clip_mouse_pos.y);
+            let prev_sel = editor.selection();
+            let sel = prev_sel.extend_to_point(layout, clip_mouse_pos.x, clip_mouse_pos.y);
             let (mut start, mut end) = (sel.anchor().index(), sel.focus().index());
             //t!("handle_select() setting ({start}, {end})");
 
@@ -958,6 +958,11 @@ impl BaseEdit {
                 }
             }
 
+            if start == prev_sel.anchor().index() && end == prev_sel.focus().index() {
+                // No change so just return
+                return
+            }
+
             editor.set_selection(start, end);
             editor.refresh().await;