Applying a "standard" text diff patch to editor content?

Is there an extension (or even built in functions) for applying “standard” text diff patches to content in an editor, so that you don’t have to grab the content as string, patch that, then overwrite the content with that update?

E.g. is there something that can simply be fed a patch like:

--- a/old_file.txt
+++ b/new_file.txt
@@ -1,3 +1,4 @@
 This is the first line.
-This line will be deleted.
+This line will be added.
 This is the third line.
+This is another new line.

and then updates only the relevant stretches of document, rather than needing something like

const current = editor.state.doc.toString();
const updated = applyPatch(current, patch);
editor.dispatch({
  changes: {
    from: 0,
    to: current.length,
    insert: updated,
  },
});

I’m not aware of such code. I could imagine there existing a JS library for applying patches that exposes the ranges it actually replaces (or can be modified to do so), which would make it pretty easy to generate the appropriate editor changes, but with a quick search I didn’t actually locate such a thing.

1 Like

Cheers.

I guess I’ll file an issue in the repo I’m working in atm for seeing how much work writing that would be, so that if someone has time maybe we can roll our own (and if it works well enough, make it a little extension that others can use, too).