MCPcopy Create free account
hub / github.com/FormidableLabs/use-editable / flushChanges

Function flushChanges

src/useEditable.ts:345–369  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

343 };
344
345 const flushChanges = () => {
346 state.queue.push(...state.observer.takeRecords());
347 const position = getPosition(element);
348 if (state.queue.length) {
349 disconnect();
350 const content = toString(element);
351 state.position = position;
352 let mutation: MutationRecord | void;
353 let i = 0;
354 while ((mutation = state.queue.pop())) {
355 if (mutation.oldValue !== null)
356 mutation.target.textContent = mutation.oldValue;
357 for (i = mutation.removedNodes.length - 1; i >= 0; i--)
358 mutation.target.insertBefore(
359 mutation.removedNodes[i],
360 mutation.nextSibling
361 );
362 for (i = mutation.addedNodes.length - 1; i >= 0; i--)
363 if (mutation.addedNodes[i].parentNode)
364 mutation.target.removeChild(mutation.addedNodes[i]);
365 }
366
367 state.onChange(content, position);
368 }
369 };
370
371 const onKeyDown = (event: HTMLElementEventMap['keydown']) => {
372 if (event.defaultPrevented || event.target !== element) {

Callers 3

onKeyDownFunction · 0.85
onKeyUpFunction · 0.85
onPasteFunction · 0.85

Calls 4

getPositionFunction · 0.85
disconnectFunction · 0.85
toStringFunction · 0.85
onChangeMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…