summaryrefslogtreecommitdiff
path: root/src/display_buffer.cc
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2012-10-22 13:20:02 +0200
committerMaxime Coste <frrrwww@gmail.com>2012-10-22 13:20:02 +0200
commit98b661865856ea7a6ed74a922197b506b1eae8da (patch)
tree4a3e80f0ec35bed8ef05a605edbc8da4328f5759 /src/display_buffer.cc
parent6b2f8ed70c5514d7580d5f6a772c097f041b0d97 (diff)
merge contiguous DisplayAtoms after highlighting DisplayBuffer
Diffstat (limited to 'src/display_buffer.cc')
-rw-r--r--src/display_buffer.cc31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/display_buffer.cc b/src/display_buffer.cc
index 576e5a14..bdd7d68a 100644
--- a/src/display_buffer.cc
+++ b/src/display_buffer.cc
@@ -20,6 +20,32 @@ DisplayLine::iterator DisplayLine::split(iterator it, BufferIterator pos)
return m_atoms.insert(it, std::move(atom));
}
+void DisplayLine::optimize()
+{
+ for (auto atom_it = m_atoms.begin(); atom_it != m_atoms.end(); ++atom_it)
+ {
+ decltype(atom_it) next_atom_it;
+ while ((next_atom_it = atom_it + 1) != m_atoms.end())
+ {
+ auto& atom = *atom_it;
+ auto& next_atom = *next_atom_it;
+
+ if (atom.fg_color == next_atom.fg_color and
+ atom.bg_color == next_atom.bg_color and
+ atom.attribute == next_atom.attribute and
+ atom.content.type() == AtomContent::BufferRange and
+ next_atom.content.type() == AtomContent::BufferRange and
+ next_atom.content.begin() == atom.content.end())
+ {
+ atom.content.m_end = next_atom.content.end();
+ atom_it = m_atoms.erase(next_atom_it) - 1;
+ }
+ else
+ break;
+ }
+ }
+}
+
void DisplayBuffer::compute_range()
{
m_range.first = BufferIterator();
@@ -42,4 +68,9 @@ void DisplayBuffer::compute_range()
assert(m_range.first <= m_range.second);
}
+void DisplayBuffer::optimize()
+{
+ for (auto& line : m_lines)
+ line.optimize();
+}
}