Skip to content

Commit

Permalink
Fix #5738 wrong selection on mouse click (#5969)
Browse files Browse the repository at this point in the history
Co-authored-by: Gerard Rovira <zurfyx@users.noreply.github.com>
  • Loading branch information
Sahejkm and zurfyx authored Apr 29, 2024
1 parent 34c70f1 commit 02ec0bb
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions packages/lexical/src/LexicalSelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1912,6 +1912,7 @@ function internalResolveSelectionPoint(
// We use the anchor to find which child node to select
const childNodes = dom.childNodes;
const childNodesLength = childNodes.length;
const blockCursorElement = editor._blockCursorElement;
// If the anchor is the same as length, then this means we
// need to select the very last text node.
if (resolvedOffset === childNodesLength) {
Expand All @@ -1920,11 +1921,20 @@ function internalResolveSelectionPoint(
}
let childDOM = childNodes[resolvedOffset];
let hasBlockCursor = false;
if (childDOM === editor._blockCursorElement) {
if (childDOM === blockCursorElement) {
childDOM = childNodes[resolvedOffset + 1];
hasBlockCursor = true;
} else if (editor._blockCursorElement !== null) {
resolvedOffset--;
} else if (blockCursorElement !== null) {
const blockCursorElementParent = blockCursorElement.parentNode;
if (dom === blockCursorElementParent) {
const blockCursorOffset = Array.prototype.indexOf.call(
blockCursorElementParent.children,
blockCursorElement,
);
if (offset > blockCursorOffset) {
resolvedOffset--;
}
}
}
resolvedNode = getNodeFromDOM(childDOM);

Expand Down

0 comments on commit 02ec0bb

Please sign in to comment.