فهرست منبع

LibGUI+TextEditor: Allow cursor line highlighting to be toggled

thankyouverycool 3 سال پیش
والد
کامیت
9a5a9fbee0

+ 9 - 0
Userland/Applications/TextEditor/MainWidget.cpp

@@ -526,6 +526,15 @@ 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_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");
+
+    view_menu.add_action(*m_cursor_line_highlighting_action);
+
     view_menu.add_separator();
     view_menu.add_action(*m_no_preview_action);
     view_menu.add_action(*m_markdown_preview_action);

+ 1 - 0
Userland/Applications/TextEditor/MainWidget.h

@@ -104,6 +104,7 @@ private:
 
     RefPtr<GUI::Action> m_visualize_trailing_whitespace_action;
     RefPtr<GUI::Action> m_visualize_leading_whitespace_action;
+    RefPtr<GUI::Action> m_cursor_line_highlighting_action;
 
     GUI::ActionGroup m_soft_tab_width_actions;
     RefPtr<GUI::Action> m_soft_tab_1_width_action;

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

@@ -511,7 +511,7 @@ 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())
+            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 constexpr (TEXTEDITOR_DEBUG)
                 painter.draw_rect(visual_line_rect, Color::Cyan);
@@ -1973,6 +1973,14 @@ void TextEditor::set_gutter_visible(bool visible)
     update();
 }
 
+void TextEditor::set_cursor_line_highlighting(bool highlighted)
+{
+    if (m_cursor_line_highlighting == highlighted)
+        return;
+    m_cursor_line_highlighting = highlighted;
+    update();
+}
+
 void TextEditor::undo()
 {
     clear_selection();

+ 4 - 0
Userland/Libraries/LibGUI/TextEditor.h

@@ -68,6 +68,9 @@ public:
     void set_visualize_leading_whitespace(bool);
     bool visualize_leading_whitespace() const { return m_visualize_leading_whitespace; }
 
+    bool is_cursor_line_highlighted() const { return m_cursor_line_highlighting; }
+    void set_cursor_line_highlighting(bool);
+
     virtual bool is_automatic_indentation_enabled() const final { return m_automatic_indentation_enabled; }
     void set_automatic_indentation_enabled(bool enabled) { m_automatic_indentation_enabled = enabled; }
 
@@ -337,6 +340,7 @@ private:
     WrappingMode m_wrapping_mode { WrappingMode::NoWrap };
     bool m_visualize_trailing_whitespace { true };
     bool m_visualize_leading_whitespace { false };
+    bool m_cursor_line_highlighting { true };
     int m_line_spacing { 4 };
     size_t m_soft_tab_width { 4 };
     int m_horizontal_content_padding { 3 };