mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-24 02:03:06 -05:00
GTextEditor: Introduce triple click to select all
This commit is contained in:
parent
c4610b825d
commit
8aecebe8f3
Notes:
sideshowbarker
2024-07-19 14:07:26 +09:00
Author: https://github.com/rburchell Commit: https://github.com/SerenityOS/serenity/commit/8aecebe8f3c Pull-request: https://github.com/SerenityOS/serenity/pull/40 Reviewed-by: https://github.com/awesomekling
2 changed files with 23 additions and 0 deletions
|
@ -134,6 +134,7 @@ void GTextEditor::doubleclick_event(GMouseEvent& event)
|
|||
if (event.button() != GMouseButton::Left)
|
||||
return;
|
||||
|
||||
m_triple_click_timer.start();
|
||||
m_in_drag_select = false;
|
||||
|
||||
auto start = text_position_at(event.position());
|
||||
|
@ -163,6 +164,27 @@ void GTextEditor::mousedown_event(GMouseEvent& event)
|
|||
return;
|
||||
}
|
||||
|
||||
if (m_triple_click_timer.is_valid() && m_triple_click_timer.elapsed() < 250) {
|
||||
m_triple_click_timer = CElapsedTimer();
|
||||
|
||||
GTextPosition start;
|
||||
GTextPosition end;
|
||||
|
||||
if (is_multi_line()) {
|
||||
// select *current* line
|
||||
start = GTextPosition(m_cursor.line(), 0);
|
||||
end = GTextPosition(m_cursor.line(), m_lines[m_cursor.line()]->length());
|
||||
} else {
|
||||
// select *whole* line
|
||||
start = GTextPosition(0, 0);
|
||||
end = GTextPosition(line_count() - 1, m_lines[line_count() - 1]->length());
|
||||
}
|
||||
|
||||
m_selection.set(start, end);
|
||||
set_cursor(end);
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.modifiers() & Mod_Shift) {
|
||||
if (!has_selection())
|
||||
m_selection.set(m_cursor, { });
|
||||
|
|
|
@ -211,4 +211,5 @@ private:
|
|||
RetainPtr<GAction> m_copy_action;
|
||||
RetainPtr<GAction> m_paste_action;
|
||||
RetainPtr<GAction> m_delete_action;
|
||||
CElapsedTimer m_triple_click_timer;
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue