From dcff8ae5afb7c0c2f4c157d209f3a1f2f108fe73 Mon Sep 17 00:00:00 2001 From: Illia Olenchenko Date: Fri, 8 Dec 2023 16:41:59 +0000 Subject: [PATCH] [PR 3] Removed edge-cases of GridSelection (#5291) Co-authored-by: icrosil --- .../flow/LexicalClipboard.js.flow | 1 - packages/lexical-clipboard/src/clipboard.ts | 13 ++++++------- .../html/TablesHTMLCopyAndPaste.spec.mjs | 4 ++++ packages/lexical-selection/src/lexical-node.ts | 3 +-- packages/lexical/src/LexicalSelection.ts | 16 ---------------- 5 files changed, 11 insertions(+), 26 deletions(-) diff --git a/packages/lexical-clipboard/flow/LexicalClipboard.js.flow b/packages/lexical-clipboard/flow/LexicalClipboard.js.flow index 66737af83f7..399f4cc9afe 100644 --- a/packages/lexical-clipboard/flow/LexicalClipboard.js.flow +++ b/packages/lexical-clipboard/flow/LexicalClipboard.js.flow @@ -11,7 +11,6 @@ import type { BaseSelection, LexicalEditor, INTERNAL_PointSelection, - GridSelection, RangeSelection, LexicalNode, } from 'lexical'; diff --git a/packages/lexical-clipboard/src/clipboard.ts b/packages/lexical-clipboard/src/clipboard.ts index 07c0f5bfdc6..7ef2c04567a 100644 --- a/packages/lexical-clipboard/src/clipboard.ts +++ b/packages/lexical-clipboard/src/clipboard.ts @@ -18,6 +18,7 @@ import { $createTabNode, $getRoot, $getSelection, + $INTERNAL_isPointSelection, $isElementNode, $isRangeSelection, $isTextNode, @@ -30,13 +31,11 @@ import { DEPRECATED_$isGridCellNode, DEPRECATED_$isGridNode, DEPRECATED_$isGridRowNode, - DEPRECATED_$isGridSelection, DEPRECATED_GridNode, - GridSelection, + INTERNAL_PointSelection, isSelectionWithinEditor, LexicalEditor, LexicalNode, - RangeSelection, SELECTION_CHANGE_COMMAND, SerializedElementNode, SerializedTextNode, @@ -206,17 +205,17 @@ export function $insertGeneratedNodes( nodes: Array, selection: BaseSelection, ): void { - const isGridSelection = DEPRECATED_$isGridSelection(selection); + const isPointSelection = $INTERNAL_isPointSelection(selection); const isRangeSelection = $isRangeSelection(selection); const isSelectionInsideOfGrid = - isGridSelection || (isRangeSelection && $findMatchingParent(selection.anchor.getNode(), (n) => DEPRECATED_$isGridCellNode(n), ) !== null && $findMatchingParent(selection.focus.getNode(), (n) => DEPRECATED_$isGridCellNode(n), - ) !== null); + ) !== null) || + (isPointSelection && !isRangeSelection); if ( isSelectionInsideOfGrid && @@ -233,7 +232,7 @@ export function $insertGeneratedNodes( function $mergeGridNodesStrategy( nodes: LexicalNode[], - selection: RangeSelection | GridSelection, + selection: INTERNAL_PointSelection, isFromLexical: boolean, editor: LexicalEditor, ) { diff --git a/packages/lexical-playground/__tests__/e2e/CopyAndPaste/html/TablesHTMLCopyAndPaste.spec.mjs b/packages/lexical-playground/__tests__/e2e/CopyAndPaste/html/TablesHTMLCopyAndPaste.spec.mjs index 574e14eef68..7500887fbfb 100644 --- a/packages/lexical-playground/__tests__/e2e/CopyAndPaste/html/TablesHTMLCopyAndPaste.spec.mjs +++ b/packages/lexical-playground/__tests__/e2e/CopyAndPaste/html/TablesHTMLCopyAndPaste.spec.mjs @@ -242,6 +242,10 @@ test.describe('HTML Tables CopyAndPaste', () => { test('Copy + paste - Merge Grids', async ({page, isPlainText, isCollab}) => { test.skip(isPlainText); + test.fixme( + isCollab, + 'Table selection styles are not properly selected/deselected', + ); await focusEditor(page); await insertTable(page, 4, 4); diff --git a/packages/lexical-selection/src/lexical-node.ts b/packages/lexical-selection/src/lexical-node.ts index 785cfe0f396..f49fd82ae1b 100644 --- a/packages/lexical-selection/src/lexical-node.ts +++ b/packages/lexical-selection/src/lexical-node.ts @@ -19,7 +19,6 @@ import { $setSelection, BaseSelection, DEPRECATED_$isGridCellNode, - DEPRECATED_$isGridSelection, ElementNode, INTERNAL_PointSelection, LexicalEditor, @@ -328,7 +327,7 @@ export function $patchStyleText( const selectedNodes = selection.getNodes(); const selectedNodesLength = selectedNodes.length; - if (DEPRECATED_$isGridSelection(selection)) { + if (!$isRangeSelection(selection)) { const cellSelection = $createRangeSelection(); const cellSelectionAnchor = cellSelection.anchor; const cellSelectionFocus = cellSelection.focus; diff --git a/packages/lexical/src/LexicalSelection.ts b/packages/lexical/src/LexicalSelection.ts index 5e1c3a9f429..f3aa0e9057f 100644 --- a/packages/lexical/src/LexicalSelection.ts +++ b/packages/lexical/src/LexicalSelection.ts @@ -545,14 +545,6 @@ export class GridSelection extends INTERNAL_PointSelection { this.gridKey = gridKey; } - getCachedNodes(): LexicalNode[] | null { - return this._cachedNodes; - } - - setCachedNodes(nodes: LexicalNode[] | null): void { - this._cachedNodes = nodes; - } - is(selection: null | BaseSelection): boolean { if (!DEPRECATED_$isGridSelection(selection)) { return false; @@ -841,14 +833,6 @@ export class RangeSelection extends INTERNAL_PointSelection { this.style = style; } - getCachedNodes(): LexicalNode[] | null { - return this._cachedNodes; - } - - setCachedNodes(nodes: LexicalNode[] | null): void { - this._cachedNodes = nodes; - } - /** * Used to check if the provided selections is equal to this one by value, * inluding anchor, focus, format, and style properties.