merge contiguous DisplayAtoms after highlighting DisplayBuffer
This commit is contained in:
parent
6b2f8ed70c
commit
98b6618658
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -144,6 +144,7 @@ public:
|
|||
iterator insert(iterator it, DisplayAtom atom) { return m_atoms.insert(it, std::move(atom)); }
|
||||
void push_back(DisplayAtom atom) { m_atoms.push_back(std::move(atom)); }
|
||||
|
||||
void optimize();
|
||||
private:
|
||||
LineCount m_buffer_line;
|
||||
AtomList m_atoms;
|
||||
|
@ -162,11 +163,11 @@ public:
|
|||
|
||||
// returns the smallest BufferIterator range which contains every DisplayAtoms
|
||||
const BufferRange& range() const { return m_range; }
|
||||
void optimize();
|
||||
void compute_range();
|
||||
|
||||
private:
|
||||
LineList m_lines;
|
||||
|
||||
BufferRange m_range;
|
||||
};
|
||||
|
||||
|
|
|
@ -63,6 +63,7 @@ void Window::update_display_buffer()
|
|||
|
||||
m_display_buffer.compute_range();
|
||||
m_highlighters(m_display_buffer);
|
||||
m_display_buffer.optimize();
|
||||
}
|
||||
|
||||
void Window::set_dimensions(const DisplayCoord& dimensions)
|
||||
|
|
Loading…
Reference in New Issue
Block a user