Skip to content

Commit 62dead9

Browse files
committed
Make snippet completions overwrite the selected text
FIX: Align the behavior of snippet completions with text completions in that they overwrite the selected text. See https://discuss.codemirror.net/t/autocompleting-the-expressions-of-a-snippet/6226/4
1 parent c323263 commit 62dead9

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/snippet.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,9 @@ export function snippet(template: string) {
169169
let snippet = Snippet.parse(template)
170170
return (editor: {state: EditorState, dispatch: (tr: Transaction) => void}, completion: Completion | null, from: number, to: number) => {
171171
let {text, ranges} = snippet.instantiate(editor.state, from)
172+
let {main} = editor.state.selection
172173
let spec: TransactionSpec = {
173-
changes: {from, to, insert: Text.of(text)},
174+
changes: {from, to: to == main.from ? main.to : to, insert: Text.of(text)},
174175
scrollIntoView: true,
175176
annotations: completion ? [pickedCompletion.of(completion), Transaction.userEvent.of("input.complete")] : undefined
176177
}

0 commit comments

Comments
 (0)