1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-12-19 17:31:44 +03:00

DisplayAtom: support empty replacement

This commit is contained in:
Maxime Coste 2012-07-03 19:13:16 +02:00
parent 603cfd3108
commit d7e1cab116
2 changed files with 27 additions and 7 deletions

View File

@ -8,10 +8,15 @@ namespace Kakoune
String DisplayAtom::content() const
{
if (m_replacement_text.empty())
switch (m_content_mode)
{
case BufferText:
return m_begin.buffer().string(m_begin, m_end);
else
case ReplacementText:
return m_replacement_text;
}
assert(false);
return "";
}
static DisplayCoord advance_coord(const DisplayCoord& pos,
@ -40,17 +45,23 @@ static DisplayCoord advance_coord(const DisplayCoord& pos,
}
return res;
}
DisplayCoord DisplayAtom::end_coord() const
{
if (m_replacement_text.empty())
switch (m_content_mode)
{
case BufferText:
return advance_coord(m_coord, m_begin, m_end);
else
case ReplacementText:
return advance_coord(m_coord, m_replacement_text);
}
assert(false);
return { 0, 0 };
}
BufferIterator DisplayAtom::iterator_at(const DisplayCoord& coord) const
{
if (not m_replacement_text.empty() or coord <= m_coord)
if (m_content_mode != BufferText or coord <= m_coord)
return m_begin;
DisplayCoord pos = m_coord;
@ -74,7 +85,7 @@ DisplayCoord DisplayAtom::line_and_column_at(const BufferIterator& iterator) con
{
assert(iterator >= m_begin and iterator < m_end);
if (not m_replacement_text.empty())
if (m_content_mode != BufferText)
return m_coord;
return advance_coord(m_coord, m_begin, iterator);
@ -140,6 +151,7 @@ void DisplayBuffer::check_invariant() const
void DisplayBuffer::replace_atom_content(iterator atom,
const String& replacement)
{
atom->m_content_mode = DisplayAtom::ReplacementText;
atom->m_replacement_text = replacement;
// update coordinates of subsequents atoms

View File

@ -57,7 +57,8 @@ struct DisplayAtom
Color fg_color = Color::Default,
Color bg_color = Color::Default,
Attribute attribute = Attributes::Normal)
: m_coord(coord),
: m_content_mode(BufferText),
m_coord(coord),
m_begin(begin), m_end(end),
m_fg_color(fg_color),
m_bg_color(bg_color),
@ -86,6 +87,13 @@ struct DisplayAtom
private:
friend class DisplayBuffer;
enum ContentMode
{
BufferText,
ReplacementText
};
ContentMode m_content_mode;
DisplayCoord m_coord;
BufferIterator m_begin;
BufferIterator m_end;