mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:27:43 +00:00
LibGUI: Fall back to words when double-clicking TextEditor with spans
If we double-click on a TextEditor that has spans, but the click itself was not on a span, fall back to the without-spans behavior. Previously the cursor would instead jump to the end of the document.
This commit is contained in:
parent
631a988a57
commit
39cba61c2d
1 changed files with 5 additions and 1 deletions
|
@ -265,19 +265,23 @@ void TextEditor::doubleclick_event(MouseEvent& event)
|
||||||
m_in_drag_select = false;
|
m_in_drag_select = false;
|
||||||
|
|
||||||
auto position = text_position_at(event.position());
|
auto position = text_position_at(event.position());
|
||||||
|
bool got_selection = false;
|
||||||
|
|
||||||
if (m_substitution_code_point.has_value()) {
|
if (m_substitution_code_point.has_value()) {
|
||||||
// NOTE: If we substitute the code points, we don't want double clicking to only select a single word, since
|
// NOTE: If we substitute the code points, we don't want double clicking to only select a single word, since
|
||||||
// whitespace isn't visible anymore.
|
// whitespace isn't visible anymore.
|
||||||
m_selection = document().range_for_entire_line(position.line());
|
m_selection = document().range_for_entire_line(position.line());
|
||||||
|
got_selection = true;
|
||||||
} else if (document().has_spans()) {
|
} else if (document().has_spans()) {
|
||||||
for (auto& span : document().spans()) {
|
for (auto& span : document().spans()) {
|
||||||
if (span.range.contains(position)) {
|
if (span.range.contains(position)) {
|
||||||
m_selection = span.range;
|
m_selection = span.range;
|
||||||
|
got_selection = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
if (!got_selection) {
|
||||||
m_selection.set_start(document().first_word_break_before(position, false));
|
m_selection.set_start(document().first_word_break_before(position, false));
|
||||||
m_selection.set_end(document().first_word_break_after(position));
|
m_selection.set_end(document().first_word_break_after(position));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue