v145 · Web APIs · Undo Coalescer

Undo coalescer

Editor that uses Chrome 145's deletion inputType distinctions to chunk undo history — coalescing rapid Backspaces but breaking the chain when the user selects and deletes content.

type, then undo / redo

Select text and press Backspace — the InputEvent reports deleteContent instead of deleteContentBackward, which we use to split undo history.

Type or paste here, then select a few words and press Backspace.
coalesced into prior step new undo step

undo history

code

ed.addEventListener('beforeinput', (e) => {
  const distinct = /^delete(Content|ByCut|HardLineBackward|ByDrag)$/.test(e.inputType);
  if (distinct) flush(); // start a new undo step
  else stay();           // coalesce with previous backspace
});

see also