fix: Capture errors recreating transform and log, these are non-critical

This commit is contained in:
Tom Moor
2023-09-25 20:45:34 -04:00
parent 0014bcf22d
commit b1ddf417be

View File

@@ -2,6 +2,7 @@ import { EditorState, Plugin } from "prosemirror-state";
import { Decoration, DecorationSet } from "prosemirror-view"; import { Decoration, DecorationSet } from "prosemirror-view";
import * as React from "react"; import * as React from "react";
import ReactDOM from "react-dom"; import ReactDOM from "react-dom";
import Logger from "~/utils/Logger";
import FileExtension from "../components/FileExtension"; import FileExtension from "../components/FileExtension";
import { recreateTransform } from "./prosemirror-recreate-transform"; import { recreateTransform } from "./prosemirror-recreate-transform";
@@ -13,16 +14,21 @@ const uploadPlaceholder = new Plugin({
}, },
apply(tr, set: DecorationSet) { apply(tr, set: DecorationSet) {
const ySyncEdit = !!tr.getMeta("y-sync$"); const ySyncEdit = !!tr.getMeta("y-sync$");
let mapping = tr.mapping;
if (ySyncEdit) { if (ySyncEdit) {
const mapping = recreateTransform(tr.before, tr.doc, { try {
mapping = recreateTransform(tr.before, tr.doc, {
complexSteps: true, complexSteps: true,
wordDiffs: false, wordDiffs: false,
simplifyDiff: true, simplifyDiff: true,
}).mapping; }).mapping;
set = set.map(mapping, tr.doc); } catch (err) {
} else { Logger.warn("Failed to recreate transform", err);
set = set.map(tr.mapping, tr.doc);
} }
}
set = set.map(mapping, tr.doc);
// See if the transaction adds or removes any placeholders // See if the transaction adds or removes any placeholders
const action = tr.getMeta(this); const action = tr.getMeta(this);