diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2013-06-29 16:50:51 +0200 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2013-06-29 16:50:51 +0200 |
| commit | 2dcdc0cf4b749708cc48fa1ef23a1523023be6ba (patch) | |
| tree | 4eb4ea3397ce1118a4669c42092bdae1dcc105b2 /src | |
| parent | e510bf8b9655da59171899604c3d10955144ac0d (diff) | |
more horizontal scrolling fixes
Diffstat (limited to 'src')
| -rw-r--r-- | src/window.cc | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/src/window.cc b/src/window.cc index 6072c142..8e8f2ee8 100644 --- a/src/window.cc +++ b/src/window.cc @@ -112,7 +112,6 @@ void Window::scroll_to_keep_cursor_visible_ifn() { const auto& first = main_selection().first(); const auto& last = main_selection().last(); - const String& content = buffer()[last.line]; const LineCount offset = std::min<LineCount>(options()["scrolloff"].get<int>(), (m_dimensions.line - 1) / 2); @@ -138,30 +137,28 @@ void Window::scroll_to_keep_cursor_visible_ifn() // (this is only valid if highlighting one line and multiple lines put // the cursor in the same position, however I do not find any sane example // of highlighters not doing that) - CharCount column = 0; + auto cursor = buffer().iterator_at(last); + CharCount buffer_column = 0; + CharCount non_buffer_column = 0; for (auto& atom : lines.back()) { - if (atom.content.has_buffer_range() and - atom.content.begin() <= last and atom.content.end() > last) + if (atom.content.has_buffer_range()) { - column += atom.content.length(); - - auto first_col = (first.line == last.line) ? content.char_count_to(first.column) : 0_char; - auto last_col = content.char_count_to(last.column); - - if (first_col < m_position.column) - m_position.column = first_col; - else if (column >= m_position.column + m_dimensions.column) - m_position.column = column - m_dimensions.column; + if (atom.content.begin() <= last and atom.content.end() > last) + { + if (buffer_column < m_position.column) + m_position.column = buffer_column; - if (last_col < m_position.column) - m_position.column = last_col; - else if (column >= m_position.column + m_dimensions.column) - m_position.column = column - m_dimensions.column; + auto last_column = buffer_column + atom.content.length(); + if (last_column >= m_position.column + m_dimensions.column - non_buffer_column) + m_position.column = last_column - m_dimensions.column + non_buffer_column; - return; + return; + } + buffer_column += atom.content.length(); } - column += atom.content.content().char_length(); + else + non_buffer_column += atom.content.length(); } if (not buffer().is_end(last)) { |
