summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDexesTTP <dexes.ttp@gmail.com>2020-04-24 20:01:57 +0200
committerAndreas Kling <kling@serenityos.org>2020-04-24 20:29:47 +0200
commit424f47cbe581427fca397fac037b315578c939ee (patch)
tree029a76f4a128721139dbe9f11f68f9a7a63acac3
parenta832ab0f4e36fd4d12214736d318f3bc7550feb7 (diff)
downloadserenity-424f47cbe581427fca397fac037b315578c939ee.zip
LibGUI: Fix display issue when selecting multi-lines in TextEditor
When selecting the start of a multi-line line, a selection rect was displayed for the whole line but the text wasn't rendered properly. This change prevents the selection rect from being drawn in virtual lines with no selected characters.
-rw-r--r--Libraries/LibGUI/TextEditor.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/Libraries/LibGUI/TextEditor.cpp b/Libraries/LibGUI/TextEditor.cpp
index 0f6e0e005d..c38ea0ef8e 100644
--- a/Libraries/LibGUI/TextEditor.cpp
+++ b/Libraries/LibGUI/TextEditor.cpp
@@ -99,7 +99,7 @@ void TextEditor::create_actions()
this);
}
m_select_all_action = Action::create(
- "Select all", { Mod_Ctrl, Key_A },Gfx::Bitmap::load_from_file("/res/icons/16x16/select-all.png"), [this](auto&) { select_all(); }, this);
+ "Select all", { Mod_Ctrl, Key_A }, Gfx::Bitmap::load_from_file("/res/icons/16x16/select-all.png"), [this](auto&) { select_all(); }, this);
}
void TextEditor::set_text(const StringView& text)
@@ -473,9 +473,12 @@ void TextEditor::paint_event(PaintEvent& event)
}
bool physical_line_has_selection = has_selection && line_index >= selection.start().line() && line_index <= selection.end().line();
if (physical_line_has_selection) {
+ size_t start_of_selection_within_visual_line = (size_t)max(0, (int)selection_start_column_within_line - (int)start_of_visual_line);
+ size_t end_of_selection_within_visual_line = selection_end_column_within_line - start_of_visual_line;
- bool current_visual_line_has_selection = (line_index != selection.start().line() && line_index != selection.end().line())
- || (visual_line_index >= first_visual_line_with_selection && visual_line_index <= last_visual_line_with_selection);
+ bool current_visual_line_has_selection = start_of_selection_within_visual_line != end_of_selection_within_visual_line
+ && ((line_index != selection.start().line() && line_index != selection.end().line())
+ || (visual_line_index >= first_visual_line_with_selection && visual_line_index <= last_visual_line_with_selection));
if (current_visual_line_has_selection) {
bool selection_begins_on_current_visual_line = visual_line_index == first_visual_line_with_selection;
bool selection_ends_on_current_visual_line = visual_line_index == last_visual_line_with_selection;
@@ -500,9 +503,6 @@ void TextEditor::paint_event(PaintEvent& event)
painter.fill_rect(selection_rect, background_color);
- size_t start_of_selection_within_visual_line = (size_t)max(0, (int)selection_start_column_within_line - (int)start_of_visual_line);
- size_t end_of_selection_within_visual_line = selection_end_column_within_line - start_of_visual_line;
-
StringView visual_selected_text {
visual_line_text.characters_without_null_termination() + start_of_selection_within_visual_line,
end_of_selection_within_visual_line - start_of_selection_within_visual_line