terminal: Fix last character of IME marked text not being deleted (#46224)

This commit is contained in:
ᴀᴍᴛᴏᴀᴇʀ authored and GitHub committed 2026-01-14 02:00:30 -05:00
1 parent eb33aab104
commit f50cb30f0c
2 files changed
+8 -14

No files matched your search

+2 -2
View File
@@ -1488,12 +1488,12 @@ impl InputHandler for TerminalInputHandler {
&mut self, &mut self,
_range_utf16: Option<std::ops::Range<usize>>, _range_utf16: Option<std::ops::Range<usize>>,
new_text: &str, new_text: &str,
new_marked_range: Option<std::ops::Range<usize>>, _new_marked_range: Option<std::ops::Range<usize>>,
_window: &mut Window, _window: &mut Window,
cx: &mut App, cx: &mut App,
) { ) {
self.terminal_view.update(cx, |view, view_cx| { self.terminal_view.update(cx, |view, view_cx| {
view.set_marked_text(new_text.to_string(), new_marked_range, view_cx); view.set_marked_text(new_text.to_string(), view_cx);
}); });
} }
+6 -12
View File
@@ -62,7 +62,6 @@ use std::{
struct ImeState { struct ImeState {
marked_text: String, marked_text: String,
marked_range_utf16: Option<Range<usize>>,
} }
const CURSOR_BLINK_INTERVAL: Duration = Duration::from_millis(500); const CURSOR_BLINK_INTERVAL: Duration = Duration::from_millis(500);
@@ -327,16 +326,11 @@ impl TerminalView {
} }
/// Sets the marked (pre-edit) text from the IME. /// Sets the marked (pre-edit) text from the IME.
pub(crate) fn set_marked_text( pub(crate) fn set_marked_text(&mut self, text: String, cx: &mut Context<Self>) {
&mut self, if text.is_empty() {
text: String, return self.clear_marked_text(cx);
range: Option<Range<usize>>, }
cx: &mut Context<Self>, self.ime_state = Some(ImeState { marked_text: text });
) {
self.ime_state = Some(ImeState {
marked_text: text,
marked_range_utf16: range,
});
cx.notify(); cx.notify();
} }
@@ -344,7 +338,7 @@ impl TerminalView {
pub(crate) fn marked_text_range(&self) -> Option<Range<usize>> { pub(crate) fn marked_text_range(&self) -> Option<Range<usize>> {
self.ime_state self.ime_state
.as_ref() .as_ref()
.and_then(|state| state.marked_range_utf16.clone()) .map(|state| 0..state.marked_text.encode_utf16().count())
} }
/// Clears the marked (pre-edit) text state. /// Clears the marked (pre-edit) text state.