DisplayAtom::content returns a StringView
This commit is contained in:
parent
aa48179131
commit
c21368cac5
|
@ -37,18 +37,25 @@ public:
|
||||||
: m_type(Text), m_text(std::move(str)), colors(colors), attribute(attribute)
|
: m_type(Text), m_text(std::move(str)), colors(colors), attribute(attribute)
|
||||||
{ check_invariant(); }
|
{ check_invariant(); }
|
||||||
|
|
||||||
String content() const
|
StringView content() const
|
||||||
{
|
{
|
||||||
switch (m_type)
|
switch (m_type)
|
||||||
{
|
{
|
||||||
case BufferRange:
|
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 Text:
|
||||||
case ReplacedBufferRange:
|
case ReplacedBufferRange:
|
||||||
return m_text;
|
return m_text;
|
||||||
}
|
}
|
||||||
kak_assert(false);
|
kak_assert(false);
|
||||||
return 0;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
CharCount length() const
|
CharCount length() const
|
||||||
|
|
|
@ -241,8 +241,10 @@ void NCursesUI::draw_line(const DisplayLine& line, CharCount col_index) const
|
||||||
|
|
||||||
set_color(stdscr, atom.colors);
|
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
|
if (content[content.length()-1] == '\n' and
|
||||||
content.char_length() - 1 < m_dimensions.column - col_index)
|
content.char_length() - 1 < m_dimensions.column - col_index)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user