diff options
author | Andreas Kling <kling@serenityos.org> | 2020-05-18 17:55:21 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-05-18 17:55:21 +0200 |
commit | bdfd1f1545fae1b6f6b8b97d30a4708e8250f213 (patch) | |
tree | 3061ee01194bc0cc7564d32f5283aec5c6b732b6 /Libraries/LibGUI | |
parent | 3d5233ae40b2a018a8c9b5cd2753a938b2adba25 (diff) | |
download | serenity-bdfd1f1545fae1b6f6b8b97d30a4708e8250f213.zip |
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.
Diffstat (limited to 'Libraries/LibGUI')
-rw-r--r-- | Libraries/LibGUI/TextEditor.cpp | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/Libraries/LibGUI/TextEditor.cpp b/Libraries/LibGUI/TextEditor.cpp index bcd45043a2..15f38e106a 100644 --- a/Libraries/LibGUI/TextEditor.cpp +++ b/Libraries/LibGUI/TextEditor.cpp @@ -164,24 +164,23 @@ 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())) { - 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. - } else { - int glyph_x = 0; - size_t i = 0; - for (; i < view.length(); ++i) { - int advance = font().glyph_width(view.codepoints()[i]) + font().glyph_spacing(); - if ((glyph_x + (advance / 2)) >= position.x()) - break; - glyph_x += advance; - } - column_index += i; + 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. + } else { + int glyph_x = 0; + size_t i = 0; + for (; i < view.length(); ++i) { + int advance = font().glyph_width(view.codepoints()[i]) + font().glyph_spacing(); + if ((glyph_x + (advance / 2)) >= position.x()) + break; + glyph_x += advance; } - return IterationDecision::Break; + column_index += i; } - return IterationDecision::Continue; + return IterationDecision::Break; }); break; case Gfx::TextAlignment::CenterRight: |