Skip to content

Commit

Permalink
refactor: PointSelection instead of Grid/RangeSelections
Browse files Browse the repository at this point in the history
  • Loading branch information
umaranis committed Mar 24, 2024
1 parent 398c05a commit d7f455a
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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));
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
$getSelection as getSelection,
$isRangeSelection as isRangeSelection,

Check failure on line 8 in packages/svelte-lexical/src/components/toolbar/BlockFormatDropDown/ParagraphDropDownItem.svelte

View workflow job for this annotation

GitHub Actions / build

'isRangeSelection' is defined but never used
$createParagraphNode as createParagraphNode,
DEPRECATED_$isGridSelection,
$INTERNAL_isPointSelection as INTERNAL_PointSelection,
} from 'lexical';
import {$setBlocksType as setBlocksType} from '@lexical/selection';
import {getEditor} from '../../../core/composerContext';
Expand All @@ -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());
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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());
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
LexicalEditor,
LexicalNode,
RangeSelection,
INTERNAL_PointSelection,
} from 'lexical';
import {$generateHtmlFromNodes as generateHtmlFromNodes} from '@lexical/html';
Expand Down Expand Up @@ -533,7 +534,7 @@
function getSelectionStartEnd(
node: LexicalNode,
selection: RangeSelection | GridSelection,
selection: INTERNAL_PointSelection,
): [number, number] {
const anchor = selection.anchor;
const focus = selection.focus;
Expand Down

0 comments on commit d7f455a

Please sign in to comment.