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

This commit is contained in:
ᴀᴍᴛᴏᴀᴇʀ 2026-01-14 15:00:30 +08:00 committed by GitHub
parent 22415e5f49
commit a1263830bb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 14 deletions

View file

@ -1488,12 +1488,12 @@ impl InputHandler for TerminalInputHandler {
&mut self,
_range_utf16: Option<std::ops::Range<usize>>,
new_text: &str,
new_marked_range: Option<std::ops::Range<usize>>,
_new_marked_range: Option<std::ops::Range<usize>>,
_window: &mut Window,
cx: &mut App,
) {
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);
});
}

View file

@ -62,7 +62,6 @@ use std::{
struct ImeState {
marked_text: String,
marked_range_utf16: Option<Range<usize>>,
}
const CURSOR_BLINK_INTERVAL: Duration = Duration::from_millis(500);
@ -327,16 +326,11 @@ impl TerminalView {
}
/// Sets the marked (pre-edit) text from the IME.
pub(crate) fn set_marked_text(
&mut self,
text: String,
range: Option<Range<usize>>,
cx: &mut Context<Self>,
) {
self.ime_state = Some(ImeState {
marked_text: text,
marked_range_utf16: range,
});
pub(crate) fn set_marked_text(&mut self, text: String, cx: &mut Context<Self>) {
if text.is_empty() {
return self.clear_marked_text(cx);
}
self.ime_state = Some(ImeState { marked_text: text });
cx.notify();
}
@ -344,7 +338,7 @@ impl TerminalView {
pub(crate) fn marked_text_range(&self) -> Option<Range<usize>> {
self.ime_state
.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.