Skip to content

Commit

Permalink
Fix composition bugs affecting intern (facebook#2487)
Browse files Browse the repository at this point in the history
  • Loading branch information
thegreatercurve authored Jun 21, 2022
1 parent 0863b62 commit 1cc09d3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/lexical/src/LexicalEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ export class LexicalEditor {
_compositionKey: null | NodeKey;
_deferred: Array<() => void>;
_keyToDOMMap: Map<NodeKey, HTMLElement>;
_updates: Array<[() => void, EditorUpdateOptions]>;
_updates: Array<[() => void, EditorUpdateOptions | undefined]>;
_updating: boolean;
_listeners: Listeners;
_commands: Commands;
Expand Down
2 changes: 1 addition & 1 deletion packages/lexical/src/LexicalUpdates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ export function updateEditor(
updateFn: () => void,
options?: EditorUpdateOptions,
): void {
if (editor._updating && options) {
if (editor._updating) {
editor._updates.push([updateFn, options]);
} else {
beginUpdate(editor, updateFn, options);
Expand Down
9 changes: 7 additions & 2 deletions packages/lexical/src/nodes/LexicalTextNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,15 @@ function setTextContent(
dom.textContent = text;
} else {
const nodeValue = firstChild.nodeValue;
if (nodeValue && nodeValue !== text)
if (nodeValue !== text) {
if (isComposing || IS_FIREFOX) {
// We also use the diff composed text for general text in FF to avoid
// We also use the diff composed text for general text in FF to avoid
// the spellcheck red line from flickering.
const [index, remove, insert] = diffComposedText(nodeValue, text);
const [index, remove, insert] = diffComposedText(
nodeValue as string,
text,
);
if (remove !== 0) {
// @ts-expect-error
firstChild.deleteData(index, remove);
Expand All @@ -224,6 +228,7 @@ function setTextContent(
} else {
firstChild.nodeValue = text;
}
}
}
}

Expand Down

0 comments on commit 1cc09d3

Please sign in to comment.