Prechádzať zdrojové kódy

app: chatedit fix set text property

darkfi 1 rok pred
rodič
commit
e1daeb7b64

+ 1 - 0
bin/app/java/MainActivity.java

@@ -95,6 +95,7 @@ public InvisibleInputView getInputView(int id) {
 }
 
 public boolean setText(int id, String txt) {
+    //Log.d("darkfi", "setText(" + id + ", " + txt + ")");
     InvisibleInputView iv = editors.get(id);
     if (iv == null) {
         return false;

+ 4 - 3
bin/app/java/autosuggest/CustomInputConnection.java

@@ -118,14 +118,15 @@ public class CustomInputConnection extends BaseInputConnection {
         Selection.setSelection(mEditable, selectionStart, selectionEnd);
         super.setComposingRegion(compositionStart, compositionEnd);
 
-        if (textUnchanged || prevText.equals("")) {
-            log("setEditableText updating selection");
+        //log("textUnchanged=%s  prevText=%s", textUnchanged, prevText);
+        //if (textUnchanged || prevText.equals("")) {
+        //    log("setEditableText updating selection");
             // updateSelection should be called when a manual selection change occurs.
             // Should not be called if text is being entered else issues can occur
             // e.g. backspace to undo autocorrection will not work with the default OSK.
             getInputMethodManager().updateSelection(mInternalView,
                     selectionStart, selectionEnd, compositionStart, compositionEnd);
-        }
+        //}
     }
 
     @Override

+ 3 - 2
bin/app/src/app/schema/chat.rs

@@ -96,6 +96,7 @@ mod android_ui_consts {
     pub const CMD_HELP_NICK_CMD_WIDTH: f32 = 280.;
     pub const CMD_HELP_NICK_DESC_WIDTH: f32 = 1000.;
     pub const CMD_HELP_NICK_DESC_X: f32 = 320.;
+    pub const CMD_HELP_LABEL_Y: f32 = 20.;
 
     pub const ACTION_POPUP_Y_OFF: f32 = 200.;
     pub const ACTION_COPY_RECT: Rectangle = Rectangle::new(0., 0., 200., 160.);
@@ -1148,7 +1149,7 @@ pub async fn make(
     let node = create_text("cmd_nick_label");
     let prop = node.get_property("rect").unwrap();
     prop.clone().set_f32(atom, Role::App, 0, CMD_HELP_CMD_LABEL_X_INSET).unwrap();
-    prop.clone().set_f32(atom, Role::App, 1, 0.).unwrap();
+    prop.clone().set_f32(atom, Role::App, 1, CMD_HELP_LABEL_Y).unwrap();
     prop.clone().set_f32(atom, Role::App, 2, 1000.).unwrap();
     prop.clone().set_f32(atom, Role::App, 3, 1000.).unwrap();
     node.set_property_f32(atom, Role::App, "baseline", CMD_HELP_BASELINE).unwrap();
@@ -1180,7 +1181,7 @@ pub async fn make(
     let node = create_text("cmd_nick_desc_label");
     let prop = node.get_property("rect").unwrap();
     prop.clone().set_f32(atom, Role::App, 0, CMD_HELP_NICK_DESC_X).unwrap();
-    prop.clone().set_f32(atom, Role::App, 1, 0.).unwrap();
+    prop.clone().set_f32(atom, Role::App, 1, CMD_HELP_LABEL_Y).unwrap();
     prop.clone().set_f32(atom, Role::App, 2, 1000.).unwrap();
     prop.clone().set_f32(atom, Role::App, 3, 1000.).unwrap();
     node.set_property_f32(atom, Role::App, "baseline", CMD_HELP_BASELINE).unwrap();

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

@@ -469,7 +469,7 @@ impl<'a> RenderContext<'a> {
                     // using an is_visible flag.
                     match self.view.clip(&old_view) {
                         Some(clipped) => self.view = clipped,
-                        None => self.view = Rectangle::zero()
+                        None => self.view = Rectangle::zero(),
                     }
                     // Cursor resets within the view
                     self.cursor = Point::zero();

+ 13 - 13
bin/app/src/logger.rs

@@ -30,19 +30,19 @@ const LOGFILE_MAXSIZE: usize = 5_000_000;
 static MUTED_TARGETS: &[&'static str] = &[
     "sled",
     "rustls",
-    //"net::channel",
-    //"net::message_publisher",
-    //"net::hosts",
-    //"net::protocol",
-    //"net::session",
-    //"net::outbound_session",
-    //"net::tcp",
-    //"net::p2p::seed",
-    //"net::refinery::handshake_node()",
-    //"system::publisher",
-    //"event_graph::dag_sync()",
-    //"event_graph::dag_insert()",
-    //"event_graph::protocol",
+    "net::channel",
+    "net::message_publisher",
+    "net::hosts",
+    "net::protocol",
+    "net::session",
+    "net::outbound_session",
+    "net::tcp",
+    "net::p2p::seed",
+    "net::refinery::handshake_node()",
+    "system::publisher",
+    "event_graph::dag_sync()",
+    "event_graph::dag_insert()",
+    "event_graph::protocol",
 ];
 
 static ALLOW_TRACE: &[&'static str] = &["ui", "app", "gfx"];

+ 10 - 3
bin/app/src/main.rs

@@ -24,7 +24,10 @@ use async_lock::{Mutex as AsyncMutex, RwLock as AsyncRwLock};
 use darkfi::system::CondVar;
 use darkfi_serial::{deserialize, Decodable, Encodable};
 use file_rotate::{compression::Compression, suffix::AppendCount, ContentLimit, FileRotate};
-use std::{io::Cursor, sync::{mpsc, Arc, OnceLock}};
+use std::{
+    io::Cursor,
+    sync::{mpsc, Arc, OnceLock},
+};
 
 #[macro_use]
 extern crate log;
@@ -66,9 +69,14 @@ mod util;
 use crate::{
     app::{App, AppPtr},
     net::ZeroMQAdapter,
+    prop::{
+        Property, PropertyAtomicGuard, PropertyBool, PropertyStr, PropertySubType, PropertyType,
+        Role,
+    },
+    scene::{CallArgType, SceneNode, SceneNodePtr, SceneNodeType, Slot},
     text::TextShaper,
+    ui::chatview,
     util::AsyncRuntime,
-    prop::{PropertyType, Property, PropertySubType, PropertyBool, PropertyStr, Role, PropertyAtomicGuard}, scene::{SceneNode, SceneNodePtr, SceneNodeType, Slot, CallArgType}, ui::chatview
 };
 
 // This is historical, but ideally we can fix the entire project and remove this import.
@@ -484,4 +492,3 @@ def foo():
     println!("{:?}", res);
 }
 */
-

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

@@ -122,6 +122,23 @@ impl Editor {
         t!("Initialized composer [{}]", self.composer_id);
     }
 
+    pub async fn on_text_changed(&mut self) {
+        // Get modified text property
+        let txt = self.text.get();
+        // Update Android text buffer
+        android::set_text(self.composer_id, &txt);
+        assert_eq!(android::get_editable(self.composer_id).unwrap().buffer, txt);
+        // Refresh our layout
+        self.refresh().await;
+    }
+    pub async fn on_buffer_changed(&mut self) {
+        // Refresh the layout using the Android buffer
+        self.refresh().await;
+        // Now update the text attribute
+        let edit = android::get_editable(self.composer_id).unwrap();
+        self.text.set(&mut PropertyAtomicGuard::new(), &edit.buffer);
+    }
+
     /// Can only be called after AndroidSuggestEvent::Init.
     pub fn focus(&self) {
         // We're not yet ready to receive focus
@@ -135,7 +152,7 @@ impl Editor {
         android::unfocus(self.composer_id).unwrap();
     }
 
-    pub async fn refresh(&mut self, atom: &mut PropertyAtomicGuard) {
+    pub async fn refresh(&mut self) {
         let font_size = self.font_size.get();
         let text_color = self.text_color.get();
         let window_scale = self.window_scale.get();
@@ -162,8 +179,6 @@ impl Editor {
             self.width,
             &underlines,
         );
-
-        self.text.set(atom, edit.buffer);
     }
 
     pub fn layout(&self) -> &parley::Layout<Color> {

+ 7 - 20
bin/app/src/ui/chatedit.rs

@@ -704,7 +704,7 @@ impl ChatEdit {
 
         let mut editor = self.lock_editor().await;
         editor.select_word_at_point(touch_pos);
-        editor.refresh(atom).await;
+        editor.refresh().await;
 
         let seltext = editor.selected_text().unwrap();
         d!("Selected {seltext:?} from {touch_pos:?}");
@@ -890,14 +890,13 @@ impl ChatEdit {
     }
     async fn handle_touch_end(&self, mut touch_pos: Point) -> bool {
         //t!("handle_touch_end({touch_pos:?})");
-        let atom = &mut PropertyAtomicGuard::new();
         self.abs_to_local(&mut touch_pos);
 
         let state = self.touch_info.lock().stop();
         match state {
             TouchStateAction::Inactive => return false,
             TouchStateAction::Started { pos: _, instant: _ } | TouchStateAction::SetCursorPos => {
-                self.touch_set_cursor_pos(touch_pos, atom).await;
+                self.touch_set_cursor_pos(touch_pos).await;
                 self.redraw().await;
             }
             _ => {}
@@ -909,12 +908,12 @@ impl ChatEdit {
         true
     }
 
-    async fn touch_set_cursor_pos(&self, mut touch_pos: Point, atom: &mut PropertyAtomicGuard) {
+    async fn touch_set_cursor_pos(&self, mut touch_pos: Point) {
         t!("touch_set_cursor_pos({touch_pos:?})");
 
         let mut editor = self.lock_editor().await;
         editor.move_to_pos(touch_pos);
-        editor.refresh(atom).await;
+        editor.refresh().await;
         drop(editor);
 
         self.pause_blinking();
@@ -1179,7 +1178,7 @@ impl ChatEdit {
         let content_height = {
             let mut editor = self.lock_editor().await;
             editor.set_width(rect_w);
-            editor.refresh(atom).await;
+            editor.refresh().await;
             editor.height()
         };
         self.content_height.set(atom, content_height);
@@ -1366,8 +1365,7 @@ impl ChatEdit {
             }
         }
 
-        let atom = &mut PropertyAtomicGuard::new();
-        editor.refresh(atom).await;
+        editor.on_buffer_changed().await;
         drop(editor);
 
         self.redraw().await;
@@ -1436,18 +1434,7 @@ impl UIObject for ChatEdit {
             self_.redraw().await;
         }
         async fn set_text(self_: Arc<ChatEdit>) {
-            {
-                let text = self_.text.get();
-
-                //let mut text_wrap = self_.text_wrap.lock();
-                //text_wrap.editable.end_compose();
-                //text_wrap.editable.set_text(text, String::new());
-                //text_wrap.clear_cache();
-
-                //let select = &mut text_wrap.select;
-                //select.clear();
-            }
-
+            self_.lock_editor().await.on_text_changed().await;
             self_.redraw().await;
         }