LibGUI: Don't paint TextEditor selection in non-focused widgets

Showing the selection in non-focused text editors was not really useful,
since refocusing the widget would clear or change the selection
immediately anyway.

Note that TextEditors in inactive windows can still be the focused
widget within that window, and will still be painted with an "inactive"
looking selection.
This commit is contained in:
Andreas Kling 2021-10-21 19:38:59 +02:00
parent c1576aca11
commit 649cb67f28
Notes: sideshowbarker 2024-07-18 02:04:50 +09:00

View file

@ -670,7 +670,7 @@ void TextEditor::paint_event(PaintEvent& event)
}
}
if (physical_line_has_selection) {
if (physical_line_has_selection && window()->focused_widget() == this) {
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;
@ -696,8 +696,8 @@ void TextEditor::paint_event(PaintEvent& event)
visual_line_rect.height()
};
Color background_color = is_focused() ? palette().selection() : palette().inactive_selection();
Color text_color = is_focused() ? palette().selection_text() : palette().inactive_selection_text();
Color background_color = window()->is_active() ? palette().selection() : palette().inactive_selection();
Color text_color = window()->is_active() ? palette().selection_text() : palette().inactive_selection_text();
painter.fill_rect(selection_rect, background_color);