GTextEditor: Introduce triple click to select all

This commit is contained in:
Robin Burchell 2019-05-16 00:40:55 +02:00 committed by Andreas Kling
parent c4610b825d
commit 8aecebe8f3
Notes: sideshowbarker 2024-07-19 14:07:26 +09:00
2 changed files with 23 additions and 0 deletions

View file

@ -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, { });

View file

@ -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;
};