diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2015-07-07 22:36:27 +0100 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2015-07-07 22:36:27 +0100 |
| commit | 3c4400c5fd64f5da216e8a6c045d3d4cd2bd0d37 (patch) | |
| tree | dfa6b9084203bff1020ed38b88b7f8032f9304de /src | |
| parent | 1cbaac532339709da9f72ada02f838d689734eac (diff) | |
Change scrolloff behaviour, allow displaying pas the end of buffer
Fixes #306
Diffstat (limited to 'src')
| -rw-r--r-- | src/window.cc | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/src/window.cc b/src/window.cc index 3ff8754a..24a02cff 100644 --- a/src/window.cc +++ b/src/window.cc @@ -129,17 +129,18 @@ static LineCount adapt_view_pos(LineCount line, LineCount offset, LineCount view_pos, LineCount view_size, LineCount buffer_size) { + offset = std::min(offset, (view_size + 1) / 2); if (line - offset < view_pos) return std::max(0_line, line - offset); else if (line + offset >= view_pos + view_size) - return std::max(0_line, std::min(buffer_size - view_size, - line + offset - (view_size - 1))); + return std::max(0_line, line + offset - view_size); return view_pos; } static CharCount adapt_view_pos(const DisplayBuffer& display_buffer, CharCount offset, ByteCoord pos, CharCount view_pos, CharCount view_size) { + offset = std::min(offset, (view_size + 1) / 2); CharCount buffer_column = 0; CharCount non_buffer_column = 0; for (auto& line : display_buffer.lines()) @@ -186,10 +187,7 @@ void Window::scroll_to_keep_selection_visible_ifn(const Context& context) const auto& anchor = selection.anchor(); const auto& cursor = selection.cursor(); - const CharCoord max_offset{(m_dimensions.line - 1)/2, - (m_dimensions.column - 1)/2}; - const CharCoord offset = std::min(options()["scrolloff"].get<CharCoord>(), - max_offset); + const CharCoord offset = options()["scrolloff"].get<CharCoord>(); // scroll lines if needed, try to get as much of the selection visible as possible m_position.line = adapt_view_pos(anchor.line, offset.line, m_position.line, |
