Skip to content

Commit

Permalink
[0.5] Treat undefined selection the same as null in $generateNodesFro…
Browse files Browse the repository at this point in the history
…mHtml (facebook#2948)

* Treat undefined selection the same as null in $generateNodesFromHtml

* fix mistake

* address feedback

* reorder params and remove undefined check
  • Loading branch information
acywatson authored Sep 15, 2022
1 parent ce2b9a7 commit faa44ff
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions packages/lexical-html/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,17 @@ export function $generateHtmlFromNodes(

for (let i = 0; i < topLevelChildren.length; i++) {
const topLevelNode = topLevelChildren[i];
if (selection !== undefined) {
$appendNodesToHTML(editor, selection, topLevelNode, container);
}
$appendNodesToHTML(editor, topLevelNode, container, selection);
}

return container.innerHTML;
}

function $appendNodesToHTML(
editor: LexicalEditor,
selection: RangeSelection | NodeSelection | GridSelection | null,
currentNode: LexicalNode,
parentElement: HTMLElement | DocumentFragment,
selection: RangeSelection | NodeSelection | GridSelection | null = null,
): boolean {
let shouldInclude = selection != null ? currentNode.isSelected() : true;
const shouldExclude =
Expand Down Expand Up @@ -108,9 +106,9 @@ function $appendNodesToHTML(
const childNode = children[i];
const shouldIncludeChild = $appendNodesToHTML(
editor,
selection,
childNode,
fragment,
selection,
);

if (
Expand Down

0 comments on commit faa44ff

Please sign in to comment.