1
0
Fork 0
mirror of https://github.com/alacritty/alacritty.git synced 2024-11-18 13:55:23 -05:00

Allow mode-exclusive bindings in any mode

This patch enables binding chains that go beyond mode changes by
allowing bindings to be defined for modes they do not usually have an
effect in.

Fixes #4073.
This commit is contained in:
Christian Duerr 2023-04-09 22:29:48 +02:00 committed by Kirill Chibisov
parent 6dd9dd0aa8
commit a173738c58
No known key found for this signature in database
GPG key ID: E803FF4B6CE71BCB
4 changed files with 17 additions and 20 deletions

View file

@ -7,6 +7,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## 0.13.0-dev
### Changed
- Mode-specific bindings can now be bound in any mode for easier macros
### Fixed
- Character `;` inside the `URI` in `OSC 8` sequence breaking the URI

View file

@ -1114,26 +1114,8 @@ impl<'a> Deserialize<'a> for RawBinding {
let action = match (action, chars, command) {
(Some(action @ Action::ViMotion(_)), None, None)
| (Some(action @ Action::Vi(_)), None, None) => {
if !mode.intersects(BindingMode::VI) || not_mode.intersects(BindingMode::VI)
{
return Err(V::Error::custom(format!(
"action `{}` is only available in vi mode, try adding `mode: Vi`",
action,
)));
}
action
},
(Some(action @ Action::Search(_)), None, None) => {
if !mode.intersects(BindingMode::SEARCH) {
return Err(V::Error::custom(format!(
"action `{}` is only available in search mode, try adding `mode: \
Search`",
action,
)));
}
action
},
| (Some(action @ Action::Vi(_)), None, None) => action,
(Some(action @ Action::Search(_)), None, None) => action,
(Some(action @ Action::Mouse(_)), None, None) => {
if mouse.is_none() {
return Err(V::Error::custom(format!(

View file

@ -496,6 +496,7 @@ impl<'a, N: Notify + 'a, T: EventListener> input::ActionContext<T> for ActionCon
// Enable IME so we can input into the search bar with it if we were in Vi mode.
self.window().set_ime_allowed(true);
self.terminal.mark_fully_damaged();
self.display.pending_update.dirty = true;
}
@ -983,6 +984,7 @@ impl<'a, N: Notify + 'a, T: EventListener> ActionContext<'a, N, T> {
let vi_mode = self.terminal.mode().contains(TermMode::VI);
self.window().set_ime_allowed(!vi_mode);
self.terminal.mark_fully_damaged();
self.display.pending_update.dirty = true;
self.search_state.history_index = None;

View file

@ -14,6 +14,7 @@ use std::marker::PhantomData;
use std::mem;
use std::time::{Duration, Instant};
use log::debug;
use winit::dpi::PhysicalPosition;
use winit::event::{
ElementState, KeyboardInput, ModifiersState, MouseButton, MouseScrollDelta,
@ -162,6 +163,11 @@ impl<T: EventListener> Execute<T> for Action {
ctx.on_typing_start();
ctx.toggle_vi_mode()
},
action @ (Action::ViMotion(_) | Action::Vi(_))
if !ctx.terminal().mode().contains(TermMode::VI) =>
{
debug!("Ignoring {action:?}: Vi mode inactive");
},
Action::ViMotion(motion) => {
ctx.on_typing_start();
ctx.terminal_mut().vi_motion(*motion);
@ -246,6 +252,9 @@ impl<T: EventListener> Execute<T> for Action {
ctx.scroll(Scroll::Delta(scroll_lines));
},
action @ Action::Search(_) if !ctx.search_active() => {
debug!("Ignoring {action:?}: Search mode inactive");
},
Action::Search(SearchAction::SearchFocusNext) => {
ctx.advance_search_origin(ctx.search_direction());
},