1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 03:58:12 +00:00

LibGUI: Make text selection feel better in single-line editors

We should always stay on the only line when selecting in a single-line
editor, instead of requiring the user to keep the cursor inside the
text when selecting.

This broke with the variable-width font changes.
This commit is contained in:
Andreas Kling 2020-05-18 17:55:21 +02:00
parent 3d5233ae40
commit bdfd1f1545

View file

@ -164,7 +164,8 @@ TextPosition TextEditor::text_position_at(const Gfx::Point& a_position) const
switch (m_text_alignment) {
case Gfx::TextAlignment::CenterLeft:
for_each_visual_line(line_index, [&](const Gfx::Rect& rect, auto& view, size_t start_of_line) {
if (rect.contains_vertically(position.y())) {
if (is_multi_line() && !rect.contains_vertically(position.y()))
return IterationDecision::Continue;
column_index = start_of_line;
if (position.x() <= 0) {
// We're outside the text on the left side, put cursor at column 0 on this visual line.
@ -180,8 +181,6 @@ TextPosition TextEditor::text_position_at(const Gfx::Point& a_position) const
column_index += i;
}
return IterationDecision::Break;
}
return IterationDecision::Continue;
});
break;
case Gfx::TextAlignment::CenterRight: