From 954373d3cfa9d168f7949f12cb7b2e730d18de99 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 27 Apr 2020 13:36:12 +1000 Subject: Support multi-line replace-ranges This likely has lots of rough edges, but should be an initial proof of concept to support folding. --- src/display_buffer.cc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/display_buffer.cc') diff --git a/src/display_buffer.cc b/src/display_buffer.cc index 3d68356f..8ade4047 100644 --- a/src/display_buffer.cc +++ b/src/display_buffer.cc @@ -111,6 +111,14 @@ DisplayLine::iterator DisplayLine::split(iterator it, ColumnCount count) return split(it, pos); } +DisplayLine::iterator DisplayLine::split(BufferCoord pos) +{ + auto it = find_if(begin(), end(), [pos](const DisplayAtom& a) { return a.type() == DisplayAtom::Range and a.end() > pos; }); + if (it == end() or it->begin() >= pos) + return it; + return ++split(it, pos); +} + DisplayLine::iterator DisplayLine::insert(iterator it, DisplayAtom atom) { if (atom.has_buffer_range()) @@ -118,7 +126,9 @@ DisplayLine::iterator DisplayLine::insert(iterator it, DisplayAtom atom) m_range.begin = std::min(m_range.begin, atom.begin()); m_range.end = std::max(m_range.end, atom.end()); } - return m_atoms.insert(it, std::move(atom)); + auto res = m_atoms.insert(it, std::move(atom)); + compute_range(); + return res; } void DisplayLine::push_back(DisplayAtom atom) -- cgit v1.2.3