Skip to content

Commit

Permalink
Draw multicursor correctly in Visual Mode (#920)
Browse files Browse the repository at this point in the history
* draw multicursor block when in visual mode

* fixed mulitcursor selection drawing
  • Loading branch information
Platzer authored and johnfn committed Oct 14, 2016
1 parent 3a3bbae commit 5d9f2b0
Showing 1 changed file with 27 additions and 26 deletions.
53 changes: 27 additions & 26 deletions src/mode/modeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1241,37 +1241,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 @@ -1296,7 +1291,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 @@ -1355,7 +1354,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

0 comments on commit 5d9f2b0

Please sign in to comment.