From fb87c7ac9fb4b9f4a0080e71913047d0268aff65 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 11 Apr 2013 21:01:00 +0200 Subject: [PATCH] add Window::display_selection_at(LineCount) --- src/window.cc | 12 ++++++++++-- src/window.hh | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/window.cc b/src/window.cc index 54d7e6a2..132c48fe 100644 --- a/src/window.cc +++ b/src/window.cc @@ -38,10 +38,18 @@ Window::~Window() m_options.unregister_watcher(*this); } +void Window::display_selection_at(LineCount line) +{ + if (line >= 0 or line < m_dimensions.line) + { + auto cursor_line = main_selection().last().line(); + m_position.line = std::max(0_line, cursor_line - line); + } +} + void Window::center_selection() { - BufferIterator cursor = main_selection().last(); - m_position.line = std::max(0_line, cursor.line() - m_dimensions.line/2_line); + display_selection_at(m_dimensions.line/2_line); } void Window::update_display_buffer() diff --git a/src/window.hh b/src/window.hh index 9349c450..b8cf0ddc 100644 --- a/src/window.hh +++ b/src/window.hh @@ -33,6 +33,7 @@ public: const DisplayBuffer& display_buffer() const { return m_display_buffer; } void center_selection(); + void display_selection_at(LineCount line); void update_display_buffer(); DisplayCoord display_position(const BufferIterator& it);