Skip to content

Commit

Permalink
Make snippet completions overwrite the selected text
Browse files Browse the repository at this point in the history
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
  • Loading branch information
marijnh committed Dec 5, 2024
1 parent c323263 commit 62dead9
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/snippet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,9 @@ export function snippet(template: string) {
let snippet = Snippet.parse(template)
return (editor: {state: EditorState, dispatch: (tr: Transaction) => void}, completion: Completion | null, from: number, to: number) => {
let {text, ranges} = snippet.instantiate(editor.state, from)
let {main} = editor.state.selection
let spec: TransactionSpec = {
changes: {from, to, insert: Text.of(text)},
changes: {from, to: to == main.from ? main.to : to, insert: Text.of(text)},
scrollIntoView: true,
annotations: completion ? [pickedCompletion.of(completion), Transaction.userEvent.of("input.complete")] : undefined
}
Expand Down

0 comments on commit 62dead9

Please sign in to comment.