Skip to content

Commit

Permalink
Merge pull request #1531 from contour-terminal/fix/vi-input-mode-miss…
Browse files Browse the repository at this point in the history
…ing-motions

Add some more missing vi input motions, such as `y$`, `o$`, and many others as initiated by `y` and `o`
  • Loading branch information
christianparpart authored Jun 21, 2024
2 parents 27130ce + 938d577 commit cfdc48e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
1 change: 1 addition & 0 deletions metainfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
<li>Add SGRSAVE and SGRRESTORE VT sequences to save and restore SGR state (They intentionally conflict with XTPUSHSGR and XTPOPSGR)</li>
<li>Add extended word selection feature (#1023)</li>
<li>Add extended word selection feature (#1023)</li>
<li>Add some more missing vi input motions, such as `y$`, `o$`, and many others as initiated by `y` and `o` (#1441)</li>
<li>Add shell integration for bash shell.</li>
<li>Add better bell sound (#1378)</li>
<li>Add config entry to configure behaviour on exit from search mode</li>
Expand Down
30 changes: 18 additions & 12 deletions src/vtbackend/ViInputHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,17 +177,18 @@ void ViInputHandler::registerAllCommands()
char const key = theKey;
ViOperator const op = viOperator;

auto const s1 = [](char ch) { return std::string(1, ch); };
registerCommand(ModeSelect::Normal, s1(toupper(key)), [this, op]() { _executor->execute(op, ViMotion::FullLine, count()); });

auto const s2 = [key](char ch) { return fmt::format("{}{}", key, ch); };
registerCommand(ModeSelect::Normal, s2(key), [this, op]() { _executor->execute(op, ViMotion::FullLine, count()); });
registerCommand(ModeSelect::Normal, s2('b'), [this, op]() { _executor->execute(op, ViMotion::WordBackward, count()); });
registerCommand(ModeSelect::Normal, s2('e'), [this, op]() { _executor->execute(op, ViMotion::WordEndForward, count()); });
registerCommand(ModeSelect::Normal, s2('w'), [this, op]() { _executor->execute(op, ViMotion::WordForward, count()); });
registerCommand(ModeSelect::Normal, s2('B'), [this, op]() { _executor->execute(op, ViMotion::BigWordBackward, count()); });
registerCommand(ModeSelect::Normal, s2('E'), [this, op]() { _executor->execute(op, ViMotion::BigWordEndForward, count()); });
registerCommand(ModeSelect::Normal, s2('W'), [this, op]() { _executor->execute(op, ViMotion::BigWordForward, count()); });
// operate on the full line, with yy or oo.
registerCommand(ModeSelect::Normal,
fmt::format("{}{}", key, key),
[this, op]() { _executor->execute(op, ViMotion::FullLine, count()); });

for (auto && [motionChars, motion]: MotionMappings)
{
// Passing motion as motion=motion (new variable) is yet another workaround for Clang 15 (Ubuntu) this time.
registerCommand(ModeSelect::Normal,
fmt::format("{}{}", key, motionChars),
[this, op, motion=motion]() { _executor->execute(op, motion, count()); });
}

auto const s3 = [key](char ch) { return fmt::format("{}{}.", key, ch); };
registerCommand(ModeSelect::Normal, s3('t'), [this, op]() { _executor->execute(op, ViMotion::TillBeforeCharRight, count(), _lastChar); });
Expand Down Expand Up @@ -243,6 +244,9 @@ void ViInputHandler::registerCommand(ModeSelect modes, std::string_view command,

auto commandStr = crispy::replace(std::string(command.data(), command.size()), "<Space>", " ");

inputLog()(
"Registering command: {} in mode: {}", commandStr, modes == ModeSelect::Normal ? "Normal" : "Visual");

switch (modes)
{
case ModeSelect::Normal: {
Expand Down Expand Up @@ -359,7 +363,7 @@ Handled ViInputHandler::sendKeyPressEvent(Key key, Modifiers modifiers, Keyboard
}
// clang-format on

auto const charMappings = std::array<std::pair<Key, char32_t>, 10> { {
auto const charMappings = std::array<std::pair<Key, char32_t>, 12> { {
{ Key::Numpad_0, '0' },
{ Key::Numpad_1, '1' },
{ Key::Numpad_2, '2' },
Expand All @@ -370,6 +374,8 @@ Handled ViInputHandler::sendKeyPressEvent(Key key, Modifiers modifiers, Keyboard
{ Key::Numpad_7, '7' },
{ Key::Numpad_8, '8' },
{ Key::Numpad_9, '9' },
{ Key::Backspace, '\b' },
{ Key::Enter, '\n' },
} };

for (auto const& [mappedKey, mappedText]: charMappings)
Expand Down

0 comments on commit cfdc48e

Please sign in to comment.