Skip to content

Commit

Permalink
refactor: registerMutationListener should initialize its existing nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
umaranis committed Oct 7, 2024
1 parent d5efec2 commit 55743fb
Showing 1 changed file with 22 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,26 +83,29 @@
);
onMount(() => {
return editor.registerMutationListener(CodeNode, (mutations) => {
editor.getEditorState().read(() => {
for (const [key, type] of mutations) {
switch (type) {
case 'created':
codeSetRef.add(key);
shouldListenMouseMove = codeSetRef.size > 0;
break;
case 'destroyed':
codeSetRef.delete(key);
shouldListenMouseMove = codeSetRef.size > 0;
break;
default:
break;
return editor.registerMutationListener(
CodeNode,
(mutations) => {
editor.getEditorState().read(() => {
for (const [key, type] of mutations) {
switch (type) {
case 'created':
codeSetRef.add(key);
break;
case 'destroyed':
codeSetRef.delete(key);
break;
default:
break;
}
}
}
});
});
});
shouldListenMouseMove = codeSetRef.size > 0;
},
{skipInitialization: false},
);
});
$: if (shouldListenMouseMove) {
Expand Down

0 comments on commit 55743fb

Please sign in to comment.