Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(keybindings): support multiple modifiers (eg. Ctrl+Alt) and the kitty keyboard protocol #3383

Merged
merged 15 commits into from
May 27, 2024
Prev Previous commit
Next Next commit
replace internal Key representation with the new KeyWithModifier in a…
…ll the places
  • Loading branch information
imsnif committed May 16, 2024
commit 34ae0a741419afc02d702a3496ce9c7a96433af9
118 changes: 59 additions & 59 deletions default-plugins/status-bar/src/first_line.rs

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions default-plugins/status-bar/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -766,23 +766,23 @@ pub mod tests {
let keyvec = vec![
KeyWithModifier::new(BareKey::Char('a')).with_alt_modifier(),
KeyWithModifier::new(BareKey::Char('b')).with_ctrl_modifier(),
KeyWithModifier::new(BareKey::Char('a')),
KeyWithModifier::new(BareKey::Char('c')),
];
let palette = get_palette();

let ret = style_key_with_modifier(&keyvec, &palette, None);
let ret = unstyle(&ANSIStrings(&ret));

assert_eq!(ret, "<Alt+a|Ctrl+b|c>".to_string())
assert_eq!(ret, "<Alt a|Ctrl b|c>".to_string())
}

#[test]
fn style_key_with_modifier_unprintables() {
let keyvec = vec![
KeyWithModifier::new(BareKey::Backspace),
KeyWithModifier::new(BareKey::Char('\n')),
KeyWithModifier::new(BareKey::Enter),
KeyWithModifier::new(BareKey::Char(' ')),
KeyWithModifier::new(BareKey::Char('\t')),
KeyWithModifier::new(BareKey::Tab),
KeyWithModifier::new(BareKey::PageDown),
KeyWithModifier::new(BareKey::Delete),
KeyWithModifier::new(BareKey::Home),
Expand Down
74 changes: 43 additions & 31 deletions default-plugins/status-bar/src/second_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ mod tests {

#[test]
fn full_length_shortcut_with_key() {
let keyvec = vec![Key::Char('a')];
let keyvec = vec![KeyWithModifier::new(BareKey::Char('a'))];
let palette = get_palette();

let ret = full_length_shortcut(false, keyvec, "Foobar", palette);
Expand All @@ -571,7 +571,7 @@ mod tests {

#[test]
fn full_length_shortcut_with_key_first_element() {
let keyvec = vec![Key::Char('a')];
let keyvec = vec![KeyWithModifier::new(BareKey::Char('a'))];
let palette = get_palette();

let ret = full_length_shortcut(true, keyvec, "Foobar", palette);
Expand All @@ -594,7 +594,7 @@ mod tests {

#[test]
fn full_length_shortcut_with_key_unprintable_1() {
let keyvec = vec![Key::Char('\n')];
let keyvec = vec![KeyWithModifier::new(BareKey::Enter)];
let palette = get_palette();

let ret = full_length_shortcut(false, keyvec, "Foobar", palette);
Expand All @@ -605,7 +605,7 @@ mod tests {

#[test]
fn full_length_shortcut_with_key_unprintable_2() {
let keyvec = vec![Key::Backspace];
let keyvec = vec![KeyWithModifier::new(BareKey::Backspace)];
let palette = get_palette();

let ret = full_length_shortcut(false, keyvec, "Foobar", palette);
Expand All @@ -616,7 +616,7 @@ mod tests {

#[test]
fn full_length_shortcut_with_ctrl_key() {
let keyvec = vec![Key::Ctrl('a')];
let keyvec = vec![KeyWithModifier::new(BareKey::Char('a')).with_ctrl_modifier()];
let palette = get_palette();

let ret = full_length_shortcut(false, keyvec, "Foobar", palette);
Expand All @@ -627,7 +627,7 @@ mod tests {

#[test]
fn full_length_shortcut_with_alt_key() {
let keyvec = vec![Key::Alt(CharOrArrow::Char('a'))];
let keyvec = vec![KeyWithModifier::new(BareKey::Char('a')).with_alt_modifier()];
let palette = get_palette();

let ret = full_length_shortcut(false, keyvec, "Foobar", palette);
Expand All @@ -638,7 +638,11 @@ mod tests {

#[test]
fn full_length_shortcut_with_homogenous_key_group() {
let keyvec = vec![Key::Char('a'), Key::Char('b'), Key::Char('c')];
let keyvec = vec![
KeyWithModifier::new(BareKey::Char('a')),
KeyWithModifier::new(BareKey::Char('b')),
KeyWithModifier::new(BareKey::Char('c')),
];
let palette = get_palette();

let ret = full_length_shortcut(false, keyvec, "Foobar", palette);
Expand All @@ -649,18 +653,26 @@ mod tests {

#[test]
fn full_length_shortcut_with_heterogenous_key_group() {
let keyvec = vec![Key::Char('a'), Key::Ctrl('b'), Key::Char('\n')];
let keyvec = vec![
KeyWithModifier::new(BareKey::Char('a')),
KeyWithModifier::new(BareKey::Char('b')).with_ctrl_modifier(),
KeyWithModifier::new(BareKey::Enter),
];
let palette = get_palette();

let ret = full_length_shortcut(false, keyvec, "Foobar", palette);
let ret = unstyle(ret);

assert_eq!(ret, " / <a|Ctrl+b|ENTER> Foobar");
assert_eq!(ret, " / <a|Ctrl b|ENTER> Foobar");
}

#[test]
fn full_length_shortcut_with_key_group_shared_ctrl_modifier() {
let keyvec = vec![Key::Ctrl('a'), Key::Ctrl('b'), Key::Ctrl('c')];
let keyvec = vec![
KeyWithModifier::new(BareKey::Char('a')).with_ctrl_modifier(),
KeyWithModifier::new(BareKey::Char('b')).with_ctrl_modifier(),
KeyWithModifier::new(BareKey::Char('c')).with_ctrl_modifier(),
];
let palette = get_palette();

let ret = full_length_shortcut(false, keyvec, "Foobar", palette);
Expand All @@ -678,14 +690,14 @@ mod tests {
keybinds: vec![(
InputMode::Pane,
vec![
(Key::Left, vec![Action::MoveFocus(Direction::Left)]),
(Key::Down, vec![Action::MoveFocus(Direction::Down)]),
(Key::Up, vec![Action::MoveFocus(Direction::Up)]),
(Key::Right, vec![Action::MoveFocus(Direction::Right)]),
(Key::Char('n'), vec![Action::NewPane(None, None), TO_NORMAL]),
(Key::Char('x'), vec![Action::CloseFocus, TO_NORMAL]),
(KeyWithModifier::new(BareKey::Left), vec![Action::MoveFocus(Direction::Left)]),
(KeyWithModifier::new(BareKey::Down), vec![Action::MoveFocus(Direction::Down)]),
(KeyWithModifier::new(BareKey::Up), vec![Action::MoveFocus(Direction::Up)]),
(KeyWithModifier::new(BareKey::Right), vec![Action::MoveFocus(Direction::Right)]),
(KeyWithModifier::new(BareKey::Char('n')), vec![Action::NewPane(None, None), TO_NORMAL]),
(KeyWithModifier::new(BareKey::Char('x')), vec![Action::CloseFocus, TO_NORMAL]),
(
Key::Char('f'),
KeyWithModifier::new(BareKey::Char('f')),
vec![Action::ToggleFocusFullscreen, TO_NORMAL],
),
],
Expand All @@ -710,14 +722,14 @@ mod tests {
keybinds: vec![(
InputMode::Pane,
vec![
(Key::Left, vec![Action::MoveFocus(Direction::Left)]),
(Key::Down, vec![Action::MoveFocus(Direction::Down)]),
(Key::Up, vec![Action::MoveFocus(Direction::Up)]),
(Key::Right, vec![Action::MoveFocus(Direction::Right)]),
(Key::Char('n'), vec![Action::NewPane(None, None), TO_NORMAL]),
(Key::Char('x'), vec![Action::CloseFocus, TO_NORMAL]),
(KeyWithModifier::new(BareKey::Left), vec![Action::MoveFocus(Direction::Left)]),
(KeyWithModifier::new(BareKey::Down), vec![Action::MoveFocus(Direction::Down)]),
(KeyWithModifier::new(BareKey::Up), vec![Action::MoveFocus(Direction::Up)]),
(KeyWithModifier::new(BareKey::Right), vec![Action::MoveFocus(Direction::Right)]),
(KeyWithModifier::new(BareKey::Char('n')), vec![Action::NewPane(None, None), TO_NORMAL]),
(KeyWithModifier::new(BareKey::Char('x')), vec![Action::CloseFocus, TO_NORMAL]),
(
Key::Char('f'),
KeyWithModifier::new(BareKey::Char('f')),
vec![Action::ToggleFocusFullscreen, TO_NORMAL],
),
],
Expand All @@ -738,13 +750,13 @@ mod tests {
keybinds: vec![(
InputMode::Pane,
vec![
(Key::Ctrl('a'), vec![Action::MoveFocus(Direction::Left)]),
(Key::Ctrl('\n'), vec![Action::MoveFocus(Direction::Down)]),
(Key::Ctrl('1'), vec![Action::MoveFocus(Direction::Up)]),
(Key::Ctrl(' '), vec![Action::MoveFocus(Direction::Right)]),
(Key::Backspace, vec![Action::NewPane(None, None), TO_NORMAL]),
(Key::Esc, vec![Action::CloseFocus, TO_NORMAL]),
(Key::End, vec![Action::ToggleFocusFullscreen, TO_NORMAL]),
(KeyWithModifier::new(BareKey::Char('a')).with_ctrl_modifier(), vec![Action::MoveFocus(Direction::Left)]),
(KeyWithModifier::new(BareKey::Enter).with_ctrl_modifier(), vec![Action::MoveFocus(Direction::Down)]),
(KeyWithModifier::new(BareKey::Char('1')).with_ctrl_modifier(), vec![Action::MoveFocus(Direction::Up)]),
(KeyWithModifier::new(BareKey::Char(' ')).with_ctrl_modifier(), vec![Action::MoveFocus(Direction::Right)]),
(KeyWithModifier::new(BareKey::Backspace), vec![Action::NewPane(None, None), TO_NORMAL]),
(KeyWithModifier::new(BareKey::Esc), vec![Action::CloseFocus, TO_NORMAL]),
(KeyWithModifier::new(BareKey::End), vec![Action::ToggleFocusFullscreen, TO_NORMAL]),
],
)],
..ModeInfo::default()
Expand Down
Loading