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

Implement CenterCursor vi motion #1700

Merged
merged 1 commit into from
Jan 3, 2025
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 @@ -111,6 +111,7 @@
<li>Adds `MoveTabToLeft` and `MoveTabToRight` actions to move tabs around (#1695)</li>
<li>Adds `MoveTabTo` action to move tabs to a specific position (#1695)</li>
<li>Ensure inserting new tabs happens right next to the currently active tab (#1695)</li>
<li>Adds CenterCursor (`zz`) vi motion</li>
</ul>
</description>
</release>
Expand Down
5 changes: 5 additions & 0 deletions src/vtbackend/ViCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,11 @@ CellLocation ViCommands::translateToCellLocationAndRecord(ViMotion motion, unsig
case ViMotion::JumpToLastJumpPoint: return _jumpHistory.jumpToLast(cursorPosition);
case ViMotion::JumpToMarkBackward: return _jumpHistory.jumpToMarkBackward(cursorPosition);
case ViMotion::JumpToMarkForward: return _jumpHistory.jumpToMarkForward(cursorPosition);
case ViMotion::CenterCursor: {
_terminal->viewport().makeVisibleWithinSafeArea(unbox<LineOffset>(cursorPosition.line),
LineCount(_terminal->pageSize().lines / 2));
return cursorPosition;
}
}
crispy::unreachable();
}
Expand Down
3 changes: 2 additions & 1 deletion src/vtbackend/ViInputHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void ViInputHandler::registerAllCommands()
std::array<std::pair<char, TextObjectScope>, 2> { { std::pair { 'i', TextObjectScope::Inner },
std::pair { 'a', TextObjectScope::A } } };

auto constexpr MotionMappings = std::array<std::pair<std::string_view, ViMotion>, 47> { {
auto constexpr MotionMappings = std::array<std::pair<std::string_view, ViMotion>, 48> { {
// clang-format off
{ "$", ViMotion::LineEnd },
{ "%", ViMotion::ParenthesisMatching },
Expand Down Expand Up @@ -118,6 +118,7 @@ void ViInputHandler::registerAllCommands()
{ "``",ViMotion::JumpToLastJumpPoint },
{ "C-O",ViMotion::JumpToMarkBackward },
{ "C-I",ViMotion::JumpToMarkForward },
{ "zz",ViMotion::CenterCursor },
// clang-format on
} };

Expand Down
2 changes: 2 additions & 0 deletions src/vtbackend/ViInputHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ enum class ViMotion : uint8_t
JumpToLastJumpPoint, // '' or `` (jump to last jump)
JumpToMarkBackward, // <C-O>
JumpToMarkForward, // <C-I>
CenterCursor, // zz
};

enum class ViOperator : uint8_t
Expand Down Expand Up @@ -383,6 +384,7 @@ struct std::formatter<vtbackend::ViMotion>: formatter<std::string_view>
case ViMotion::GlobalCurlyOpenDown: name = "GlobalCurlyOpenDown"; break;
case ViMotion::LineMarkUp: name = "LineMarkUp"; break;
case ViMotion::LineMarkDown: name = "LineMarkDown"; break;
case ViMotion::CenterCursor: name = "CenterCursor"; break;
}
return formatter<string_view>::format(name, ctx);
}
Expand Down
Loading