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

Add some more missing vi input motions, such as y$, o$, and many others as initiated by y and o #1531

Merged
merged 1 commit into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading