mirror of
https://github.com/RGBCube/serenity
synced 2025-07-08 19:47:34 +00:00
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.
This commit is contained in:
parent
d32889b19d
commit
e0312ec2ce
1 changed files with 5 additions and 2 deletions
|
@ -210,16 +210,19 @@ void TextEditor::doubleclick_event(MouseEvent& event)
|
||||||
auto start = text_position_at(event.position());
|
auto start = text_position_at(event.position());
|
||||||
auto end = start;
|
auto end = start;
|
||||||
auto& line = this->line(start.line());
|
auto& line = this->line(start.line());
|
||||||
|
auto clicked_on_alphanumeric = isalnum(line.codepoints()[start.column()]);
|
||||||
|
|
||||||
if (!document().has_spans()) {
|
if (!document().has_spans()) {
|
||||||
while (start.column() > 0) {
|
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;
|
break;
|
||||||
start.set_column(start.column() - 1);
|
start.set_column(start.column() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (end.column() < line.length()) {
|
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;
|
break;
|
||||||
end.set_column(end.column() + 1);
|
end.set_column(end.column() + 1);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue