From 0b6faf9c032f86b69e3110381aa23eafc845acc4 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Thu, 11 Jan 2024 17:54:27 +0100 Subject: [PATCH] Fix snippets with only one field with multiple instances FIX: Fix a crash when using a snippet that has only one field, but multiple instances of that field. See https://discuss.codemirror.net/t/code-snippet-placeholder-causes-error/7682 --- src/snippet.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/snippet.ts b/src/snippet.ts index 32351da..ad53b6e 100644 --- a/src/snippet.ts +++ b/src/snippet.ts @@ -174,7 +174,7 @@ export function snippet(template: string) { annotations: completion ? [pickedCompletion.of(completion), Transaction.userEvent.of("input.complete")] : undefined } if (ranges.length) spec.selection = fieldSelection(ranges, 0) - if (ranges.length > 1) { + if (ranges.some(r => r.field > 0)) { let active = new ActiveSnippet(ranges, 0) let effects: StateEffect[] = spec.effects = [setActive.of(active)] if (editor.state.field(snippetState, false) === undefined)