From d7f455a05ecea5725453e3097bd287f6b9cbc66e Mon Sep 17 00:00:00 2001 From: umaranis Date: Mon, 25 Mar 2024 06:59:55 +1100 Subject: [PATCH] refactor: PointSelection instead of Grid/RangeSelections --- .../toolbar/BlockFormatDropDown/CodeDropDrownItem.svelte | 7 ++----- .../BlockFormatDropDown/HeadingDropDownItem.svelte | 8 ++------ .../BlockFormatDropDown/ParagraphDropDownItem.svelte | 7 ++----- .../toolbar/BlockFormatDropDown/QuoteDropDrownItem.svelte | 8 ++------ .../src/core/plugins/TreeView/TreeView.svelte | 3 ++- 5 files changed, 10 insertions(+), 23 deletions(-) diff --git a/packages/svelte-lexical/src/components/toolbar/BlockFormatDropDown/CodeDropDrownItem.svelte b/packages/svelte-lexical/src/components/toolbar/BlockFormatDropDown/CodeDropDrownItem.svelte index 5ca1470f..849677cc 100644 --- a/packages/svelte-lexical/src/components/toolbar/BlockFormatDropDown/CodeDropDrownItem.svelte +++ b/packages/svelte-lexical/src/components/toolbar/BlockFormatDropDown/CodeDropDrownItem.svelte @@ -8,7 +8,7 @@ import { $getSelection as getSelection, $isRangeSelection as isRangeSelection, - DEPRECATED_$isGridSelection, + $INTERNAL_isPointSelection as INTERNAL_PointSelection, } from 'lexical'; import {$createCodeNode as createCodeNode} from '@lexical/code'; @@ -21,10 +21,7 @@ editor.update(() => { let selection = getSelection(); - if ( - isRangeSelection(selection) || - DEPRECATED_$isGridSelection(selection) - ) { + if (INTERNAL_PointSelection(selection)) { if (selection.isCollapsed()) { setBlocksType(selection, () => createCodeNode()); } else { diff --git a/packages/svelte-lexical/src/components/toolbar/BlockFormatDropDown/HeadingDropDownItem.svelte b/packages/svelte-lexical/src/components/toolbar/BlockFormatDropDown/HeadingDropDownItem.svelte index 58f13588..8669a0b3 100644 --- a/packages/svelte-lexical/src/components/toolbar/BlockFormatDropDown/HeadingDropDownItem.svelte +++ b/packages/svelte-lexical/src/components/toolbar/BlockFormatDropDown/HeadingDropDownItem.svelte @@ -2,8 +2,7 @@ import DropDownItem from '../../generic/dropdown/DropDownItem.svelte'; import { $getSelection as getSelection, - $isRangeSelection as isRangeSelection, - DEPRECATED_$isGridSelection, + $INTERNAL_isPointSelection as INTERNAL_PointSelection, } from 'lexical'; import { $createHeadingNode as createHeadingNode, @@ -25,10 +24,7 @@ if ($blockType !== headingSize) { editor.update(() => { const selection = getSelection(); - if ( - isRangeSelection(selection) || - DEPRECATED_$isGridSelection(selection) - ) { + if (INTERNAL_PointSelection(selection)) { setBlocksType(selection, () => createHeadingNode(headingSize)); } }); diff --git a/packages/svelte-lexical/src/components/toolbar/BlockFormatDropDown/ParagraphDropDownItem.svelte b/packages/svelte-lexical/src/components/toolbar/BlockFormatDropDown/ParagraphDropDownItem.svelte index 082b06a6..f42eee21 100644 --- a/packages/svelte-lexical/src/components/toolbar/BlockFormatDropDown/ParagraphDropDownItem.svelte +++ b/packages/svelte-lexical/src/components/toolbar/BlockFormatDropDown/ParagraphDropDownItem.svelte @@ -7,7 +7,7 @@ $getSelection as getSelection, $isRangeSelection as isRangeSelection, $createParagraphNode as createParagraphNode, - DEPRECATED_$isGridSelection, + $INTERNAL_isPointSelection as INTERNAL_PointSelection, } from 'lexical'; import {$setBlocksType as setBlocksType} from '@lexical/selection'; import {getEditor} from '../../../core/composerContext'; @@ -20,10 +20,7 @@ if ($blockType !== 'paragraph') { editor.update(() => { const selection = getSelection(); - if ( - isRangeSelection(selection) || - DEPRECATED_$isGridSelection(selection) - ) + if (INTERNAL_PointSelection(selection)) setBlocksType(selection, () => createParagraphNode()); }); } diff --git a/packages/svelte-lexical/src/components/toolbar/BlockFormatDropDown/QuoteDropDrownItem.svelte b/packages/svelte-lexical/src/components/toolbar/BlockFormatDropDown/QuoteDropDrownItem.svelte index 086b4643..90a830df 100644 --- a/packages/svelte-lexical/src/components/toolbar/BlockFormatDropDown/QuoteDropDrownItem.svelte +++ b/packages/svelte-lexical/src/components/toolbar/BlockFormatDropDown/QuoteDropDrownItem.svelte @@ -7,8 +7,7 @@ import {$setBlocksType as setBlocksType} from '@lexical/selection'; import { $getSelection as getSelection, - $isRangeSelection as isRangeSelection, - DEPRECATED_$isGridSelection, + $INTERNAL_isPointSelection as INTERNAL_PointSelection, } from 'lexical'; import {$createQuoteNode as createQuoteNode} from '@lexical/rich-text'; @@ -20,10 +19,7 @@ if ($blockType !== 'quote') { editor.update(() => { const selection = getSelection(); - if ( - isRangeSelection(selection) || - DEPRECATED_$isGridSelection(selection) - ) { + if (INTERNAL_PointSelection(selection)) { setBlocksType(selection, () => createQuoteNode()); } }); diff --git a/packages/svelte-lexical/src/core/plugins/TreeView/TreeView.svelte b/packages/svelte-lexical/src/core/plugins/TreeView/TreeView.svelte index f6fa174f..5293227f 100644 --- a/packages/svelte-lexical/src/core/plugins/TreeView/TreeView.svelte +++ b/packages/svelte-lexical/src/core/plugins/TreeView/TreeView.svelte @@ -8,6 +8,7 @@ LexicalEditor, LexicalNode, RangeSelection, + INTERNAL_PointSelection, } from 'lexical'; import {$generateHtmlFromNodes as generateHtmlFromNodes} from '@lexical/html'; @@ -533,7 +534,7 @@ function getSelectionStartEnd( node: LexicalNode, - selection: RangeSelection | GridSelection, + selection: INTERNAL_PointSelection, ): [number, number] { const anchor = selection.anchor; const focus = selection.focus;