Browse Source

LibLine: Update the lazy refresh data and flags in some more places

These were forgotten in the last LibLine commit, any changes to m_buffer
not going through insert() and remove_at_index() should also be updating
these.

Fixes #5440.
AnotherTest 4 years ago
parent
commit
6472e5239c

+ 8 - 1
Userland/Libraries/LibLine/Editor.cpp

@@ -317,6 +317,7 @@ void Editor::clear_line()
     fputs("\033[K", stderr);
     fflush(stderr);
     m_buffer.clear();
+    m_chars_touched_in_the_middle = buffer().size();
     m_cursor = 0;
     m_inline_search_cursor = m_cursor;
 }
@@ -550,6 +551,7 @@ void Editor::interrupted()
     fprintf(stderr, "\n");
     fflush(stderr);
     m_buffer.clear();
+    m_chars_touched_in_the_middle = buffer().size();
     m_is_editing = false;
     restore();
     m_notifier->set_enabled(false);
@@ -568,6 +570,7 @@ void Editor::really_quit_event_loop()
     fflush(stderr);
     auto string = line();
     m_buffer.clear();
+    m_chars_touched_in_the_middle = buffer().size();
     m_is_editing = false;
     restore();
 
@@ -697,6 +700,7 @@ void Editor::handle_interrupt_event()
         on_interrupt_handled();
 
     m_buffer.clear();
+    m_chars_touched_in_the_middle = buffer().size();
     m_cursor = 0;
 
     finish();
@@ -973,10 +977,13 @@ void Editor::handle_read_event()
             m_cursor = new_cursor;
             m_inline_search_cursor = new_cursor;
             m_refresh_needed = true;
+            m_chars_touched_in_the_middle++;
 
             for (auto& view : completion_result.insert)
                 insert(view);
 
+            reposition_cursor();
+
             if (completion_result.style_to_apply.has_value()) {
                 // Apply the style of the last suggestion.
                 readjust_anchored_styles(m_suggestion_manager.current_suggestion().start_index, ModificationKind::ForcedOverlapRemoval);
@@ -1250,7 +1257,7 @@ void Editor::refresh_display()
 
     // If there have been no changes to previous sections of the line (style or text)
     // just append the new text with the appropriate styles.
-    if (m_cached_prompt_valid && m_chars_touched_in_the_middle == 0 && m_drawn_spans.contains_up_to_offset(m_current_spans, m_drawn_cursor)) {
+    if (!m_always_refresh && m_cached_prompt_valid && m_chars_touched_in_the_middle == 0 && m_drawn_spans.contains_up_to_offset(m_current_spans, m_drawn_cursor)) {
         auto initial_style = find_applicable_style(m_drawn_end_of_line_offset);
         VT::apply_style(initial_style);
 

+ 3 - 0
Userland/Libraries/LibLine/Editor.h

@@ -319,6 +319,9 @@ private:
         m_refresh_needed = true;
         m_input_error.clear();
         m_returned_line = String::empty();
+        m_chars_touched_in_the_middle = 0;
+        m_drawn_end_of_line_offset = 0;
+        m_drawn_spans = {};
     }
 
     void refresh_display();

+ 6 - 0
Userland/Libraries/LibLine/InternalFunctions.cpp

@@ -65,6 +65,7 @@ void Editor::search_forwards()
         }
     } else {
         m_search_offset_state = SearchOffsetState::Unbiased;
+        m_chars_touched_in_the_middle = buffer().size();
         m_cursor = 0;
         m_buffer.clear();
         insert(search_phrase);
@@ -218,6 +219,7 @@ void Editor::transpose_characters()
         swap(m_buffer[m_cursor - 1], m_buffer[m_cursor - 2]);
         // FIXME: Update anchored styles too.
         m_refresh_needed = true;
+        m_chars_touched_in_the_middle += 2;
     }
 }
 
@@ -245,6 +247,8 @@ void Editor::enter_search()
             StringBuilder builder;
             builder.append(Utf32View { search_editor.buffer().data(), search_editor.buffer().size() });
             if (!search(builder.build(), false, false)) {
+                m_chars_touched_in_the_middle = m_buffer.size();
+                m_refresh_needed = true;
                 m_buffer.clear();
                 m_cursor = 0;
             }
@@ -405,6 +409,7 @@ void Editor::transpose_words()
         m_cursor = cursor;
         // FIXME: Update anchored styles too.
         m_refresh_needed = true;
+        m_chars_touched_in_the_middle += end - start;
     }
 }
 
@@ -428,6 +433,7 @@ void Editor::clear_screen()
     VT::move_absolute(1, 1);
     set_origin(1, 1);
     m_refresh_needed = true;
+    m_cached_prompt_valid = false;
 }
 
 void Editor::insert_last_words()