aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Duerr <contact@christianduerr.com>2024-10-15 14:06:59 +0000
committerGitHub <noreply@github.com>2024-10-15 17:06:59 +0300
commit6ba69f8dd469e1a9aff0b48b3ae10ce4510ca1e3 (patch)
tree39f86be15c954a2337fb30de92e38235deb7d024
parenta5bb567c0a15bed65ff18c94d04c8c147bf817a9 (diff)
downloadalacritty-6ba69f8dd469e1a9aff0b48b3ae10ce4510ca1e3.tar.gz
alacritty-6ba69f8dd469e1a9aff0b48b3ae10ce4510ca1e3.zip
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.
-rw-r--r--CHANGELOG.md1
-rw-r--r--alacritty/src/display/mod.rs7
-rw-r--r--alacritty/src/event.rs19
-rw-r--r--alacritty/src/input/keyboard.rs15
-rw-r--r--alacritty/src/input/mod.rs1
5 files changed, 31 insertions, 12 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e9d8d3ff..7dff2d54 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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
diff --git a/alacritty/src/display/mod.rs b/alacritty/src/display/mod.rs
index a8501da6..d0044f8b 100644
--- a/alacritty/src/display/mod.rs
+++ b/alacritty/src/display/mod.rs
@@ -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,
+ }
},
};
diff --git a/alacritty/src/event.rs b/alacritty/src/event.rs
index 46e9433c..23575e21 100644
--- a/alacritty/src/event.rs
+++ b/alacritty/src/event.rs
@@ -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()
}
diff --git a/alacritty/src/input/keyboard.rs b/alacritty/src/input/keyboard.rs
index 4bc3ffee..14755594 100644
--- a/alacritty/src/input/keyboard.rs
+++ b/alacritty/src/input/keyboard.rs
@@ -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;
}
diff --git a/alacritty/src/input/mod.rs b/alacritty/src/input/mod.rs
index c10777f2..bbd8673f 100644
--- a/alacritty/src/input/mod.rs
+++ b/alacritty/src/input/mod.rs
@@ -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) {}