summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
authorFalseHonesty <thefalsehonesty@gmail.com>2020-05-22 16:40:50 -0400
committerAndreas Kling <kling@serenityos.org>2020-05-23 01:30:20 +0200
commite0312ec2ced7dab0fa9fbe6315df96e50ffddf4e (patch)
tree4413a6265ccd96e9f0ee226b4431c7f92417767d /Libraries
parentd32889b19d982ac4b409aae9ed16c3ccbf86ac61 (diff)
downloadserenity-e0312ec2ced7dab0fa9fbe6315df96e50ffddf4e.zip
LibGUI: Improve double click selection on documents without spans
Previously, double clicking would select the range around your click up until it found a space, and in the browser's location bar this behavior didn't suffice. Now, it will select the range around your click until there is a "word break". A word break is considered to be when your selection changes from being alphanumeric to being non alphanumeric, or vice versa.
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibGUI/TextEditor.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/Libraries/LibGUI/TextEditor.cpp b/Libraries/LibGUI/TextEditor.cpp
index ab884c1c6f..884297e4f9 100644
--- a/Libraries/LibGUI/TextEditor.cpp
+++ b/Libraries/LibGUI/TextEditor.cpp
@@ -210,16 +210,19 @@ void TextEditor::doubleclick_event(MouseEvent& event)
auto start = text_position_at(event.position());
auto end = start;
auto& line = this->line(start.line());
+ auto clicked_on_alphanumeric = isalnum(line.codepoints()[start.column()]);
if (!document().has_spans()) {
while (start.column() > 0) {
- if (isspace(line.codepoints()[start.column() - 1]))
+ auto next_codepoint = line.codepoints()[start.column() - 1];
+ if ((clicked_on_alphanumeric && !isalnum(next_codepoint)) || (!clicked_on_alphanumeric && isalnum(next_codepoint)))
break;
start.set_column(start.column() - 1);
}
while (end.column() < line.length()) {
- if (isspace(line.codepoints()[end.column()]))
+ auto next_codepoint = line.codepoints()[end.column()];
+ if ((clicked_on_alphanumeric && !isalnum(next_codepoint)) || (!clicked_on_alphanumeric && isalnum(next_codepoint)))
break;
end.set_column(end.column() + 1);
}