fix: Retain image and video placeholders when document remotely edited

This commit is contained in:
Tom Moor
2023-09-21 00:15:54 -04:00
parent 34d4209dd5
commit 6672536cde
3 changed files with 41 additions and 10 deletions

View File

@@ -1,3 +1,4 @@
import { recreateTransform } from "@fellow/prosemirror-recreate-transform";
import { EditorState, Plugin } from "prosemirror-state";
import { Decoration, DecorationSet } from "prosemirror-view";
import * as React from "react";
@@ -11,8 +12,17 @@ const uploadPlaceholder = new Plugin({
return DecorationSet.empty;
},
apply(tr, set: DecorationSet) {
// Adjust decoration positions to changes made by the transaction
set = set.map(tr.mapping, tr.doc);
const ySyncEdit = !!tr.getMeta("y-sync$");
if (ySyncEdit) {
const mapping = recreateTransform(tr.before, tr.doc, {
complexSteps: true,
wordDiffs: false,
simplifyDiff: true,
}).mapping;
return set.map(mapping, tr.doc);
} else {
set = set.map(tr.mapping, tr.doc);
}
// See if the transaction adds or removes any placeholders
const action = tr.getMeta(this);