1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 05:08:13 +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()) {
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);
}