1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 14:48:14 +00:00

GTextEditor: Always call did_change() before set_cursor().

This is not very obvious and I need to come up with a better design, but for
now just make sure to call did_change() before calling set_cursor().
This is needed because set_cursor() will try to scroll the cursor into view,
and for right-aligned text, did_change() may change the content rect which
needs to be reflected by the time we call scroll_cursor_into_view().
This commit is contained in:
Andreas Kling 2019-04-25 01:28:17 +02:00
parent 4e715dbc71
commit 2c51bc92af

View file

@ -496,8 +496,8 @@ void GTextEditor::do_delete()
if (m_cursor.column() < current_line().length()) { if (m_cursor.column() < current_line().length()) {
// Delete within line // Delete within line
current_line().remove(m_cursor.column()); current_line().remove(m_cursor.column());
update_cursor();
did_change(); did_change();
update_cursor();
return; return;
} }
if (m_cursor.column() == current_line().length() && m_cursor.line() != line_count() - 1) { if (m_cursor.column() == current_line().length() && m_cursor.line() != line_count() - 1) {
@ -507,8 +507,8 @@ void GTextEditor::do_delete()
current_line().append(next_line.characters(), next_line.length()); current_line().append(next_line.characters(), next_line.length());
m_lines.remove(m_cursor.line() + 1); m_lines.remove(m_cursor.line() + 1);
update(); update();
set_cursor(m_cursor.line(), previous_length);
did_change(); did_change();
set_cursor(m_cursor.line(), previous_length);
return; return;
} }
} }
@ -534,8 +534,8 @@ void GTextEditor::insert_at_cursor(char ch)
if (at_tail || at_head) { if (at_tail || at_head) {
m_lines.insert(m_cursor.line() + (at_tail ? 1 : 0), make<Line>()); m_lines.insert(m_cursor.line() + (at_tail ? 1 : 0), make<Line>());
update(); update();
set_cursor(m_cursor.line() + 1, 0);
did_change(); did_change();
set_cursor(m_cursor.line() + 1, 0);
return; return;
} }
auto new_line = make<Line>(); auto new_line = make<Line>();
@ -543,8 +543,8 @@ void GTextEditor::insert_at_cursor(char ch)
current_line().truncate(m_cursor.column()); current_line().truncate(m_cursor.column());
m_lines.insert(m_cursor.line() + 1, move(new_line)); m_lines.insert(m_cursor.line() + 1, move(new_line));
update(); update();
set_cursor(m_cursor.line() + 1, 0);
did_change(); did_change();
set_cursor(m_cursor.line() + 1, 0);
return; return;
} }
if (ch == '\t') { if (ch == '\t') {
@ -553,15 +553,13 @@ void GTextEditor::insert_at_cursor(char ch)
for (int i = 0; i < spaces_to_insert; ++i) { for (int i = 0; i < spaces_to_insert; ++i) {
current_line().insert(m_cursor.column(), ' '); current_line().insert(m_cursor.column(), ' ');
} }
set_cursor(m_cursor.line(), next_soft_tab_stop);
update_cursor();
did_change(); did_change();
set_cursor(m_cursor.line(), next_soft_tab_stop);
return; return;
} }
current_line().insert(m_cursor.column(), ch); current_line().insert(m_cursor.column(), ch);
set_cursor(m_cursor.line(), m_cursor.column() + 1);
update_cursor();
did_change(); did_change();
set_cursor(m_cursor.line(), m_cursor.column() + 1);
} }
int GTextEditor::content_x_for_position(const GTextPosition& position) const int GTextEditor::content_x_for_position(const GTextPosition& position) const
@ -862,9 +860,9 @@ void GTextEditor::delete_selection()
m_selection.clear(); m_selection.clear();
did_update_selection(); did_update_selection();
did_change();
set_cursor(selection.start()); set_cursor(selection.start());
update(); update();
did_change();
} }
void GTextEditor::insert_at_cursor_or_replace_selection(const String& text) void GTextEditor::insert_at_cursor_or_replace_selection(const String& text)