Browse Source

LibGUI+TextEditor: Highlight the entire current line

And fix Line Highlighting's duplicate alt-menu shortcut.

Previously only text on the cursor's line was highlighted. This makes
discerning cursor focus on empty lines easier.
thankyouverycool 3 years ago
parent
commit
f35a6c13ab

+ 2 - 2
Userland/Applications/TextEditor/MainWidget.cpp

@@ -519,12 +519,12 @@ void MainWidget::initialize_menubar(GUI::Window& window)
     view_menu.add_action(*m_visualize_trailing_whitespace_action);
     view_menu.add_action(*m_visualize_leading_whitespace_action);
 
-    m_cursor_line_highlighting_action = GUI::Action::create_checkable("Line High&lighting", [&](auto&) {
+    m_cursor_line_highlighting_action = GUI::Action::create_checkable("L&ine Highlighting", [&](auto&) {
         m_editor->set_cursor_line_highlighting(m_cursor_line_highlighting_action->is_checked());
     });
 
     m_cursor_line_highlighting_action->set_checked(true);
-    m_cursor_line_highlighting_action->set_status_tip("Highlight text on the cursor's line");
+    m_cursor_line_highlighting_action->set_status_tip("Highlight the current line");
 
     view_menu.add_action(*m_cursor_line_highlighting_action);
 

+ 9 - 2
Userland/Libraries/LibGUI/TextEditor.cpp

@@ -512,8 +512,15 @@ void TextEditor::paint_event(PaintEvent& event)
 
         size_t visual_line_index = 0;
         for_each_visual_line(line_index, [&](Gfx::IntRect const& visual_line_rect, auto& visual_line_text, size_t start_of_visual_line, [[maybe_unused]] bool is_last_visual_line) {
-            if (is_multi_line() && line_index == m_cursor.line() && is_cursor_line_highlighted())
-                painter.fill_rect(visual_line_rect, widget_background_color.darkened(0.9f));
+            if (is_focused() && is_multi_line() && line_index == m_cursor.line() && is_cursor_line_highlighted()) {
+                Gfx::IntRect visible_content_line_rect {
+                    visible_content_rect().x(),
+                    visual_line_rect.y(),
+                    widget_inner_rect().width() - gutter_ruler_width,
+                    line_height()
+                };
+                painter.fill_rect(visible_content_line_rect, widget_background_color.darkened(0.9f));
+            }
             if constexpr (TEXTEDITOR_DEBUG)
                 painter.draw_rect(visual_line_rect, Color::Cyan);