From c88c883f44e6a9bda0869e932f70313ace894b19 Mon Sep 17 00:00:00 2001 From: AnotherTest Date: Mon, 11 May 2020 11:55:42 +0430 Subject: LibLine: Show suggestions in pages if they don't fit on the screen We can now cycle pages of suggestions when there are more suggestions than we can fit on one screen. This does not inculude a visual indicator that more pages exist, however. --- Libraries/LibLine/Editor.cpp | 21 +++++++++++++++++++-- Libraries/LibLine/Editor.h | 11 ++++++++--- 2 files changed, 27 insertions(+), 5 deletions(-) (limited to 'Libraries/LibLine') diff --git a/Libraries/LibLine/Editor.cpp b/Libraries/LibLine/Editor.cpp index 1e101acc97..3542511996 100644 --- a/Libraries/LibLine/Editor.cpp +++ b/Libraries/LibLine/Editor.cpp @@ -503,8 +503,11 @@ String Editor::get_line(const String& prompt) if (m_times_tab_pressed > 1 && !m_suggestions.is_empty()) { size_t longest_suggestion_length = 0; + size_t start_index = 0; for (auto& suggestion : m_suggestions) { + if (start_index++ <= m_last_displayed_suggestion_index) + continue; longest_suggestion_length = max(longest_suggestion_length, suggestion.text.length()); } @@ -529,6 +532,10 @@ String Editor::get_line(const String& prompt) } vt_move_absolute(max_line_count + m_origin_x, 1); for (auto& suggestion : m_suggestions) { + if (index < m_last_displayed_suggestion_index) { + ++index; + continue; + } size_t next_column = num_printed + suggestion.text.length() + longest_suggestion_length + 2; if (next_column > m_num_columns) { @@ -560,15 +567,23 @@ String Editor::get_line(const String& prompt) vt_apply_style({}); fflush(stdout); } + ++index; } m_lines_used_for_last_suggestions = lines_used; - // adjust for the case that we scroll up after writing the suggestions + // if we filled the screen, move back the origin if (m_origin_x + lines_used >= m_num_lines) { m_origin_x = m_num_lines - lines_used; } - reposition_cursor(); + + --index; + // cycle pages of suggestions + if (index == current_suggestion_index) + m_last_displayed_suggestion_index = index; + + if (m_last_displayed_suggestion_index >= m_suggestions.size() - 1) + m_last_displayed_suggestion_index = 0; } if (m_suggestions.size() < 2) { // we have none, or just one suggestion @@ -579,6 +594,7 @@ String Editor::get_line(const String& prompt) m_last_shown_suggestion_display_length = 0; m_suggestions.clear(); m_times_tab_pressed = 0; + m_last_displayed_suggestion_index = 0; } continue; } @@ -594,6 +610,7 @@ String Editor::get_line(const String& prompt) } m_last_shown_suggestion_display_length = 0; m_last_shown_suggestion = String::empty(); + m_last_displayed_suggestion_index = 0; m_suggestions.clear(); suggest(0, 0); } diff --git a/Libraries/LibLine/Editor.h b/Libraries/LibLine/Editor.h index d911deb5dc..6ac01bb9e5 100644 --- a/Libraries/LibLine/Editor.h +++ b/Libraries/LibLine/Editor.h @@ -215,12 +215,16 @@ private: void reset() { + m_cached_buffer_size = 0; + m_cached_prompt_valid = false; + m_cursor = 0; + m_drawn_cursor = 0; + m_inline_search_cursor = 0; + m_old_prompt_length = m_cached_prompt_length; m_origin_x = 0; m_origin_y = 0; - m_old_prompt_length = m_cached_prompt_length; + m_prompt_lines_at_suggestion_initiation = 0; m_refresh_needed = true; - m_cursor = 0; - m_inline_search_cursor = 0; } void refresh_display(); @@ -300,6 +304,7 @@ private: size_t m_next_suggestion_index { 0 }; size_t m_next_suggestion_invariant_offset { 0 }; size_t m_largest_common_suggestion_prefix_length { 0 }; + size_t m_last_displayed_suggestion_index { 0 }; bool m_always_refresh { false }; -- cgit v1.2.3