From 50cacc0758ea7e6acd7dcc350f8dbb2e6559a30e Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 11 Jul 2022 18:17:51 +1000 Subject: [PATCH] Fix buffer location of column highlighter's past-eol atoms Using buffer end was confusing Window::display_position that assumes display atom buffer locations are always increasing. --- src/display_buffer.cc | 3 ++- src/display_buffer.hh | 2 +- src/highlighters.cc | 8 ++++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/display_buffer.cc b/src/display_buffer.cc index a1dfbc36..2b377310 100644 --- a/src/display_buffer.cc +++ b/src/display_buffer.cc @@ -134,7 +134,7 @@ DisplayLine::iterator DisplayLine::insert(iterator it, DisplayAtom atom) return res; } -void DisplayLine::push_back(DisplayAtom atom) +DisplayAtom& DisplayLine::push_back(DisplayAtom atom) { if (atom.has_buffer_range()) { @@ -142,6 +142,7 @@ void DisplayLine::push_back(DisplayAtom atom) m_range.end = std::max(m_range.end, atom.end()); } m_atoms.push_back(std::move(atom)); + return m_atoms.back(); } DisplayLine::iterator DisplayLine::erase(iterator beg, iterator end) diff --git a/src/display_buffer.hh b/src/display_buffer.hh index ec5da89e..6d739095 100644 --- a/src/display_buffer.hh +++ b/src/display_buffer.hh @@ -142,7 +142,7 @@ public: } iterator erase(iterator beg, iterator end); - void push_back(DisplayAtom atom); + DisplayAtom& push_back(DisplayAtom atom); // remove first_col from the begining of the line, and make sure // the line is less that col_count character diff --git a/src/highlighters.cc b/src/highlighters.cc index 3f60721e..6d370aae 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -647,8 +647,12 @@ std::unique_ptr create_column_highlighter(HighlighterParameters par auto remaining_col = column; bool found = false; auto first_buf = find_if(line, [](auto& atom) { return atom.has_buffer_range(); }); + BufferCoord last_pos{}; for (auto atom_it = first_buf; atom_it != line.end(); ++atom_it) { + if (atom_it->has_buffer_range()) + last_pos = atom_it->end(); + const auto atom_len = atom_it->length(); if (remaining_col < atom_len) { @@ -666,8 +670,8 @@ std::unique_ptr create_column_highlighter(HighlighterParameters par continue; if (remaining_col > 0) - line.push_back({buffer, buffer.end_coord(), buffer.end_coord(), String{' ', remaining_col}}); - line.push_back({" ", face}); + line.push_back({buffer, last_pos, last_pos, String{' ', remaining_col}}); + line.push_back({buffer, last_pos, last_pos, " "}).face = face; } };