DisplayAtom::content returns a StringView

This commit is contained in:
Maxime Coste 2014-05-16 19:29:39 +01:00
parent aa48179131
commit c21368cac5
2 changed files with 15 additions and 6 deletions

View File

@ -37,18 +37,25 @@ public:
: m_type(Text), m_text(std::move(str)), colors(colors), attribute(attribute)
{ check_invariant(); }
String content() const
StringView content() const
{
switch (m_type)
{
case BufferRange:
return m_buffer->string(m_begin, m_end);
{
auto& line = (*m_buffer)[m_begin.line];
if (m_begin.line == m_end.line)
return line.substr(m_begin.column, m_end.column - m_begin.column);
else if (m_begin.line+1 == m_end.line and m_end.column == 0)
return line.substr(m_begin.column);
break;
}
case Text:
case ReplacedBufferRange:
return m_text;
}
kak_assert(false);
return 0;
return {};
}
CharCount length() const

View File

@ -241,8 +241,10 @@ void NCursesUI::draw_line(const DisplayLine& line, CharCount col_index) const
set_color(stdscr, atom.colors);
String atom_content = atom.content();
StringView content = atom_content;
StringView content = atom.content();
if (content.empty())
continue;
if (content[content.length()-1] == '\n' and
content.char_length() - 1 < m_dimensions.column - col_index)
{