From a5cecb9b951d3cc64a5ca938a6782bd658325efe Mon Sep 17 00:00:00 2001 From: l0ng-ai <24760907+l0ng-ai@users.noreply.github.com> Date: Sat, 14 Nov 2026 23:26:41 +0800 Subject: [PATCH] fix(plugins): keep document indexer markers on their lines while typing Every edit emptied the indexed-marker gutter until the host re-indexed the file. The column has no fixed width, so it collapsed and the text shifted left, then back once the new markers arrived: typing in a mapped file made the editor jitter. Map the markers through the change instead; a deleted line still drops its own, and the next indexed result replaces them. --- src/features/plugins/indexedMarkers.test.ts | 9 ++++++++- src/features/plugins/indexedMarkers.ts | 6 ++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/features/plugins/indexedMarkers.test.ts b/src/features/plugins/indexedMarkers.test.ts index 8a4babef58..cbb27dda10 100644 --- a/src/features/plugins/indexedMarkers.test.ts +++ b/src/features/plugins/indexedMarkers.test.ts @@ -56,10 +56,17 @@ it("puts a button on the marker's line that goes to its target", async () => { expect(calls.navigate).toHaveBeenCalledWith(target); }); -it("hides markers on edit and when the entry goes away", async () => { +it("keeps markers on their lines while typing and hides them when the entry goes away", async () => { setup(); await vi.waitFor(() => expect(button()).not.toBeNull()); + // Typing must not empty the column: it would collapse and shift the text (#3370). + view!.dispatch({ changes: { from: source.indexOf("SELECT"), insert: "x" } }); + expect(button()).not.toBeNull(); view!.dispatch({ changes: { from: 0, insert: "\n" } }); + expect(button()).not.toBeNull(); + // Deleting the marker's line drops it. + const line = view!.state.doc.line(3); + view!.dispatch({ changes: { from: line.from - 1, to: line.to } }); expect(button()).toBeNull(); usePluginMarkers.setState({ entries: new Map() }); await vi.waitFor(() => expect(button()).toBeNull()); diff --git a/src/features/plugins/indexedMarkers.ts b/src/features/plugins/indexedMarkers.ts index b650d73b7a..b0608ab7a6 100644 --- a/src/features/plugins/indexedMarkers.ts +++ b/src/features/plugins/indexedMarkers.ts @@ -1,7 +1,8 @@ /** * Gutter markers from plugins' document indexers, resolved by the host from * its cached graph. A click goes to the marker's targets (a chooser when there - * are several); an edit hides the markers until the edited text is indexed. + * are several); an edit keeps them on their lines until the edited text is indexed, + * so the column keeps its width while typing. */ import { RangeSet, StateEffect, StateField, type Extension } from "@codemirror/state"; import { EditorView, GutterMarker, ViewPlugin, gutter, type ViewUpdate } from "@codemirror/view"; @@ -52,7 +53,8 @@ const setMarkers = StateEffect.define>(); const markersField = StateField.define>({ create: () => RangeSet.empty, update(value, tr) { - if (tr.docChanged) value = RangeSet.empty; + // Markers move with the text; a deleted line drops its own. + if (tr.docChanged) value = value.map(tr.changes); for (const effect of tr.effects) if (effect.is(setMarkers)) value = effect.value; return value; },