From cf22952c62b9740b3c4020852bd5262ee6ed3c8f Mon Sep 17 00:00:00 2001 From: David Krcek Date: Wed, 10 Jun 2026 00:00:05 +0200 Subject: [PATCH] fix(editor): per-view ordered-list renumber guard The renumberInFlight guard was a module-level boolean shared by every editor instance, so in a split-pane layout one pane's in-flight renumber could suppress another pane's, leaving the second list mis-numbered. Key the flag on the EditorView via a WeakMap instead. Co-Authored-By: Claude Opus 4.8 (1M context) --- src/components/editor/CodeMirrorEditor.tsx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/components/editor/CodeMirrorEditor.tsx b/src/components/editor/CodeMirrorEditor.tsx index 1ceea70..0ed6a1a 100644 --- a/src/components/editor/CodeMirrorEditor.tsx +++ b/src/components/editor/CodeMirrorEditor.tsx @@ -369,10 +369,13 @@ function moveLineThenRenumber(base: Command): Command { // AND the change inserted or deleted a newline (the operations that shift item // counts); pure in-line typing is left alone for performance. const ORDERED_LINE_PROBE = /(^|\n)\s*\d+\.\s/ -let renumberInFlight = false +// Per-view guard. A single module-level boolean would be shared by every +// editor instance, so in a split-pane layout one pane's in-flight renumber +// would suppress another pane's. Key the flag on the EditorView instead. +const renumberInFlight = new WeakMap() const renumberOnEdit = EditorView.updateListener.of((update) => { if (!update.docChanged) return - if (renumberInFlight) return + if (renumberInFlight.get(update.view)) return if (update.view.composing) return let touchedNewline = false @@ -403,14 +406,14 @@ const renumberOnEdit = EditorView.updateListener.of((update) => { if (!touchedNewline && !touchedOrderedLineStart) return if (!ORDERED_LINE_PROBE.test(update.state.doc.toString())) return - renumberInFlight = true + renumberInFlight.set(update.view, true) // Defer to escape the current update cycle (dispatching inside an // updateListener is discouraged). queueMicrotask(() => { try { renumberDocument(update.view) } finally { - renumberInFlight = false + renumberInFlight.delete(update.view) } }) })