Skip to content

Commit

Permalink
Fix snippets with only one field with multiple instances
Browse files Browse the repository at this point in the history
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
  • Loading branch information
marijnh committed Jan 11, 2024
1 parent f17d63b commit 0b6faf9
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/snippet.ts
Expand Up @@ -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<unknown>[] = spec.effects = [setActive.of(active)]
if (editor.state.field(snippetState, false) === undefined)
Expand Down

0 comments on commit 0b6faf9

Please sign in to comment.