1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-19 16:35:06 +00:00

GTextEditor: Double-clicking on a word should select that word.

This commit is contained in:
Andreas Kling 2019-04-25 22:29:25 +02:00
parent 44673c4f3b
commit e2e2c78332
2 changed files with 30 additions and 0 deletions

View file

@ -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) {