Skip to content

Commit

Permalink
Addressed PR feedback for Unify implementations and deprecate @lexica…
Browse files Browse the repository at this point in the history
…l/selection
  • Loading branch information
Hadi Elghoul authored and Hadi Elghoul committed Dec 5, 2024
1 parent 6113603 commit b8a43e4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 36 deletions.
5 changes: 2 additions & 3 deletions packages/lexical-selection/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@ import {
getStyleObjectFromCSS,
} from './utils';

export {
/** @deprecated moved to the lexical package */ $selectAll,
} from 'lexical';
export {
/** @deprecated moved to the lexical package */ $cloneWithProperties,
/** @deprecated moved to the lexical package */ $selectAll,
} from 'lexical';

export {
$addNodeStyle,
$isAtNodeEnd,
Expand Down
5 changes: 0 additions & 5 deletions packages/lexical-selection/src/range-selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,11 +452,6 @@ export function $moveCharacter(
);
}

/**
* @deprecated This function has been moved to the lexical package. Use the $selectAll function from the lexical package instead.
*/
export {$selectAll} from 'lexical';

/**
* Returns the current value of a CSS property for Nodes, if set. If not set, it returns the defaultValue.
* @param node - The node whose style value to get.
Expand Down
32 changes: 4 additions & 28 deletions packages/lexical/src/LexicalUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1087,39 +1087,15 @@ export function isSelectAll(
export function $selectAll(selection?: RangeSelection | null): RangeSelection {
const root = $getRoot();

if (selection && $isRangeSelection(selection)) {
// Expand the existing RangeSelection
if ($isRangeSelection(selection)) {
const anchor = selection.anchor;
const focus = selection.focus;
const anchorNode = anchor.getNode();
const topParent = anchorNode.getTopLevelElementOrThrow();
const rootNode = topParent.getParentOrThrow();
let firstNode = rootNode.getFirstDescendant();
let lastNode = rootNode.getLastDescendant();
let firstType: 'element' | 'text' = 'element';
let lastType: 'element' | 'text' = 'element';
let lastOffset = 0;

if ($isTextNode(firstNode)) {
firstType = 'text';
} else if (!$isElementNode(firstNode) && firstNode !== null) {
firstNode = firstNode.getParentOrThrow();
}

if ($isTextNode(lastNode)) {
lastType = 'text';
lastOffset = lastNode.getTextContentSize();
} else if (!$isElementNode(lastNode) && lastNode !== null) {
lastNode = lastNode.getParentOrThrow();
}

if (firstNode && lastNode) {
anchor.set(firstNode.getKey(), 0, firstType);
focus.set(lastNode.getKey(), lastOffset, lastType);
}

// Normalize and set the updated selection
$setSelection($normalizeSelection(selection));
anchor.set(rootNode.getKey(), 0, 'element');
focus.set(rootNode.getKey(), rootNode.getChildrenSize(), 'element');
$normalizeSelection(selection);
return selection;
} else {
// Create a new RangeSelection
Expand Down

0 comments on commit b8a43e4

Please sign in to comment.