From 46deca4f3f711753c839d441f55ff6e2a0d52798 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 12 Apr 2013 01:31:21 +0200 Subject: [PATCH] Add zj and zk command for scrolling the window --- README.asciidoc | 2 ++ src/main.cc | 6 ++++++ src/window.cc | 5 +++++ src/window.hh | 1 + 4 files changed, 14 insertions(+) diff --git a/README.asciidoc b/README.asciidoc index 2e127dcb..8e8762f3 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -148,6 +148,8 @@ window. * _zz_ or _zc_: center the main selection in the window * _zt_: scroll to put the main selection on the top line of the window * _zb_: scroll to put the main selection on the bottom line of the window + * _zj_: scroll the window count line downward + * _zk_: scroll the window count line upward Multi Selection --------------- diff --git a/src/main.cc b/src/main.cc index 81cabb17..1d7d7c28 100644 --- a/src/main.cc +++ b/src/main.cc @@ -167,6 +167,12 @@ void do_disp_cmd(Context& context) case 'b': context.window().display_selection_at(window.dimensions().line-1); break; + case 'j': + context.window().scroll( std::max(1, context.numeric_param())); + break; + case 'k': + context.window().scroll(-std::max(1, context.numeric_param())); + break; } }); } diff --git a/src/window.cc b/src/window.cc index 132c48fe..f77a200f 100644 --- a/src/window.cc +++ b/src/window.cc @@ -52,6 +52,11 @@ void Window::center_selection() display_selection_at(m_dimensions.line/2_line); } +void Window::scroll(LineCount offset) +{ + m_position.line = std::max(0_line, m_position.line + offset); +} + void Window::update_display_buffer() { scroll_to_keep_cursor_visible_ifn(); diff --git a/src/window.hh b/src/window.hh index b8cf0ddc..8f842f06 100644 --- a/src/window.hh +++ b/src/window.hh @@ -34,6 +34,7 @@ public: void center_selection(); void display_selection_at(LineCount line); + void scroll(LineCount offset); void update_display_buffer(); DisplayCoord display_position(const BufferIterator& it);