DisplayBuffer: add range and compute_range methods
This commit is contained in:
parent
b1a087485c
commit
03d8efc249
|
@ -17,4 +17,26 @@ DisplayLine::iterator DisplayLine::split(iterator it, BufferIterator pos)
|
|||
return m_atoms.insert(it, std::move(atom));
|
||||
}
|
||||
|
||||
void DisplayBuffer::compute_range()
|
||||
{
|
||||
m_range.first = BufferIterator();
|
||||
m_range.second = BufferIterator();
|
||||
for (auto& line : m_lines)
|
||||
{
|
||||
for (auto& atom : line)
|
||||
{
|
||||
if (not atom.content.has_buffer_range())
|
||||
continue;
|
||||
|
||||
if (not m_range.first.is_valid() or m_range.first > atom.content.begin())
|
||||
m_range.first = atom.content.begin();
|
||||
|
||||
if (not m_range.second.is_valid() or m_range.second < atom.content.end())
|
||||
m_range.second = atom.content.end();
|
||||
}
|
||||
}
|
||||
assert(m_range.first.is_valid() and m_range.second.is_valid());
|
||||
assert(m_range.first <= m_range.second);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -144,6 +144,8 @@ private:
|
|||
AtomList m_atoms;
|
||||
};
|
||||
|
||||
using BufferRange = std::pair<BufferIterator, BufferIterator>;
|
||||
|
||||
class DisplayBuffer
|
||||
{
|
||||
public:
|
||||
|
@ -152,8 +154,15 @@ public:
|
|||
|
||||
LineList& lines() { return m_lines; }
|
||||
const LineList& lines() const { return m_lines; }
|
||||
|
||||
// returns the smallest BufferIterator range which contains every DisplayAtoms
|
||||
const BufferRange& range() const { return m_range; }
|
||||
void compute_range();
|
||||
|
||||
private:
|
||||
LineList m_lines;
|
||||
|
||||
BufferRange m_range;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -18,6 +18,9 @@ void highlight_range(DisplayBuffer& display_buffer,
|
|||
BufferIterator begin, BufferIterator end,
|
||||
bool skip_replaced, T func)
|
||||
{
|
||||
if (end <= display_buffer.range().first or begin >= display_buffer.range().second)
|
||||
return;
|
||||
|
||||
for (auto& line : display_buffer.lines())
|
||||
{
|
||||
if (line.buffer_line() >= begin.line() and line.buffer_line() <= end.line())
|
||||
|
@ -50,11 +53,11 @@ void highlight_range(DisplayBuffer& display_buffer,
|
|||
}
|
||||
|
||||
void colorize_regex(DisplayBuffer& display_buffer,
|
||||
const Buffer& buffer,
|
||||
const Regex& ex,
|
||||
Color fg_color, Color bg_color = Color::Default)
|
||||
{
|
||||
RegexIterator re_it(buffer.begin(), buffer.end(), ex, boost::match_nosubs);
|
||||
const BufferRange& range = display_buffer.range();
|
||||
RegexIterator re_it(range.first, range.second, ex, boost::match_nosubs);
|
||||
RegexIterator re_end;
|
||||
for (; re_it != re_end; ++re_it)
|
||||
{
|
||||
|
@ -94,8 +97,7 @@ HighlighterAndId colorize_regex_factory(Window& window,
|
|||
String id = "colre'" + params[0] + "'";
|
||||
|
||||
return HighlighterAndId(id, std::bind(colorize_regex,
|
||||
_1, std::ref(window.buffer()),
|
||||
ex, fg_color, bg_color));
|
||||
_1, ex, fg_color, bg_color));
|
||||
}
|
||||
|
||||
void expand_tabulations(Window& window, DisplayBuffer& display_buffer)
|
||||
|
|
|
@ -61,6 +61,7 @@ void Window::update_display_buffer()
|
|||
lines.back().push_back(DisplayAtom(AtomContent(pos,end)));
|
||||
}
|
||||
|
||||
m_display_buffer.compute_range();
|
||||
m_highlighters(m_display_buffer);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user