Skip to content

Commit

Permalink
Make sure the cursor is scrolled into view after applying a completion
Browse files Browse the repository at this point in the history
FIX: Make sure the cursor is scrolled into view after inserting completion text.

See https://discuss.codemirror.net/t/how-to-scroll-the-view-after-autocomplete-is-picked/6829
  • Loading branch information
marijnh committed Jul 18, 2023
1 parent a878319 commit 4e9fc1c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ export function insertCompletionText(state: EditorState, text: string, from: num
range: EditorSelection.cursor(range.from + fromOff + text.length)
}
}),
scrollIntoView: true,
userEvent: "input.complete"
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/snippet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ function moveField(dir: 1 | -1): StateCommand {
let next = active.active + dir, last = dir > 0 && !active.ranges.some(r => r.field == next + dir)
dispatch(state.update({
selection: fieldSelection(active.ranges, next),
effects: setActive.of(last ? null : new ActiveSnippet(active.ranges, next))
effects: setActive.of(last ? null : new ActiveSnippet(active.ranges, next)),
scrollIntoView: true
}))
return true
}
Expand Down Expand Up @@ -256,7 +257,9 @@ const snippetPointerHandler = EditorView.domEventHandlers({
if (!match || match.field == active.active) return false
view.dispatch({
selection: fieldSelection(active.ranges, match.field),
effects: setActive.of(active.ranges.some(r => r.field > match!.field) ? new ActiveSnippet(active.ranges, match.field) : null)
effects: setActive.of(active.ranges.some(r => r.field > match!.field)
? new ActiveSnippet(active.ranges, match.field) : null),
scrollIntoView: true
})
return true
}
Expand Down

0 comments on commit 4e9fc1c

Please sign in to comment.