Skip to content

Commit

Permalink
fix(symbols): keep visual selection while selecting range (#3128)
Browse files Browse the repository at this point in the history
When selectRange is missing and use visual mode, we should reselect
the selection.

An edge case like the current range is the same as the range that
language server returned, coc will make n/vim lose the selection.
  • Loading branch information
kevinhwang91 authored Jun 5, 2021
1 parent 530a47c commit 44bac21
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/handler/symbols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,11 @@ export default class Symbols {
let endLine = doc.getline(end.line - 1)
selectRange = Range.create(start.line + 1, line.match(/^\s*/)[0].length, end.line - 1, endLine.length)
}
if (selectRange) await workspace.selectRange(selectRange)
if (selectRange) {
await workspace.selectRange(selectRange)
} else if (['v', 'V', '\x16'].includes(visualmode)) {
await this.nvim.command('normal! gv')
}
}

public dispose(): void {
Expand Down
2 changes: 1 addition & 1 deletion src/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ export class Workspace implements IWorkspace {
public async selectRange(range: Range): Promise<void> {
let { nvim } = this
let { start, end } = range
let [bufnr, ve, selection] = await nvim.eval(`[bufnr('%'), &virtualedit, &selection, mode()]`) as [number, string, string, string]
let [bufnr, ve, selection] = await nvim.eval(`[bufnr('%'), &virtualedit, &selection]`) as [number, string, string, string]
let document = this.getDocument(bufnr)
if (!document) return
let line = document.getline(start.line)
Expand Down

0 comments on commit 44bac21

Please sign in to comment.