diff options
author | Max Wipfli <mail@maxwipfli.ch> | 2021-05-18 21:56:20 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-05-21 21:57:03 +0200 |
commit | 08d09c4afb341cea1d435e7acc226dbcfdec1a7e (patch) | |
tree | 928954418929c36ff8dbc4f236460d87ab42a1c2 /Userland/Libraries/LibWeb/Layout/TextNode.cpp | |
parent | d7df6de6a6e77769733e1e71a23dcdc343f08083 (diff) | |
download | serenity-08d09c4afb341cea1d435e7acc226dbcfdec1a7e.zip |
LibWeb: Improving cursor behavior in editable DOM nodes
This patch makes two modifications to improve the behavior of cursors in
editable DOM nodes, such as HTML tags with the contenteditable
attribute.
When the cursor blink cycle is reset in an editable DOM node, a repaint
should be initiated. For this, set_needs_display() needs to be called on
the layout node. Previously, the cursor blink cycle would not reset
properly and moving the cursor with the arrow keys did not feel
intuitive.
Furthermore, this modifies one of the conditions necessary to actually
paint the cursor, which previously prevented it from being painted when
at the end of a text node, after all the text present.
Diffstat (limited to 'Userland/Libraries/LibWeb/Layout/TextNode.cpp')
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/TextNode.cpp | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/TextNode.cpp b/Userland/Libraries/LibWeb/Layout/TextNode.cpp index 7cee023604..e2f6783e31 100644 --- a/Userland/Libraries/LibWeb/Layout/TextNode.cpp +++ b/Userland/Libraries/LibWeb/Layout/TextNode.cpp @@ -86,7 +86,8 @@ void TextNode::paint_cursor_if_needed(PaintContext& context, const LineBoxFragme if (frame().cursor_position().node() != &dom_node()) return; - if (!(frame().cursor_position().offset() >= (unsigned)fragment.start() && frame().cursor_position().offset() < (unsigned)(fragment.start() + fragment.length()))) + // NOTE: This checks if the cursor is before the start or after the end of the fragment. If it is at the end, after all text, it should still be painted. + if (frame().cursor_position().offset() < (unsigned)fragment.start() || frame().cursor_position().offset() > (unsigned)(fragment.start() + fragment.length())) return; if (!fragment.layout_node().dom_node() || !fragment.layout_node().dom_node()->is_editable()) |