mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-25 19:04:58 +00:00
GTextEditor: Double-clicking on a word should select that word.
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
|
||||
GTextEditor::GTextEditor(Type type, GWidget* parent)
|
||||
: GScrollableWidget(parent)
|
||||
@@ -129,6 +130,34 @@ GTextPosition GTextEditor::text_position_at(const Point& a_position) const
|
||||
return { line_index, column_index };
|
||||
}
|
||||
|
||||
void GTextEditor::doubleclick_event(GMouseEvent& event)
|
||||
{
|
||||
if (event.button() != GMouseButton::Left)
|
||||
return;
|
||||
|
||||
m_in_drag_select = false;
|
||||
|
||||
auto start = text_position_at(event.position());
|
||||
auto end = start;
|
||||
auto& line = *m_lines[start.line()];
|
||||
while (start.column() > 0) {
|
||||
if (isspace(line.characters()[start.column() - 1]))
|
||||
break;
|
||||
start.set_column(start.column() - 1);
|
||||
}
|
||||
|
||||
while (end.column() < line.length()) {
|
||||
if (isspace(line.characters()[end.column()]))
|
||||
break;
|
||||
end.set_column(end.column() + 1);
|
||||
}
|
||||
|
||||
m_selection.set(start, end);
|
||||
set_cursor(end);
|
||||
update();
|
||||
did_update_selection();
|
||||
}
|
||||
|
||||
void GTextEditor::mousedown_event(GMouseEvent& event)
|
||||
{
|
||||
if (event.button() == GMouseButton::Left) {
|
||||
|
||||
Reference in New Issue
Block a user