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

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.
This commit is contained in:
AnotherTest 2021-02-21 04:03:43 +03:30 committed by Andreas Kling
parent 84b2d4c475
commit 6472e5239c
3 changed files with 17 additions and 1 deletions

View file

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

View file

@ -319,6 +319,9 @@ private:
m_refresh_needed = true; m_refresh_needed = true;
m_input_error.clear(); m_input_error.clear();
m_returned_line = String::empty(); 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(); void refresh_display();

View file

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