1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 04:07:44 +00:00

LibGUI: Fix double-clicking words in syntax-highlighted text

This patch fixes a bug where double-clicking on a word in a TextEditor
with syntax highlighting would also select an additional character after
the word. This also simplifies the logic for double- and
triple-clicking.
This commit is contained in:
Max Wipfli 2021-06-25 11:57:34 +02:00 committed by Andreas Kling
parent 988e17ed05
commit 37961bf7cb

View file

@ -216,25 +216,21 @@ void TextEditor::doubleclick_event(MouseEvent& event)
m_triple_click_timer.start();
m_in_drag_select = false;
auto start = text_position_at(event.position());
auto end = start;
auto position = text_position_at(event.position());
if (!document().has_spans()) {
start = document().first_word_break_before(start, false);
end = document().first_word_break_after(end);
} else {
if (document().has_spans()) {
for (auto& span : document().spans()) {
if (!span.range.contains(start))
continue;
start = span.range.start();
end = span.range.end();
end.set_column(end.column() + 1);
break;
if (span.range.contains(position)) {
m_selection = span.range;
break;
}
}
} else {
m_selection.set_start(document().first_word_break_before(position, false));
m_selection.set_end(document().first_word_break_after(position));
}
m_selection.set(start, end);
set_cursor(end);
set_cursor(m_selection.end());
update();
did_update_selection();
}
@ -253,22 +249,8 @@ void TextEditor::mousedown_event(MouseEvent& event)
if (m_triple_click_timer.is_valid() && m_triple_click_timer.elapsed() < 250) {
m_triple_click_timer = Core::ElapsedTimer();
TextPosition start;
TextPosition end;
if (is_multi_line()) {
// select *current* line
start = TextPosition(m_cursor.line(), 0);
end = TextPosition(m_cursor.line(), line(m_cursor.line()).length());
} else {
// select *whole* line
start = TextPosition(0, 0);
end = TextPosition(line_count() - 1, line(line_count() - 1).length());
}
m_selection.set(start, end);
set_cursor(end);
m_selection = document().range_for_entire_line(m_cursor.line());
set_cursor(m_selection.end());
update();
did_update_selection();
return;