Honor setting the selected range in addition to marking text

Antonio Scandurra created

Change summary

crates/editor/src/editor.rs            | 6 +++++-
crates/gpui/src/app.rs                 | 2 ++
crates/gpui/src/platform/mac/window.rs | 6 +++---
3 files changed, 10 insertions(+), 4 deletions(-)

Detailed changes

crates/editor/src/editor.rs 🔗

@@ -5922,7 +5922,7 @@ impl View for Editor {
         &mut self,
         range: Option<Range<usize>>,
         text: &str,
-        _new_selected_range: Option<Range<usize>>,
+        new_selected_range: Option<Range<usize>>,
         cx: &mut ViewContext<Self>,
     ) {
         self.transact(cx, |this, cx| {
@@ -5948,6 +5948,10 @@ impl View for Editor {
             );
 
             this.handle_input(text, cx);
+
+            if let Some(new_selected_range) = new_selected_range {
+                this.set_selected_text_range(new_selected_range, cx);
+            }
         });
     }
 }

crates/gpui/src/app.rs 🔗

@@ -449,10 +449,12 @@ impl InputHandler for WindowInputHandler {
     // TODO - do these need to be handled separately?
 
     fn cancel_composition(&mut self) {
+        println!("cancel_composition()");
         self.unmark_text();
     }
 
     fn finish_composition(&mut self) {
+        println!("finish_composition()");
         self.unmark_text();
     }
 }

crates/gpui/src/platform/mac/window.rs 🔗

@@ -775,7 +775,7 @@ extern "C" fn handle_key_equivalent(this: &Object, _: Sel, native_event: id) ->
                     &text,
                     new_selected_range,
                 )
-            } else if had_marked_text && !inserted_text {
+            } else if had_marked_text && !has_marked_text && !inserted_text {
                 if pending_event.unmark_text {
                     input_handler.finish_composition();
                 } else {
@@ -1194,9 +1194,9 @@ extern "C" fn attributed_substring_for_proposed_range(
         }
 
         unsafe {
-            let selected_text = ns_string(&input_handler.text_for_range(intersection)?);
+            let selected_text = input_handler.text_for_range(intersection)?;
             let string: id = msg_send![class!(NSAttributedString), alloc];
-            let string: id = msg_send![string, initWithString: selected_text];
+            let string: id = msg_send![string, initWithString: ns_string(&selected_text)];
             Some(string)
         }
     })