From 86202e595b0f78f5dff17b6459ea2d2e483113e3 Mon Sep 17 00:00:00 2001 From: "posthog[bot]" <206114724+posthog[bot]@users.noreply.github.com> Date: Thu, 27 Aug 2026 21:34:50 +0000 Subject: [PATCH] fix(editor): clamp paste mark range to document size in authored-tracker handlePaste computed insertTo = insertFrom + slice.size with no clamp against the document size. slice.size counts the slice's open ends, which merge into surrounding blocks when you paste multiple blocks into a paragraph, so removeMark walked past the end of the document and threw "Cannot read properties of undefined (reading 'nodeSize')". The handler returns true, so the plugin owned the paste and the user's content was dropped. Clamp insertFrom and insertTo to tr.doc.content.size before the removeMark/addMark pair, matching the clamping the same file already does in appendTransaction. Generated-By: PostHog Desktop Task-Id: ee2f2fca-abd7-4a4a-a035-2b37dea8bddc --- src/editor/plugins/authored-tracker.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/editor/plugins/authored-tracker.ts b/src/editor/plugins/authored-tracker.ts index f2264687..7180e91f 100644 --- a/src/editor/plugins/authored-tracker.ts +++ b/src/editor/plugins/authored-tracker.ts @@ -76,8 +76,9 @@ export const authoredTrackerPlugin = $prose(() => { const { from } = view.state.selection; let tr = view.state.tr.replaceSelection(slice); - const insertFrom = tr.mapping.map(from, -1); - const insertTo = insertFrom + slice.size; + const docSize = tr.doc.content.size; + const insertFrom = Math.max(0, Math.min(tr.mapping.map(from, -1), docSize)); + const insertTo = Math.max(insertFrom, Math.min(insertFrom + slice.size, docSize)); if (insertTo > insertFrom) { tr = tr.removeMark(insertFrom, insertTo, markType);