Просмотр исходного кода

LibWeb: Restart the cursor blink cycle whenever the user edits content

Having the text cursor disappear during rapid continuous editing is
quite jarring, so let's make sure we always restart the blink cycle
whenever the user performs some kind of editing action in a frame.
Andreas Kling 4 лет назад
Родитель
Сommit
ce2894c95b

+ 4 - 0
Libraries/LibWeb/Page/EditEventHandler.cpp

@@ -96,6 +96,8 @@ void EditEventHandler::handle_delete(DOM::Range& range)
     //        remain in the layout tree. This has to be fixed, this just causes everything to be recomputed
     //        remain in the layout tree. This has to be fixed, this just causes everything to be recomputed
     //        which really hurts performance.
     //        which really hurts performance.
     m_frame.document()->force_layout();
     m_frame.document()->force_layout();
+
+    m_frame.did_edit({});
 }
 }
 
 
 void EditEventHandler::handle_insert(DOM::Position position, u32 code_point)
 void EditEventHandler::handle_insert(DOM::Position position, u32 code_point)
@@ -116,5 +118,7 @@ void EditEventHandler::handle_insert(DOM::Position position, u32 code_point)
     //        remain in the layout tree. This has to be fixed, this just causes everything to be recomputed
     //        remain in the layout tree. This has to be fixed, this just causes everything to be recomputed
     //        which really hurts performance.
     //        which really hurts performance.
     m_frame.document()->force_layout();
     m_frame.document()->force_layout();
+
+    m_frame.did_edit({});
 }
 }
 }
 }

+ 8 - 0
Libraries/LibWeb/Page/Frame.cpp

@@ -70,6 +70,14 @@ void Frame::setup()
     });
     });
 }
 }
 
 
+void Frame::did_edit(Badge<EditEventHandler>)
+{
+    // The user has edited the content, restart the cursor blink cycle so that
+    // the cursor doesn't disappear during rapid continuous editing.
+    m_cursor_blink_state = true;
+    m_cursor_blink_timer->restart();
+}
+
 bool Frame::is_focused_frame() const
 bool Frame::is_focused_frame() const
 {
 {
     return m_page && &m_page->focused_frame() == this;
     return m_page && &m_page->focused_frame() == this;

+ 2 - 0
Libraries/LibWeb/Page/Frame.h

@@ -94,6 +94,8 @@ public:
 
 
     String selected_text() const;
     String selected_text() const;
 
 
+    void did_edit(Badge<EditEventHandler>);
+
 private:
 private:
     explicit Frame(DOM::Element& host_element, Frame& main_frame);
     explicit Frame(DOM::Element& host_element, Frame& main_frame);
     explicit Frame(Page&);
     explicit Frame(Page&);