Skip to content

Commit

Permalink
Merge pull request #1614 from contour-terminal/fix/arrow_word_navigat…
Browse files Browse the repository at this point in the history
…ion_macos

Fix macOS specific key handling
  • Loading branch information
Yaraslaut authored Oct 28, 2024
2 parents 1b32bf0 + 139b7c7 commit 1cc177f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions metainfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
<li>Add binding to exit normal mode with `Esc` (#1604)</li>
<li>Add config option to switch into insert mode after yank (#1604)</li>
<li>Improves window size/resize handling on HiDPI monitor settings (#1628)</li>
<li>Improves macOS key handling for Option+Left|Right keys to jump between words in the shell</li>
<li>Fixes cropping of underscore character for some fonts (#1603)</li>
</ul>
</description>
Expand Down
6 changes: 6 additions & 0 deletions src/vtbackend/InputGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ using Modifiers = crispy::flags<Modifier>;
/// @returns CSI parameter for given function key modifier
constexpr size_t makeVirtualTerminalParam(Modifiers modifier) noexcept
{
#if defined(__APPLE__)
// Use option key as a control modifier to use
// Ctrl-Left[Right]Arrow for word navigation.
if (modifier == Modifier::Alt)
return 1 + Modifier::Control;
#endif
return 1 + modifier.value();
}

Expand Down
7 changes: 7 additions & 0 deletions src/vtbackend/InputGenerator_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,17 @@ TEST_CASE("InputGenerator.Modifier+ArrowKeys", "[terminal,input]")
Mapping { Shift, Key::DownArrow, "\033[1;2B"sv },
Mapping { Shift, Key::RightArrow, "\033[1;2C"sv },
Mapping { Shift, Key::LeftArrow, "\033[1;2D"sv },
#ifdef __APPLE__
Mapping { Alt, Key::UpArrow, "\033[1;5A"sv },
Mapping { Alt, Key::DownArrow, "\033[1;5B"sv },
Mapping { Alt, Key::RightArrow, "\033[1;5C"sv },
Mapping { Alt, Key::LeftArrow, "\033[1;5D"sv },
#else
Mapping { Alt, Key::UpArrow, "\033[1;3A"sv },
Mapping { Alt, Key::DownArrow, "\033[1;3B"sv },
Mapping { Alt, Key::RightArrow, "\033[1;3C"sv },
Mapping { Alt, Key::LeftArrow, "\033[1;3D"sv },
#endif
Mapping { Control, Key::UpArrow, "\033[1;5A"sv },
Mapping { Control, Key::DownArrow, "\033[1;5B"sv },
Mapping { Control, Key::RightArrow, "\033[1;5C"sv },
Expand Down

0 comments on commit 1cc177f

Please sign in to comment.