From a7d3b37b7c81e4ac328427f5d79714ec6cc26004 Mon Sep 17 00:00:00 2001 From: Sherry Date: Mon, 29 Apr 2024 12:18:59 +0800 Subject: [PATCH 1/3] Documentation: add PR template (#5851) --- .github/pull_request_template.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/pull_request_template.md diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 00000000000..c8949b400c3 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,30 @@ + + +## Description + +*Describe the changes in this pull request* + +**Closes:** # + +## Test plan + +### Before + +*Insert relevant screenshots/recordings/automated-tests* + + +### After + +*Insert relevant screenshots/recordings/automated-tests* \ No newline at end of file From 34c70f19a37222f7cd58f62dc3bb9b0d0cd350c7 Mon Sep 17 00:00:00 2001 From: Sherry Date: Mon, 29 Apr 2024 14:46:28 +0800 Subject: [PATCH 2/3] refactor: cleanup unused react imports in tests files (#5983) --- .../lexical-react/src/__tests__/unit/LexicalComposer.test.tsx | 1 - .../src/__tests__/unit/PlainRichTextPlugin.test.tsx | 1 - .../src/__tests__/unit/LexicalSelection.test.tsx | 1 - .../src/__tests__/unit/LexicalTableSelection.test.tsx | 1 - .../src/__tests__/unit/LexicalEventHelpers.test.tsx | 1 - packages/lexical/src/__tests__/unit/LexicalListPlugin.test.tsx | 1 - 6 files changed, 6 deletions(-) diff --git a/packages/lexical-react/src/__tests__/unit/LexicalComposer.test.tsx b/packages/lexical-react/src/__tests__/unit/LexicalComposer.test.tsx index afb35f9fea5..6775ffac0ab 100644 --- a/packages/lexical-react/src/__tests__/unit/LexicalComposer.test.tsx +++ b/packages/lexical-react/src/__tests__/unit/LexicalComposer.test.tsx @@ -7,7 +7,6 @@ */ import {useLexicalComposerContext} from '@lexical/react/LexicalComposerContext'; -import * as React from 'react'; import {createRoot} from 'react-dom/client'; import * as ReactTestUtils from 'react-dom/test-utils'; diff --git a/packages/lexical-react/src/__tests__/unit/PlainRichTextPlugin.test.tsx b/packages/lexical-react/src/__tests__/unit/PlainRichTextPlugin.test.tsx index b1878b14921..2af120036c9 100644 --- a/packages/lexical-react/src/__tests__/unit/PlainRichTextPlugin.test.tsx +++ b/packages/lexical-react/src/__tests__/unit/PlainRichTextPlugin.test.tsx @@ -23,7 +23,6 @@ import { $getSelection, $isRangeSelection, } from 'lexical'; -import * as React from 'react'; import {createRoot} from 'react-dom/client'; import * as ReactTestUtils from 'react-dom/test-utils'; diff --git a/packages/lexical-selection/src/__tests__/unit/LexicalSelection.test.tsx b/packages/lexical-selection/src/__tests__/unit/LexicalSelection.test.tsx index d6a7b9a588a..5cef71ba65b 100644 --- a/packages/lexical-selection/src/__tests__/unit/LexicalSelection.test.tsx +++ b/packages/lexical-selection/src/__tests__/unit/LexicalSelection.test.tsx @@ -41,7 +41,6 @@ import { invariant, TestComposer, } from 'lexical/src/__tests__/utils'; -import * as React from 'react'; import {createRoot} from 'react-dom/client'; import * as ReactTestUtils from 'react-dom/test-utils'; diff --git a/packages/lexical-table/src/__tests__/unit/LexicalTableSelection.test.tsx b/packages/lexical-table/src/__tests__/unit/LexicalTableSelection.test.tsx index 4d5f9f3ae95..f098b0b9c86 100644 --- a/packages/lexical-table/src/__tests__/unit/LexicalTableSelection.test.tsx +++ b/packages/lexical-table/src/__tests__/unit/LexicalTableSelection.test.tsx @@ -15,7 +15,6 @@ import { $setSelection, } from 'lexical'; import {createTestEditor} from 'lexical/src/__tests__/utils'; -import * as React from 'react'; import {createRef, useEffect, useMemo} from 'react'; import {createRoot} from 'react-dom/client'; import * as ReactTestUtils from 'react-dom/test-utils'; diff --git a/packages/lexical-utils/src/__tests__/unit/LexicalEventHelpers.test.tsx b/packages/lexical-utils/src/__tests__/unit/LexicalEventHelpers.test.tsx index 7434d0a0937..7a4ed67ba7f 100644 --- a/packages/lexical-utils/src/__tests__/unit/LexicalEventHelpers.test.tsx +++ b/packages/lexical-utils/src/__tests__/unit/LexicalEventHelpers.test.tsx @@ -23,7 +23,6 @@ import { } from '@lexical/selection/src/__tests__/utils'; import {TableCellNode, TableNode, TableRowNode} from '@lexical/table'; import {initializeClipboard, TestComposer} from 'lexical/src/__tests__/utils'; -import * as React from 'react'; import {createRoot} from 'react-dom/client'; import * as ReactTestUtils from 'react-dom/test-utils'; diff --git a/packages/lexical/src/__tests__/unit/LexicalListPlugin.test.tsx b/packages/lexical/src/__tests__/unit/LexicalListPlugin.test.tsx index 37c0aa4de3a..f9e6544fe95 100644 --- a/packages/lexical/src/__tests__/unit/LexicalListPlugin.test.tsx +++ b/packages/lexical/src/__tests__/unit/LexicalListPlugin.test.tsx @@ -21,7 +21,6 @@ import { html, TestComposer, } from 'lexical/src/__tests__/utils'; -import * as React from 'react'; import {createRoot, Root} from 'react-dom/client'; import * as ReactTestUtils from 'react-dom/test-utils'; From 02ec0bb8755ee2a574c834332df811149c527c22 Mon Sep 17 00:00:00 2001 From: Sahejkm <163521239+Sahejkm@users.noreply.github.com> Date: Mon, 29 Apr 2024 15:21:51 +0800 Subject: [PATCH 3/3] Fix #5738 wrong selection on mouse click (#5969) Co-authored-by: Gerard Rovira --- packages/lexical/src/LexicalSelection.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/lexical/src/LexicalSelection.ts b/packages/lexical/src/LexicalSelection.ts index 12067bad8e3..8bd4f1467d9 100644 --- a/packages/lexical/src/LexicalSelection.ts +++ b/packages/lexical/src/LexicalSelection.ts @@ -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) { @@ -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);