1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 05:27:43 +00:00

GTextEditor: Double-clicking on a span should select the span

This makes double-clicking on a C++ token in HackStudio select the
whole token, which is pretty nice. It's not perfect in all cases,
but a lot nicer than just expanding until we hit whitespace. :^)
This commit is contained in:
Andreas Kling 2019-10-27 11:10:32 +01:00
parent 8fa466e496
commit db5178fb8f

View file

@ -164,6 +164,8 @@ void GTextEditor::doubleclick_event(GMouseEvent& event)
auto start = text_position_at(event.position());
auto end = start;
auto& line = m_lines[start.line()];
if (m_spans.is_empty()) {
while (start.column() > 0) {
if (isspace(line.characters()[start.column() - 1]))
break;
@ -175,6 +177,16 @@ void GTextEditor::doubleclick_event(GMouseEvent& event)
break;
end.set_column(end.column() + 1);
}
} else {
for (auto& span : m_spans) {
if (!span.range.contains(start))
continue;
start = span.range.start();
end = span.range.end();
end.set_column(end.column() + 1);
break;
}
}
m_selection.set(start, end);
set_cursor(end);