summaryrefslogtreecommitdiff
path: root/Libraries/LibLine/Editor.cpp
diff options
context:
space:
mode:
authorAnotherTest <ali.mpfard@gmail.com>2020-05-21 05:14:34 +0430
committerAndreas Kling <kling@serenityos.org>2020-05-21 10:52:11 +0200
commit0751592a183394e333dd3e5bd60a461be00b07e0 (patch)
tree8ccd337726d58e9b6654bf3b94fb5da009371fad /Libraries/LibLine/Editor.cpp
parent5358608a947730b36bee5d4f39fb2127eb585824 (diff)
downloadserenity-0751592a183394e333dd3e5bd60a461be00b07e0.zip
LibLine: Correctly track the completion start and end
To achieve this, the API was tweaked a bit to allow for easier tracking of completions. This API change is non-disruptive to any application that does not use anchored styles.
Diffstat (limited to 'Libraries/LibLine/Editor.cpp')
-rw-r--r--Libraries/LibLine/Editor.cpp18
1 files changed, 14 insertions, 4 deletions
diff --git a/Libraries/LibLine/Editor.cpp b/Libraries/LibLine/Editor.cpp
index bd30a751d0..71eeb1efbc 100644
--- a/Libraries/LibLine/Editor.cpp
+++ b/Libraries/LibLine/Editor.cpp
@@ -445,7 +445,7 @@ String Editor::get_line(const String& prompt)
// reverse tab can count as regular tab here
m_times_tab_pressed++;
- int token_start = m_cursor - 1 - m_last_shown_suggestion_display_length;
+ int token_start = m_cursor;
// ask for completions only on the first tab
// and scan for the largest common prefix to display
@@ -523,7 +523,8 @@ String Editor::get_line(const String& prompt)
m_refresh_needed = true;
}
m_last_shown_suggestion = m_suggestions[m_next_suggestion_index];
- m_last_shown_suggestion.token_start_index = token_start - m_next_suggestion_invariant_offset - m_last_shown_suggestion.trailing_trivia.length();
+ m_last_shown_suggestion.token_start_index = token_start - m_next_suggestion_invariant_offset - m_next_suggestion_static_offset;
+ dbg() << "Last shown suggestion token start index: " << m_last_shown_suggestion.token_start_index << " Token Start " << token_start << " invariant offset " << m_next_suggestion_invariant_offset;
m_last_shown_suggestion_display_length = m_last_shown_suggestion.text.length();
m_last_shown_suggestion_was_complete = true;
if (m_times_tab_pressed == 1) {
@@ -537,7 +538,8 @@ String Editor::get_line(const String& prompt)
m_times_tab_pressed = 0;
// add in the trivia of the last selected suggestion
insert(m_last_shown_suggestion.trailing_trivia);
- m_last_shown_suggestion_display_length += m_last_shown_suggestion.trailing_trivia.length();
+ m_last_shown_suggestion_display_length = 0;
+ readjust_anchored_styles(m_last_shown_suggestion.token_start_index, ModificationKind::ForcedOverlapRemoval);
stylize({ m_last_shown_suggestion.token_start_index, m_cursor, Span::Mode::CodepointOriented }, m_last_shown_suggestion.style);
}
} else {
@@ -659,6 +661,8 @@ String Editor::get_line(const String& prompt)
if (m_times_tab_pressed) {
// Apply the style of the last suggestion
+ dbg() << "Last shown suggestion token start index: " << m_last_shown_suggestion.token_start_index << " invariant offset " << m_next_suggestion_invariant_offset << " static offset " << m_next_suggestion_static_offset;
+ readjust_anchored_styles(m_last_shown_suggestion.token_start_index, ModificationKind::ForcedOverlapRemoval);
stylize({ m_last_shown_suggestion.token_start_index, m_cursor, Span::Mode::CodepointOriented }, m_last_shown_suggestion.style);
// we probably have some suggestions drawn
// let's clean them up
@@ -1415,9 +1419,16 @@ void Editor::readjust_anchored_styles(size_t hint_index, ModificationKind modifi
};
Vector<Anchor> anchors_to_relocate;
auto index_shift = modification == ModificationKind::Insertion ? 1 : -1;
+ auto forced_removal = modification == ModificationKind::ForcedOverlapRemoval;
for (auto& start_entry : m_anchored_spans_starting) {
for (auto& end_entry : start_entry.value) {
+ if (forced_removal) {
+ if (start_entry.key <= hint_index && end_entry.key >= hint_index) {
+ // remove any overlapping regions
+ continue;
+ }
+ }
if (start_entry.key >= hint_index) {
if (start_entry.key == hint_index && end_entry.key == hint_index + 1 && modification == ModificationKind::Removal) {
// remove the anchor, as all its text was wiped
@@ -1443,5 +1454,4 @@ void Editor::readjust_anchored_styles(size_t hint_index, ModificationKind modifi
stylize(relocation.new_span, relocation.style);
}
}
-
}