mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:27:43 +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:
parent
988e17ed05
commit
37961bf7cb
1 changed files with 12 additions and 30 deletions
|
@ -216,25 +216,21 @@ void TextEditor::doubleclick_event(MouseEvent& event)
|
||||||
m_triple_click_timer.start();
|
m_triple_click_timer.start();
|
||||||
m_in_drag_select = false;
|
m_in_drag_select = false;
|
||||||
|
|
||||||
auto start = text_position_at(event.position());
|
auto position = text_position_at(event.position());
|
||||||
auto end = start;
|
|
||||||
|
|
||||||
if (!document().has_spans()) {
|
if (document().has_spans()) {
|
||||||
start = document().first_word_break_before(start, false);
|
|
||||||
end = document().first_word_break_after(end);
|
|
||||||
} else {
|
|
||||||
for (auto& span : document().spans()) {
|
for (auto& span : document().spans()) {
|
||||||
if (!span.range.contains(start))
|
if (span.range.contains(position)) {
|
||||||
continue;
|
m_selection = span.range;
|
||||||
start = span.range.start();
|
break;
|
||||||
end = span.range.end();
|
}
|
||||||
end.set_column(end.column() + 1);
|
|
||||||
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(m_selection.end());
|
||||||
set_cursor(end);
|
|
||||||
update();
|
update();
|
||||||
did_update_selection();
|
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) {
|
if (m_triple_click_timer.is_valid() && m_triple_click_timer.elapsed() < 250) {
|
||||||
m_triple_click_timer = Core::ElapsedTimer();
|
m_triple_click_timer = Core::ElapsedTimer();
|
||||||
|
m_selection = document().range_for_entire_line(m_cursor.line());
|
||||||
TextPosition start;
|
set_cursor(m_selection.end());
|
||||||
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);
|
|
||||||
update();
|
update();
|
||||||
did_update_selection();
|
did_update_selection();
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue