1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-23 20:17:42 +00:00

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.
This commit is contained in:
AnotherTest 2020-05-11 11:55:42 +04:30 committed by Andreas Kling
parent 5b9fe0cf46
commit c88c883f44
2 changed files with 27 additions and 5 deletions

View file

@ -503,8 +503,11 @@ String Editor::get_line(const String& prompt)
if (m_times_tab_pressed > 1 && !m_suggestions.is_empty()) { if (m_times_tab_pressed > 1 && !m_suggestions.is_empty()) {
size_t longest_suggestion_length = 0; size_t longest_suggestion_length = 0;
size_t start_index = 0;
for (auto& suggestion : m_suggestions) { for (auto& suggestion : m_suggestions) {
if (start_index++ <= m_last_displayed_suggestion_index)
continue;
longest_suggestion_length = max(longest_suggestion_length, suggestion.text.length()); 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); vt_move_absolute(max_line_count + m_origin_x, 1);
for (auto& suggestion : m_suggestions) { 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; size_t next_column = num_printed + suggestion.text.length() + longest_suggestion_length + 2;
if (next_column > m_num_columns) { if (next_column > m_num_columns) {
@ -560,15 +567,23 @@ String Editor::get_line(const String& prompt)
vt_apply_style({}); vt_apply_style({});
fflush(stdout); fflush(stdout);
} }
++index; ++index;
} }
m_lines_used_for_last_suggestions = lines_used; 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) { if (m_origin_x + lines_used >= m_num_lines) {
m_origin_x = m_num_lines - lines_used; 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) { if (m_suggestions.size() < 2) {
// we have none, or just one suggestion // 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_last_shown_suggestion_display_length = 0;
m_suggestions.clear(); m_suggestions.clear();
m_times_tab_pressed = 0; m_times_tab_pressed = 0;
m_last_displayed_suggestion_index = 0;
} }
continue; continue;
} }
@ -594,6 +610,7 @@ String Editor::get_line(const String& prompt)
} }
m_last_shown_suggestion_display_length = 0; m_last_shown_suggestion_display_length = 0;
m_last_shown_suggestion = String::empty(); m_last_shown_suggestion = String::empty();
m_last_displayed_suggestion_index = 0;
m_suggestions.clear(); m_suggestions.clear();
suggest(0, 0); suggest(0, 0);
} }

View file

@ -215,12 +215,16 @@ private:
void reset() 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_x = 0;
m_origin_y = 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_refresh_needed = true;
m_cursor = 0;
m_inline_search_cursor = 0;
} }
void refresh_display(); void refresh_display();
@ -300,6 +304,7 @@ private:
size_t m_next_suggestion_index { 0 }; size_t m_next_suggestion_index { 0 };
size_t m_next_suggestion_invariant_offset { 0 }; size_t m_next_suggestion_invariant_offset { 0 };
size_t m_largest_common_suggestion_prefix_length { 0 }; size_t m_largest_common_suggestion_prefix_length { 0 };
size_t m_last_displayed_suggestion_index { 0 };
bool m_always_refresh { false }; bool m_always_refresh { false };