diff --git a/src/display_buffer.cc b/src/display_buffer.cc index 4a8233ba..fc5b7bb7 100644 --- a/src/display_buffer.cc +++ b/src/display_buffer.cc @@ -79,17 +79,36 @@ DisplayBuffer::DisplayBuffer() { } +DisplayBuffer::iterator DisplayBuffer::insert(iterator where, const DisplayAtom& atom) +{ + check_invariant(); + iterator res = m_atoms.insert(where, atom); + check_invariant(); + return res; +} + +DisplayBuffer::iterator DisplayBuffer::atom_containing(const BufferIterator& where) +{ + for (iterator it = m_atoms.begin(); it != m_atoms.end(); ++it) + { + if (it->end() > where) + return it; + } + return end(); +} + DisplayBuffer::iterator DisplayBuffer::split(iterator atom, const BufferIterator& pos) { assert(atom < end()); assert(pos > atom->begin()); assert(pos < atom->end()); + check_invariant(); DisplayAtom new_atom(atom->coord(), atom->begin(), pos, atom->fg_color(), atom->bg_color(), atom->attribute()); atom->m_begin = pos; atom->m_coord = new_atom.end_coord(); - iterator res = insert(atom, std::move(new_atom)); + iterator res = m_atoms.insert(atom, std::move(new_atom)); check_invariant(); return res; } diff --git a/src/display_buffer.hh b/src/display_buffer.hh index 874276a8..d4f69b23 100644 --- a/src/display_buffer.hh +++ b/src/display_buffer.hh @@ -99,7 +99,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 insert(iterator where, const DisplayAtom& atom); iterator split(iterator atom, const BufferIterator& pos); void replace_atom_content(iterator atom, const BufferString& replacement); @@ -110,6 +110,8 @@ public: const_iterator begin() const { return m_atoms.begin(); } const_iterator end() const { return m_atoms.end(); } + iterator atom_containing(const BufferIterator& where); + const DisplayAtom& front() const { return m_atoms.front(); } const DisplayAtom& back() const { return m_atoms.back(); }