From d2a1c5ce4697c25b7b7c8e99d7ca9bb39795e7f1 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 30 Jan 2014 11:30:51 +0000 Subject: [PATCH] Prompt handles scrolling in the line being edited --- src/input_handler.cc | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/src/input_handler.cc b/src/input_handler.cc index d2e3e7d3..904ce420 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -165,19 +165,25 @@ public: const String& line() const { return m_line; } CharCount cursor_pos() const { return m_cursor_pos; } - DisplayLine build_display_line() const + DisplayLine build_display_line(CharCount width) { kak_assert(m_cursor_pos <= m_line.char_length()); + if (m_cursor_pos < m_display_pos) + m_display_pos = m_cursor_pos; + if (m_cursor_pos >= m_display_pos + width) + m_display_pos = m_cursor_pos + 1 - width; + if (m_cursor_pos == m_line.char_length()) - return DisplayLine{{ {m_line, get_color("StatusLine")}, + return DisplayLine{{ {m_line.substr(m_display_pos, width-1), get_color("StatusLine")}, {" "_str, get_color("StatusCursor")} }}; else - return DisplayLine({ { m_line.substr(0, m_cursor_pos), get_color("StatusLine") }, - { m_line.substr(m_cursor_pos, 1), get_color("StatusCursor") }, - { m_line.substr(m_cursor_pos+1), get_color("StatusLine") } }); + return DisplayLine({ { m_line.substr(m_display_pos, m_cursor_pos - m_display_pos), get_color("StatusLine") }, + { m_line.substr(m_cursor_pos,1), get_color("StatusCursor") }, + { m_line.substr(m_cursor_pos+1, width - m_cursor_pos + m_display_pos - 1), get_color("StatusLine") } }); } private: CharCount m_cursor_pos = 0; + CharCount m_display_pos = 0; String m_line; }; @@ -265,10 +271,12 @@ public: select(it); } - if (m_edit_filter) + if (m_edit_filter and context().has_ui()) { - auto display_line = m_filter_editor.build_display_line(); - display_line.insert(display_line.begin(), { "filter:"_str, get_color("Prompt") }); + auto prompt = "filter:"_str; + auto width = context().ui().dimensions().column - prompt.char_length(); + auto display_line = m_filter_editor.build_display_line(width); + display_line.insert(display_line.begin(), { prompt, get_color("Prompt") }); context().print_status(display_line); } } @@ -535,9 +543,13 @@ private: context().ui().menu_hide(); } - void display() const + void display() { - auto display_line = m_line_editor.build_display_line(); + if (not context().has_ui()) + return; + + auto width = context().ui().dimensions().column - m_prompt.char_length(); + auto display_line = m_line_editor.build_display_line(width); display_line.insert(display_line.begin(), { m_prompt, m_prompt_colors }); context().print_status(display_line); }