Просмотр исходного кода

app: chatedit desktop add autoscroll, and disable actionbar visibility

darkfi 1 год назад
Родитель
Сommit
ec53e4caf5
2 измененных файлов с 52 добавлено и 34 удалено
  1. 21 18
      bin/app/src/app/schema/chat.rs
  2. 31 16
      bin/app/src/ui/chatedit.rs

+ 21 - 18
bin/app/src/app/schema/chat.rs

@@ -171,7 +171,7 @@ mod ui_consts {
     pub const ACTION_COPY_RECT: Rectangle = Rectangle::new(0., 0., 100., 80.);
     pub const ACTION_PASTE_RECT: Rectangle = Rectangle::new(110., 0., 120., 80.);
     pub const ACTION_SELECT_ALL_RECT: Rectangle = Rectangle::new(240., 0., 200., 80.);
-    pub const ACTION_LABEL_POS: Point = Point::new(20., 46.);
+    pub const ACTION_LABEL_POS: Point = Point::new(20., 20.);
 }
 
 use super::EMOJI_PICKER_ICON_SIZE;
@@ -1586,24 +1586,27 @@ pub async fn make(
     });
     app.tasks.lock().unwrap().push(listen_click);
 
-    let editz_select_sub = editz_select_text.subscribe_modify();
-    let pasta_is_visible2 = pasta_is_visible.clone();
-    let editz_select_task = app.ex.spawn(async move {
-        while let Ok(_) = editz_select_sub.receive().await {
-            let atom = &mut PropertyAtomicGuard::new();
-            if editz_select_text.is_null(0).unwrap() {
-                info!(target: "app::chat", "selection changed: null");
-                actions_is_visible.set(atom, false);
-                pasta_is_visible2.set(atom, false);
-            } else {
-                let select_text = editz_select_text.get_str(0).unwrap();
-                info!(target: "app::chat", "selection changed: {select_text}");
-                actions_is_visible.set(atom, true);
-                pasta_is_visible2.set(atom, false);
+    #[cfg(target_os = "android")]
+    {
+        let editz_select_sub = editz_select_text.subscribe_modify();
+        let pasta_is_visible2 = pasta_is_visible.clone();
+        let editz_select_task = app.ex.spawn(async move {
+            while let Ok(_) = editz_select_sub.receive().await {
+                let atom = &mut PropertyAtomicGuard::new();
+                if editz_select_text.is_null(0).unwrap() {
+                    info!(target: "app::chat", "selection changed: null");
+                    actions_is_visible.set(atom, false);
+                    pasta_is_visible2.set(atom, false);
+                } else {
+                    let select_text = editz_select_text.get_str(0).unwrap();
+                    info!(target: "app::chat", "selection changed: {select_text}");
+                    actions_is_visible.set(atom, true);
+                    pasta_is_visible2.set(atom, false);
+                }
             }
-        }
-    });
-    app.tasks.lock().unwrap().push(editz_select_task);
+        });
+        app.tasks.lock().unwrap().push(editz_select_task);
+    }
 
     let editz_text_sub = editz_text.prop().subscribe_modify();
     let editz_text_task = app.ex.spawn(async move {

+ 31 - 16
bin/app/src/ui/chatedit.rs

@@ -554,36 +554,39 @@ impl ChatEdit {
         #[cfg(target_os = "macos")]
         let action_mod = mods.logo;
 
-        let mut txt_ctx = text2::TEXT_CTX.get().await;
-        let mut editor = self.lock_editor().await;
-        let mut drv = editor.driver(&mut txt_ctx).unwrap();
-
         match key {
             'a' => {
                 if action_mod {
+                    let mut txt_ctx = text2::TEXT_CTX.get().await;
+                    let mut editor = self.lock_editor().await;
+                    let mut drv = editor.driver(&mut txt_ctx).unwrap();
+
                     drv.select_all();
+                    if let Some(seltext) = editor.selected_text() {
+                        self.select_text.clone().set_str(atom, Role::Internal, 0, seltext).unwrap();
+                    }
                 }
             }
             'c' => {
                 if action_mod {
-                    if let Some(text) = editor.selected_text() {
-                        miniquad::window::clipboard_set(&text);
+                    let editor = self.lock_editor().await;
+                    if let Some(txt) = editor.selected_text() {
+                        miniquad::window::clipboard_set(&txt);
                     }
                 }
             }
             'v' => {
                 if action_mod {
-                    if let Some(text) = miniquad::window::clipboard_get() {
-                        drv.insert_or_replace_selection(&text);
+                    if let Some(txt) = miniquad::window::clipboard_get() {
+                        self.insert(&txt, atom).await;
+                        // Maybe insert should call this?
+                        self.apply_cursor_scrolling(atom).await;
                     }
                 }
             }
             _ => return false,
         }
 
-        drop(editor);
-        drop(txt_ctx);
-
         self.redraw().await;
         true
     }
@@ -702,9 +705,16 @@ impl ChatEdit {
             _ => return false,
         }
 
+        if let Some(seltext) = editor.selected_text() {
+            self.select_text.clone().set_str(atom, Role::Internal, 0, seltext).unwrap();
+        } else {
+            self.select_text.clone().set_null(atom, Role::Internal, 0).unwrap();
+        }
+
         drop(editor);
         drop(txt_ctx);
 
+        self.apply_cursor_scrolling(atom).await;
         self.pause_blinking();
         self.redraw().await;
 
@@ -951,12 +961,15 @@ impl ChatEdit {
         let cursor_h = self.baseline.get() + self.cursor_descent.get();
         // The bottom
         let cursor_y1 = cursor_y0 + cursor_h;
+        //t!("apply_cursor_scrolling() cursor = [{cursor_y0}, {cursor_y1}] rect_h={rect_h} scroll={scroll}");
 
         if cursor_y1 > rect_h + scroll {
+            //t!("  cursor bottom below rect");
             // We want cursor_y1 = rect_h + scroll by adjusting scroll
             scroll = cursor_y1 - rect_h;
             self.scroll.set(atom, scroll);
         } else if cursor_y0 < scroll {
+            //t!("  cursor top above rect");
             scroll = cursor_y0;
             self.scroll.set(atom, scroll);
         }
@@ -1102,11 +1115,11 @@ impl ChatEdit {
     }
 
     async fn regen_phone_select_handle_mesh(&self) -> Vec<GfxDrawInstruction> {
+        if !self.is_phone_select.load(Ordering::Relaxed) {
+            return vec![]
+        }
         //t!("regen_phone_select_handle_mesh()");
-        let Some((mut first, mut last)) = self.get_select_handles().await else {
-            assert!(!self.is_phone_select.load(Ordering::Relaxed));
-            return vec![];
-        };
+        let (mut first, mut last) = self.get_select_handles().await.unwrap();
 
         let scroll = self.scroll.get();
 
@@ -1713,7 +1726,9 @@ impl UIObject for ChatEdit {
         }
 
         self.pause_blinking();
-        //self.apply_cursor_scrolling();
+        self.apply_cursor_scrolling(atom).await;
+        self.redraw_scroll().await;
+        self.redraw_cursor().await;
         self.redraw_select().await;
         true
     }