Skip to content

Safari Desktop: programmatic document.exectCommand('undo') at oncompositionend not working #16

@michael

Description

@michael

For context: I'm searching for solutions to make my editor (svedit.dev) work with incremental rerendering (after an internal model change). See #13 for details.

I proposed something like this:

function oncompositionend(event) {
  // Roll back the dom changes made throughout the composition, so the DOM is in
  // sync with my document model again, before i apply the change to the document model,
  // allowing for 
  event.resetDOM(); 
  doc.apply(doc.tr.insert_text(event.data);
}

Since an API like event.resetDOM() does not yet exist, I had the idea that programmatically calling undo would have the same effect. And yes, it does. 🍾

function oncompositionend(event) {
  document.execCommand('undo');
  doc.apply(doc.tr.insert_text(event.data);
}

BUT: This does not reliably work on Safari Desktop. 😢 It looks like the Undo is not performed. However, it generally seems to break some internal state of the browser after I run my incremental rerender. Safari Mobile is no problem, as there are no composition events anyways.

To isolate the problem I created a reproduction, where you can see the difference in behavior when running the code in Safari.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions