Prevent diffing against a stale snapshot or position

While doing some testing on the user experience of multiple users concurrently editing a shared post via the shared-edits plugin, I ran into scenarios where parts of new additions where silently dropped or new content was weirdly mangled into existing content without any regards to word boundaries and such.

It turned out, there were two places in the plugin code, where in a scenario of concurrent edits, users would get changes applied to an outdated snapshot of the content, rather than the content they’re actually seeing.

I updated the code so that the diffing takes place on the actual current state of the editor / the DOM, rather than on a previously taken snapshot. See the corresponding PR for the details.

With the change in, I feel like the overall user experience got a bit smoother, even when concurrently editing the exact same position in a document. The outcome is more human readable and one gets less word-in-word mangling.

(Background on this: I’m running an automated test with Playwright that does some concurrent edits on a post.)

I’m continuing to test/benchmark this and I may have found another occurrence :eyes:

Will take a look to verify and then update the PR.