Skip to content

Commit

Permalink
Handle set_ime_allowed
Browse files Browse the repository at this point in the history
  • Loading branch information
kchibisov committed Apr 5, 2022
1 parent 8730019 commit 7245394
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions alacritty/src/display/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ impl Window {
// Text cursor.
let current_mouse_cursor = CursorIcon::Text;
windowed_context.window().set_cursor_icon(current_mouse_cursor);

// Enable IME.
windowed_context.window().set_ime_allowed(true);

// Set OpenGL symbol loader. This call MUST be after window.make_current on windows.
Expand Down Expand Up @@ -464,6 +466,11 @@ impl Window {
self.window().set_ime_position(PhysicalPosition::new(nspot_x, nspot_y));
}

/// Enable or disable IME input for that window.
pub fn set_ime_allowed(&self, allowed: bool) {
self.window().set_ime_allowed(allowed);
}

pub fn swap_buffers(&self) {
self.windowed_context.swap_buffers().expect("swap buffers");
}
Expand Down
12 changes: 11 additions & 1 deletion alacritty/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,9 @@ impl<'a, N: Notify + 'a, T: EventListener> input::ActionContext<T> for ActionCon
};
}

// Enable IME so user can type using it.
self.window().set_ime_allowed(true);

self.display.pending_update.dirty = true;
*self.dirty = true;
}
Expand Down Expand Up @@ -770,7 +773,8 @@ impl<'a, N: Notify + 'a, T: EventListener> input::ActionContext<T> for ActionCon
/// Toggle the vi mode status.
#[inline]
fn toggle_vi_mode(&mut self) {
if self.terminal.mode().contains(TermMode::VI) {
let was_in_vi_mode = self.terminal.mode().contains(TermMode::VI);
if was_in_vi_mode {
// If we had search running when leaving Vi mode we should mark terminal fully damaged
// to cleanup highlighted results.
if self.search_state.dfas().is_some() {
Expand All @@ -787,6 +791,9 @@ impl<'a, N: Notify + 'a, T: EventListener> input::ActionContext<T> for ActionCon
self.cancel_search();
self.terminal.toggle_vi_mode();

// We don't want IME input for Vi mode.
self.window().set_ime_allowed(was_in_vi_mode);

*self.dirty = true;
}

Expand Down Expand Up @@ -918,6 +925,9 @@ impl<'a, N: Notify + 'a, T: EventListener> ActionContext<'a, N, T> {

/// Cleanup the search state.
fn exit_search(&mut self) {
let vi_mode = self.terminal.mode().contains(TermMode::VI);
self.window().set_ime_allowed(!vi_mode);

self.display.pending_update.dirty = true;
self.search_state.history_index = None;
*self.dirty = true;
Expand Down

0 comments on commit 7245394

Please sign in to comment.