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; },