Skip to content

Commit

Permalink
[PR 3] Removed edge-cases of GridSelection (#5291)
Browse files Browse the repository at this point in the history
Co-authored-by: icrosil <[email protected]>
  • Loading branch information
icrosil and icrosil authored Dec 8, 2023
1 parent f38bd6a commit dcff8ae
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 26 deletions.
1 change: 0 additions & 1 deletion packages/lexical-clipboard/flow/LexicalClipboard.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import type {
BaseSelection,
LexicalEditor,
INTERNAL_PointSelection,
GridSelection,
RangeSelection,
LexicalNode,
} from 'lexical';
Expand Down
13 changes: 6 additions & 7 deletions packages/lexical-clipboard/src/clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
$createTabNode,
$getRoot,
$getSelection,
$INTERNAL_isPointSelection,
$isElementNode,
$isRangeSelection,
$isTextNode,
Expand All @@ -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,
Expand Down Expand Up @@ -206,17 +205,17 @@ export function $insertGeneratedNodes(
nodes: Array<LexicalNode>,
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 &&
Expand All @@ -233,7 +232,7 @@ export function $insertGeneratedNodes(

function $mergeGridNodesStrategy(
nodes: LexicalNode[],
selection: RangeSelection | GridSelection,
selection: INTERNAL_PointSelection,
isFromLexical: boolean,
editor: LexicalEditor,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions packages/lexical-selection/src/lexical-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
$setSelection,
BaseSelection,
DEPRECATED_$isGridCellNode,
DEPRECATED_$isGridSelection,
ElementNode,
INTERNAL_PointSelection,
LexicalEditor,
Expand Down Expand Up @@ -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;
Expand Down
16 changes: 0 additions & 16 deletions packages/lexical/src/LexicalSelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down

2 comments on commit dcff8ae

@vercel
Copy link

@vercel vercel bot commented on dcff8ae Dec 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

lexical – ./packages/lexical-website

lexical-git-main-fbopensource.vercel.app
lexical-fbopensource.vercel.app
www.lexical.dev
lexical.dev
lexicaljs.com
lexicaljs.org

@vercel
Copy link

@vercel vercel bot commented on dcff8ae Dec 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

lexical-playground – ./packages/lexical-playground

lexical-playground.vercel.app
lexical-playground-fbopensource.vercel.app
lexical-playground-git-main-fbopensource.vercel.app
playground.lexical.dev

Please sign in to comment.