ソースを参照

app: use upstream parley git repo, rework editor set_selection()

darkfi 9 ヶ月 前
コミット
64b167e134

ファイルの差分が大きいため隠しています
+ 147 - 155
bin/app/Cargo.lock


+ 1 - 1
bin/app/Cargo.toml

@@ -52,7 +52,7 @@ clap = { version = "4.5", features = ["derive"] }
 file-rotate = "0.7.6"
 parking_lot = { version = "0.12.4", features = ["nightly"] }
 regex = "1.11"
-parley = { git = "https://github.com/narodnik/parley.git" }
+parley = { git = "https://github.com/linebender/parley.git" }
 swash = "0.2.5"
 zeno = "0.3.3"
 peniko = "*"

+ 1 - 1
bin/app/src/app/schema/mod.rs

@@ -57,7 +57,7 @@ mod ui_consts {
     use std::path::PathBuf;
 
     //pub const BG_PATH: &str = "bg.png";
-    pub const VID_PATH: &str = "forest6/forest_02cjpg{frame}.qoi";
+    pub const VID_PATH: &str = "forest8/forest_02cjpg{frame}.qoi";
     pub use super::android_ui_consts::*;
 
     pub fn get_chatdb_path() -> PathBuf {

+ 3 - 3
bin/app/src/text2/editor/android.rs

@@ -197,11 +197,11 @@ impl Editor {
         android::set_selection(self.composer_id, pos, pos);
     }
 
-    pub fn select_word_at_point(&mut self, pos: Point) {
+    pub async fn select_word_at_point(&mut self, pos: Point) {
         let select = parley::Selection::word_from_point(&self.layout, pos.x, pos.y);
         assert!(!select.is_collapsed());
         let select = select.text_range();
-        self.set_selection(select.start, select.end);
+        self.set_selection(select.start, select.end).await;
     }
 
     pub fn get_cursor_pos(&self) -> Point {
@@ -280,7 +280,7 @@ impl Editor {
 
         parley::Selection::new(anchor, focus)
     }
-    pub fn set_selection(&mut self, select_start: usize, select_end: usize) {
+    pub async fn set_selection(&mut self, select_start: usize, select_end: usize) {
         //t!("set_selection({select_start}, {select_end})");
         let edit = android::get_editable(self.composer_id).unwrap();
         let select_start = byte_to_char16_index(&edit.buffer, select_start).unwrap();

+ 6 - 6
bin/app/src/text2/editor/parley.rs

@@ -95,7 +95,7 @@ impl Editor {
     pub fn move_to_pos(&self, _pos: Point) {
         unimplemented!()
     }
-    pub fn select_word_at_point(&mut self, _pos: Point) {
+    pub async fn select_word_at_point(&mut self, _pos: Point) {
         unimplemented!()
     }
 
@@ -140,11 +140,11 @@ impl Editor {
     }
     /// Android uses byte indexes whereas parley has its own things. So this API is a compromise
     /// between them both.
-    pub fn set_selection(&mut self, select_start: usize, select_end: usize) {
-        let anchor = self.editor.cursor_at(select_start);
-        let focus = self.editor.cursor_at(select_end);
-        let sel = parley::Selection::new(anchor, focus);
-        self.editor.set_selection(sel);
+    pub async fn set_selection(&mut self, select_start: usize, select_end: usize) {
+        let mut txt_ctx = TEXT_CTX.get().await;
+        let (font_ctx, layout_ctx) = txt_ctx.borrow();
+        let mut drv = self.editor.driver(font_ctx, layout_ctx);
+        drv.select_byte_range(select_start, select_end);
     }
 
     #[allow(dead_code)]

+ 2 - 2
bin/app/src/ui/edit/mod.rs

@@ -690,7 +690,7 @@ impl BaseEdit {
         t!("start_touch_select({touch_pos:?})");
 
         let mut editor = self.lock_editor().await;
-        editor.select_word_at_point(touch_pos);
+        editor.select_word_at_point(touch_pos).await;
         editor.refresh().await;
 
         let seltext = editor.selected_text().unwrap();
@@ -976,7 +976,7 @@ impl BaseEdit {
             assert!(start < end);
 
             //t!("handle_select(): set_selection({start}, {end})");
-            editor.set_selection(start, end);
+            editor.set_selection(start, end).await;
             editor.refresh().await;
 
             editor.selected_text()

この差分においてかなりの量のファイルが変更されているため、一部のファイルを表示していません