From c21368cac52526afe1805b2e5a8bad32ba283e53 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 16 May 2014 19:29:39 +0100 Subject: [PATCH] DisplayAtom::content returns a StringView --- src/display_buffer.hh | 15 +++++++++++---- src/ncurses.cc | 6 ++++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/display_buffer.hh b/src/display_buffer.hh index 50b1c92a..db70d840 100644 --- a/src/display_buffer.hh +++ b/src/display_buffer.hh @@ -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; + return m_text; } kak_assert(false); - return 0; + return {}; } CharCount length() const diff --git a/src/ncurses.cc b/src/ncurses.cc index a4a84fb5..f48ef7ee 100644 --- a/src/ncurses.cc +++ b/src/ncurses.cc @@ -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) {