1
0
Fork 0
mirror of https://github.com/alacritty/alacritty.git synced 2024-11-25 14:05:41 -05:00

Add IME support to inline search

This changes the behavior of inline search from only accepting direct
key inputs, to also accepting IME and paste. The additional characters
are still being discarded, matching the existing behavior.

This also fixes an issue where inline search wouldn't work for
characters requiring modifiers, since the modifier press was interpreted
as the search target instead.

Closes #8208.
This commit is contained in:
Christian Duerr 2024-10-15 14:06:59 +00:00
parent b56a0e86b7
commit a720a765b4
5 changed files with 31 additions and 12 deletions

View file

@ -50,6 +50,7 @@ Notable changes to the `alacritty_terminal` crate are documented in its
- Alacritty not being properly activated with startup notify
- Invalid URL highlights after terminal scrolling
- Hollow block cursor not spanning multiple chars being edited inside the IME preview
- Vi inline search only working for direct key input without modifiers
## 0.13.2

View file

@ -884,8 +884,11 @@ impl Display {
},
None => {
let num_lines = self.size_info.screen_lines();
term::point_to_viewport(display_offset, cursor_point)
.filter(|point| point.line < num_lines)
match vi_cursor_viewport_point {
None => term::point_to_viewport(display_offset, cursor_point)
.filter(|point| point.line < num_lines),
point => point,
}
},
};

View file

@ -1218,6 +1218,8 @@ impl<'a, N: Notify + 'a, T: EventListener> input::ActionContext<T> for ActionCon
for c in text.chars() {
self.search_input(c);
}
} else if self.inline_search_state.char_pending {
self.inline_search_input(text);
} else if bracketed && self.terminal().mode().contains(TermMode::BRACKETED_PASTE) {
self.on_terminal_input_start();
@ -1291,6 +1293,7 @@ impl<'a, N: Notify + 'a, T: EventListener> input::ActionContext<T> for ActionCon
self.inline_search_state.stop_short = stop_short;
self.inline_search_state.direction = direction;
self.inline_search_state.char_pending = true;
self.inline_search_state.character = None;
}
/// Jump to the next matching character in the line.
@ -1305,6 +1308,22 @@ impl<'a, N: Notify + 'a, T: EventListener> input::ActionContext<T> for ActionCon
self.inline_search(direction);
}
/// Process input during inline search.
fn inline_search_input(&mut self, text: &str) {
// Ignore input with empty text, like modifier keys.
let c = match text.chars().next() {
Some(c) => c,
None => return,
};
self.inline_search_state.char_pending = false;
self.inline_search_state.character = Some(c);
self.window().set_ime_allowed(false);
// Immediately move to the captured character.
self.inline_search_next();
}
fn message(&self) -> Option<&Message> {
self.message_buffer.message()
}

View file

@ -1,5 +1,4 @@
use std::borrow::Cow;
use std::mem;
use winit::event::{ElementState, KeyEvent};
#[cfg(target_os = "macos")]
@ -29,6 +28,9 @@ impl<T: EventListener, A: ActionContext<T>> Processor<T, A> {
let mods = self.ctx.modifiers().state();
if key.state == ElementState::Released {
if self.ctx.inline_search_state().char_pending {
self.ctx.window().set_ime_allowed(true);
}
self.key_release(key, mode, mods);
return;
}
@ -45,15 +47,8 @@ impl<T: EventListener, A: ActionContext<T>> Processor<T, A> {
// First key after inline search is captured.
let inline_state = self.ctx.inline_search_state();
if mem::take(&mut inline_state.char_pending) {
if let Some(c) = text.chars().next() {
inline_state.character = Some(c);
// Immediately move to the captured character.
self.ctx.inline_search_next();
}
// Ignore all other characters in `text`.
if inline_state.char_pending {
self.ctx.inline_search_input(text);
return;
}

View file

@ -127,6 +127,7 @@ pub trait ActionContext<T: EventListener> {
fn inline_search_state(&mut self) -> &mut InlineSearchState;
fn start_inline_search(&mut self, _direction: Direction, _stop_short: bool) {}
fn inline_search_next(&mut self) {}
fn inline_search_input(&mut self, _text: &str) {}
fn inline_search_previous(&mut self) {}
fn hint_input(&mut self, _character: char) {}
fn trigger_hint(&mut self, _hint: &HintMatch) {}