Skip to content

Commit

Permalink
Fix C-n and C-p in autocomplete for multi cursor (#3283)
Browse files Browse the repository at this point in the history
This fixes jumping the autocomplete options in multi cursors so that it
only jumps one at a time. Without this fix it jumps once _per cursor_,
so if I have 3 cursors, I am forced to traverse the list 3 at a time.

I initially found this as part of #3282.
  • Loading branch information
jackfranklin authored and jpoon committed Feb 1, 2019
1 parent 3072338 commit 088536d
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions src/actions/commands/insert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,23 @@ class CommandNavigateAutocompleteDown extends BaseCommand {
keys = [['<C-n>'], ['<C-j>']];

public async exec(position: Position, vimState: VimState): Promise<VimState> {
await vscode.commands.executeCommand('selectNextSuggestion');
/* if we're in a multi cursor state, we check to see if the current active text selection
* is the same as the position we've been passed when we exec this function
* this has the effect of only ever executing `selectNextSuggestion` once.
* without this we execute it once per multi cursor, meaning it skips over the autocomplete
* list suggestions
*/
if (vimState.isMultiCursor && vscode.window.activeTextEditor) {
const selection = vscode.window.activeTextEditor.selections[0];
if (
selection.active.line === position.line &&
selection.active.character === position.character
) {
await vscode.commands.executeCommand('selectNextSuggestion');
}
} else {
await vscode.commands.executeCommand('selectNextSuggestion');
}

return vimState;
}
Expand All @@ -494,7 +510,23 @@ class CommandNavigateAutocompleteUp extends BaseCommand {
keys = [['<C-p>'], ['<C-k>']];

public async exec(position: Position, vimState: VimState): Promise<VimState> {
await vscode.commands.executeCommand('selectPrevSuggestion');
/* if we're in a multi cursor state, we check to see if the current active text selection
* is the same as the position we've been passed when we exec this function
* this has the effect of only ever executing `selectPrevSuggestion` once.
* without this we execute it once per multi cursor, meaning it skips over the autocomplete
* list suggestions
*/
if (vimState.isMultiCursor && vscode.window.activeTextEditor) {
const selection = vscode.window.activeTextEditor.selections[0];
if (
selection.active.line === position.line &&
selection.active.character === position.character
) {
await vscode.commands.executeCommand('selectPrevSuggestion');
}
} else {
await vscode.commands.executeCommand('selectPrevSuggestion');
}

return vimState;
}
Expand Down

0 comments on commit 088536d

Please sign in to comment.