Skip to content

Commit 5c30578

Browse files
authored
linux: Fix IME preedit text not showing in Terminal on Wayland (#37701)
Closes #37268 Release Notes: - Fixed an issue where IME preedit text was not showing in the Terminal on Wayland.
1 parent 1552afd commit 5c30578

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

crates/terminal_view/src/terminal_element.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,8 +1192,8 @@ impl Element for TerminalElement {
11921192
bounds.origin + Point::new(layout.gutter, px(0.)) - Point::new(px(0.), scroll_top);
11931193

11941194
let marked_text_cloned: Option<String> = {
1195-
let ime_state = self.terminal_view.read(cx);
1196-
ime_state.marked_text.clone()
1195+
let ime_state = &self.terminal_view.read(cx).ime_state;
1196+
ime_state.as_ref().map(|state| state.marked_text.clone())
11971197
};
11981198

11991199
let terminal_input_handler = TerminalInputHandler {
@@ -1421,11 +1421,9 @@ impl InputHandler for TerminalInputHandler {
14211421
_window: &mut Window,
14221422
cx: &mut App,
14231423
) {
1424-
if let Some(range) = new_marked_range {
1425-
self.terminal_view.update(cx, |view, view_cx| {
1426-
view.set_marked_text(new_text.to_string(), range, view_cx);
1427-
});
1428-
}
1424+
self.terminal_view.update(cx, |view, view_cx| {
1425+
view.set_marked_text(new_text.to_string(), new_marked_range, view_cx);
1426+
});
14291427
}
14301428

14311429
fn unmark_text(&mut self, _window: &mut Window, cx: &mut App) {

crates/terminal_view/src/terminal_view.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ use std::{
6262
time::Duration,
6363
};
6464

65+
struct ImeState {
66+
marked_text: String,
67+
marked_range_utf16: Option<Range<usize>>,
68+
}
69+
6570
const CURSOR_BLINK_INTERVAL: Duration = Duration::from_millis(500);
6671
const TERMINAL_SCROLLBAR_WIDTH: Pixels = px(12.);
6772

@@ -138,8 +143,7 @@ pub struct TerminalView {
138143
scroll_handle: TerminalScrollHandle,
139144
show_scrollbar: bool,
140145
hide_scrollbar_task: Option<Task<()>>,
141-
marked_text: Option<String>,
142-
marked_range_utf16: Option<Range<usize>>,
146+
ime_state: Option<ImeState>,
143147
_subscriptions: Vec<Subscription>,
144148
_terminal_subscriptions: Vec<Subscription>,
145149
}
@@ -263,8 +267,7 @@ impl TerminalView {
263267
show_scrollbar: !Self::should_autohide_scrollbar(cx),
264268
hide_scrollbar_task: None,
265269
cwd_serialized: false,
266-
marked_text: None,
267-
marked_range_utf16: None,
270+
ime_state: None,
268271
_subscriptions: vec![
269272
focus_in,
270273
focus_out,
@@ -323,24 +326,27 @@ impl TerminalView {
323326
pub(crate) fn set_marked_text(
324327
&mut self,
325328
text: String,
326-
range: Range<usize>,
329+
range: Option<Range<usize>>,
327330
cx: &mut Context<Self>,
328331
) {
329-
self.marked_text = Some(text);
330-
self.marked_range_utf16 = Some(range);
332+
self.ime_state = Some(ImeState {
333+
marked_text: text,
334+
marked_range_utf16: range,
335+
});
331336
cx.notify();
332337
}
333338

334339
/// Gets the current marked range (UTF-16).
335340
pub(crate) fn marked_text_range(&self) -> Option<Range<usize>> {
336-
self.marked_range_utf16.clone()
341+
self.ime_state
342+
.as_ref()
343+
.and_then(|state| state.marked_range_utf16.clone())
337344
}
338345

339346
/// Clears the marked (pre-edit) text state.
340347
pub(crate) fn clear_marked_text(&mut self, cx: &mut Context<Self>) {
341-
if self.marked_text.is_some() {
342-
self.marked_text = None;
343-
self.marked_range_utf16 = None;
348+
if self.ime_state.is_some() {
349+
self.ime_state = None;
344350
cx.notify();
345351
}
346352
}

0 commit comments

Comments
 (0)