Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draw multicursor correctly in Visual Mode #920

Merged
merged 2 commits into from
Oct 14, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 27 additions & 26 deletions src/mode/modeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1239,37 +1239,32 @@ export class ModeHandler implements vscode.Disposable {
}

public async updateView(vimState: VimState, drawSelection = true): Promise<void> {
// Update cursor position

let start = vimState.cursorStartPosition;
let stop = vimState.cursorPosition;

if (vimState.currentMode === ModeName.Visual) {

/**
* Always select the letter that we started visual mode on, no matter
* if we are in front or behind it. Imagine that we started visual mode
* with some text like this:
*
* abc|def
*
* (The | represents the cursor.) If we now press w, we'll select def,
* but if we hit b we expect to select abcd, so we need to getRight() on the
* start of the selection when it precedes where we started visual mode.
*/

if (start.compareTo(stop) > 0) {
start = start.getRight();
}
}

// Draw selection (or cursor)

if (drawSelection) {
let selections: vscode.Selection[];

if (!vimState.isMultiCursor) {
let start = vimState.cursorStartPosition;
let stop = vimState.cursorPosition;

if (vimState.currentMode === ModeName.Visual) {
/**
* Always select the letter that we started visual mode on, no matter
* if we are in front or behind it. Imagine that we started visual mode
* with some text like this:
*
* abc|def
*
* (The | represents the cursor.) If we now press w, we'll select def,
* but if we hit b we expect to select abcd, so we need to getRight() on the
* start of the selection when it precedes where we started visual mode.
*/

if (start.compareTo(stop) > 0) {
start = start.getRight();
}

selections = [ new vscode.Selection(start, stop) ];
} else if (vimState.currentMode === ModeName.VisualLine) {
selections = [ new vscode.Selection(
Expand All @@ -1294,7 +1289,11 @@ export class ModeHandler implements vscode.Disposable {
if (vimState.currentMode === ModeName.Visual) {
selections = [];

for (const { start: cursorStart, stop: cursorStop } of vimState.allCursors) {
for (let { start: cursorStart, stop: cursorStop } of vimState.allCursors) {
if (cursorStart.compareTo(cursorStop) > 0) {
cursorStart = cursorStart.getRight();
}

selections.push(new vscode.Selection(cursorStart, cursorStop));
}
} else if (vimState.currentMode === ModeName.Normal ||
Expand Down Expand Up @@ -1353,7 +1352,9 @@ export class ModeHandler implements vscode.Disposable {
// Fake block cursor with text decoration. Unfortunately we can't have a cursor
// in the middle of a selection natively, which is what we need for Visual Mode.

rangesToDraw.push(new vscode.Range(stop, stop.getRight()));
for (const { stop: cursorStop } of vimState.allCursors) {
rangesToDraw.push(new vscode.Range(cursorStop, cursorStop.getRight()));
}
}

// Draw marks
Expand Down