DisplayBuffer: do not store content in atom, begin and end are sufficient
This commit is contained in:
parent
a19f4f059d
commit
10106e8c8e
|
@ -9,17 +9,15 @@ DisplayBuffer::DisplayBuffer()
|
|||
{
|
||||
}
|
||||
|
||||
DisplayBuffer::iterator DisplayBuffer::split(iterator atom, size_t pos_in_atom)
|
||||
DisplayBuffer::iterator DisplayBuffer::split(iterator atom, const BufferIterator& pos)
|
||||
{
|
||||
assert(atom < end());
|
||||
assert(pos_in_atom > 0);
|
||||
assert(pos_in_atom < atom->content.length());
|
||||
DisplayAtom new_atom(atom->begin, atom->begin + pos_in_atom,
|
||||
atom->content.substr(0, pos_in_atom),
|
||||
assert(pos > atom->begin);
|
||||
assert(pos < atom->end);
|
||||
DisplayAtom new_atom(atom->begin, pos,
|
||||
atom->fg_color, atom->bg_color, atom->attribute);
|
||||
|
||||
atom->begin = atom->begin + pos_in_atom;
|
||||
atom->content = atom->content.substr(pos_in_atom);
|
||||
atom->begin = pos;
|
||||
return insert(atom, std::move(new_atom));
|
||||
}
|
||||
|
||||
|
|
|
@ -35,7 +35,6 @@ enum class Color
|
|||
|
||||
struct DisplayAtom
|
||||
{
|
||||
std::string content;
|
||||
BufferIterator begin;
|
||||
BufferIterator end;
|
||||
Color fg_color;
|
||||
|
@ -43,12 +42,10 @@ struct DisplayAtom
|
|||
Attribute attribute;
|
||||
|
||||
DisplayAtom(BufferIterator begin, BufferIterator end,
|
||||
const std::string& content,
|
||||
Color fg_color = Color::Default,
|
||||
Color bg_color = Color::Default,
|
||||
Attribute attribute = Attributes::Normal)
|
||||
: content(content),
|
||||
begin(begin),
|
||||
: begin(begin),
|
||||
end(end),
|
||||
fg_color(fg_color),
|
||||
bg_color(bg_color),
|
||||
|
@ -68,7 +65,7 @@ public:
|
|||
void clear() { m_atoms.clear(); }
|
||||
void append(const DisplayAtom& atom) { m_atoms.push_back(atom); }
|
||||
iterator insert(iterator where, const DisplayAtom& atom) { return m_atoms.insert(where, atom); }
|
||||
iterator split(iterator atom, size_t pos_in_atom);
|
||||
iterator split(iterator atom, const BufferIterator& pos);
|
||||
|
||||
iterator begin() { return m_atoms.begin(); }
|
||||
iterator end() { return m_atoms.end(); }
|
||||
|
|
|
@ -9,16 +9,16 @@ void colorize_regex(DisplayBuffer& display_buffer,
|
|||
for (auto atom_it = display_buffer.begin();
|
||||
atom_it != display_buffer.end(); ++atom_it)
|
||||
{
|
||||
boost::smatch matches;
|
||||
if (boost::regex_search(atom_it->content, matches, ex, boost::match_nosubs))
|
||||
boost::match_results<BufferIterator> matches;
|
||||
if (boost::regex_search(atom_it->begin, atom_it->end, matches, ex, boost::match_nosubs))
|
||||
{
|
||||
size_t pos = matches.begin()->first - atom_it->content.begin();
|
||||
if (pos != 0)
|
||||
atom_it = display_buffer.split(atom_it, pos) + 1;
|
||||
const BufferIterator& begin = matches.begin()->first;
|
||||
if (begin != atom_it->begin)
|
||||
atom_it = display_buffer.split(atom_it, begin) + 1;
|
||||
|
||||
pos = matches.begin()->second - matches.begin()->first;
|
||||
if (pos != atom_it->content.length())
|
||||
atom_it = display_buffer.split(atom_it, pos);
|
||||
const BufferIterator& end = matches.begin()->second;
|
||||
if (end != atom_it->end)
|
||||
atom_it = display_buffer.split(atom_it, end);
|
||||
|
||||
atom_it->fg_color = color;
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ void draw_window(Window& window)
|
|||
WindowCoord position;
|
||||
for (const DisplayAtom& atom : window.display_buffer())
|
||||
{
|
||||
const std::string& content = atom.content;
|
||||
const std::string content = window.buffer().string(atom.begin, atom.end);
|
||||
|
||||
set_attribute(A_UNDERLINE, atom.attribute & Underline);
|
||||
set_attribute(A_REVERSE, atom.attribute & Reverse);
|
||||
|
|
|
@ -62,8 +62,7 @@ public:
|
|||
// [###------]
|
||||
if (atom.begin >= sel.begin() and atom.begin < sel.end() and atom.end > sel.end())
|
||||
{
|
||||
size_t length = sel.end() - atom.begin;
|
||||
atom_it = display_buffer.split(atom_it, length);
|
||||
atom_it = display_buffer.split(atom_it, sel.end());
|
||||
atom_it->attribute |= Attributes::Underline;
|
||||
++atom_it;
|
||||
++sel_it;
|
||||
|
@ -71,10 +70,8 @@ public:
|
|||
// [---###---]
|
||||
else if (atom.begin < sel.begin() and atom.end > sel.end())
|
||||
{
|
||||
size_t prefix_length = sel.begin() - atom.begin;
|
||||
atom_it = display_buffer.split(atom_it, prefix_length);
|
||||
size_t sel_length = sel.end() - sel.begin();
|
||||
atom_it = display_buffer.split(atom_it + 1, sel_length);
|
||||
atom_it = display_buffer.split(atom_it, sel.begin());
|
||||
atom_it = display_buffer.split(atom_it + 1, sel.end());
|
||||
atom_it->attribute |= Attributes::Underline;
|
||||
++atom_it;
|
||||
++sel_it;
|
||||
|
@ -82,8 +79,7 @@ public:
|
|||
// [------###]
|
||||
else if (atom.begin < sel.begin() and atom.end > sel.begin())
|
||||
{
|
||||
size_t length = sel.begin() - atom.begin;
|
||||
atom_it = display_buffer.split(atom_it, length) + 1;
|
||||
atom_it = display_buffer.split(atom_it, sel.begin()) + 1;
|
||||
atom_it->attribute |= Attributes::Underline;
|
||||
++atom_it;
|
||||
}
|
||||
|
@ -289,7 +285,10 @@ void Window::update_display_buffer()
|
|||
BufferIterator begin = m_buffer.iterator_at(m_position);
|
||||
BufferIterator end = m_buffer.iterator_at(m_position +
|
||||
BufferCoord(m_dimensions.line, m_dimensions.column+1));
|
||||
m_display_buffer.append(DisplayAtom(begin, end, m_buffer.string(begin, end)));
|
||||
if (begin == end)
|
||||
return;
|
||||
|
||||
m_display_buffer.append(DisplayAtom(begin, end));
|
||||
|
||||
for (auto& filter : m_filters)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user