Honor setting the selected range in addition to marking text

This commit is contained in:
Antonio Scandurra 2022-07-21 08:57:20 +02:00
parent f712dec4c0
commit eda60effed
3 changed files with 10 additions and 4 deletions

View file

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

View file

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

View file

@ -775,7 +775,7 @@ extern "C" fn handle_key_equivalent(this: &Object, _: Sel, native_event: id) ->
&text, &text,
new_selected_range, 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 { if pending_event.unmark_text {
input_handler.finish_composition(); input_handler.finish_composition();
} else { } else {
@ -1194,9 +1194,9 @@ extern "C" fn attributed_substring_for_proposed_range(
} }
unsafe { 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![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) Some(string)
} }
}) })