Skip to content

Commit

Permalink
Merge pull request contour-terminal#1700 from contour-terminal/featur…
Browse files Browse the repository at this point in the history
…es/vi_motion_zz

Implement CenterCursor vi motion
  • Loading branch information
Yaraslaut authored Jan 3, 2025
2 parents b1eeafa + ec04588 commit ccb590a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
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

0 comments on commit ccb590a

Please sign in to comment.