Skip to content

Commit

Permalink
Revert "includeIfCollapsed"
Browse files Browse the repository at this point in the history
This reverts commit f6407b7.
  • Loading branch information
GermanJablo committed Dec 20, 2024
1 parent cd2a199 commit 813d61c
Showing 1 changed file with 7 additions and 18 deletions.
25 changes: 7 additions & 18 deletions packages/lexical-selection/src/lexical-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,33 +289,22 @@ export function $patchStyleText(
) => string)
>,
): void {
$forEachSelectedTextNode((textNode) => {
$patchStyle(textNode, patch);
});
if (selection.isCollapsed() && $isRangeSelection(selection)) {
$patchStyle(selection, patch);
} else {
$forEachSelectedTextNode((textNode) => {
$patchStyle(textNode, patch);
});
}
}

/**
* @param fn - The function to apply to each selected TextNode.
* @param includeIfCollapsed - Whether to include the TextNode if the selection is collapsed. Defaults to false.
*/
export function $forEachSelectedTextNode(
fn: (textNode: TextNode) => void,
includeIfCollapsed = false,
): void {
const selection = $getSelection();
if (!$isRangeSelection(selection)) {
return;
}
if (selection.isCollapsed()) {
if (!includeIfCollapsed) {
return;
}
const node = selection.anchor.getNode();
if ($isTextNode(node)) {
fn(node);
}
return;
}
const selectedNodes = selection.getNodes();
const selectedNodesLength = selectedNodes.length;
const {anchor, focus} = selection;
Expand Down

0 comments on commit 813d61c

Please sign in to comment.