Skip to content

Commit

Permalink
Add some more missing vi input motions, such as y$, o$, and many …
Browse files Browse the repository at this point in the history
…others as initiated by `y` and `o` (#1441)

Signed-off-by: Christian Parpart <christian@parpart.family>
  • Loading branch information
christianparpart committed Jun 21, 2024
1 parent 9db2f16 commit 4dcb919
Show file tree
Hide file tree
Showing 2 changed files with 15 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
26 changes: 14 additions & 12 deletions src/vtbackend/ViInputHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,17 +177,15 @@ 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)
registerCommand(ModeSelect::Normal,
fmt::format("{}{}", key, motionChars),
[this, op, 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 +241,8 @@ 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 +359,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 +370,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 4dcb919

Please sign in to comment.