Skip to content

Commit

Permalink
Merge branch 'master' into cobbweb/more-readme-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jpoon authored May 10, 2017
2 parents adc5a2a + f373319 commit dc18a81
Show file tree
Hide file tree
Showing 26 changed files with 265 additions and 93 deletions.
13 changes: 5 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ sudo: false
os:
- linux

addons:
apt:
packages:

language: node_js

node_js:
Expand All @@ -22,18 +18,19 @@ env:
before_install:
- if [ $TRAVIS_OS_NAME == "linux" ]; then
export CXX="g++-4.9" CC="gcc-4.9" DISPLAY=:99.0;
sh -e /etc/init.d/xvfb start; sleep 3;
sh -e /etc/init.d/xvfb start;
sleep 3;
fi

install:
- npm install -g gulp;
- npm install;

script:
- npm install -g gulp;
- gulp;
- gulp
- npm test --silent;

after_success:
before_deploy:
- npm install -g vsce;
- vsce package;

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "Vim",
"description": "Vim emulation for Visual Studio Code",
"icon": "images/icon.png",
"version": "0.7.0",
"version": "0.7.1",
"publisher": "vscodevim",
"galleryBanner": {
"color": "#e3f4ff",
Expand Down Expand Up @@ -88,7 +88,7 @@
{
"key": "ctrl+d",
"command": "extension.vim_ctrl+d",
"when": "editorTextFocus && vim.active && vim.use<C-d> && !inDebugRepl"
"when": "editorTextFocus && vim.active && !inDebugRepl"
},
{
"key": "ctrl+alt+down",
Expand Down Expand Up @@ -232,7 +232,7 @@
{
"key": "cmd+c",
"command": "extension.vim_cmd+c",
"when": "editorTextFocus && vvim.active && im.use<D-c> && vim.overrideCopy && !inDebugRepl"
"when": "editorTextFocus && vim.active && vim.use<D-c> && vim.overrideCopy && !inDebugRepl"
},
{
"key": "ctrl+a",
Expand Down
72 changes: 66 additions & 6 deletions src/actions/commands/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1348,14 +1348,20 @@ export class PutCommandVisual extends BaseCommand {
public async exec(position: Position, vimState: VimState, after: boolean = false): Promise<VimState> {
let start = vimState.cursorStartPosition;
let end = vimState.cursorPosition;

const isLineWise = vimState.currentMode === ModeName.VisualLine;
if (start.isAfter(end)) {
[start, end] = [end, start];
}
// The reason we need to handle Delete and Yank separately is because of
// linewise mode. If we're in visualLine mode, then we want to copy
// linewise but not necessarily delete linewise.
let result = await new PutCommand().exec(start, vimState, true);
result.currentRegisterMode = isLineWise ? RegisterMode.LineWise : RegisterMode.CharacterWise;
result = await new operator.YankOperator(this.multicursorIndex).run(result, start, end);
result.currentRegisterMode = RegisterMode.CharacterWise;
result = await new operator.DeleteOperator(this.multicursorIndex).run(result, start, end.getLeftIfEOL(), false);
return result;

const result = await new operator.DeleteOperator(this.multicursorIndex).run(vimState, start, end, false);

return await new PutCommand().exec(start, result, true);
}

// TODO - execWithCount
Expand Down Expand Up @@ -2104,6 +2110,36 @@ class MoveToRightPane extends BaseCommand {
}
}

@RegisterAction
class MoveToLowerPane extends BaseCommand {
modes = [ModeName.Normal, ModeName.Visual, ModeName.VisualLine];
keys = [["<C-w>", "j"], ["<C-w>", "<down>"], ["<C-w j>"]];

public async exec(position: Position, vimState: VimState): Promise<VimState> {
vimState.postponedCodeViewChanges.push({
command: "workbench.action.navigateDown",
args: {}
});

return vimState;
}
}

@RegisterAction
class MoveToUpperPane extends BaseCommand {
modes = [ModeName.Normal, ModeName.Visual, ModeName.VisualLine];
keys = [["<C-w>", "k"], ["<C-w>", "<up>"], ["<C-w k>"]];

public async exec(position: Position, vimState: VimState): Promise<VimState> {
vimState.postponedCodeViewChanges.push({
command: "workbench.action.navigateUp",
args: {}
});

return vimState;
}
}

@RegisterAction
class MoveToLeftPane extends BaseCommand {
modes = [ModeName.Normal, ModeName.Visual, ModeName.VisualLine];
Expand All @@ -2119,14 +2155,15 @@ class MoveToLeftPane extends BaseCommand {
}
}


@RegisterAction
class CycleThroughPanes extends BaseCommand {
modes = [ModeName.Normal, ModeName.Visual, ModeName.VisualLine];
keys = ["<C-w>", "<C-w>"];
keys = [["<C-w>", "<C-w>"], ["<C-w>", "w"]];

public async exec(position: Position, vimState: VimState): Promise<VimState> {
vimState.postponedCodeViewChanges.push({
command: "workbench.action.navigateRight",
command: "workbench.action.navigateEditorGroups",
args: {}
});

Expand Down Expand Up @@ -3317,6 +3354,29 @@ class ActionOverrideCmdD extends BaseCommand {
}
}

@RegisterAction
class ActionOverrideCmdDInsert extends BaseCommand {
modes = [ModeName.Insert];
keys = ["<D-d>"];
runsOnceForEveryCursor() { return false; }
runsOnceForEachCountPrefix = true;

public async exec(position: Position, vimState: VimState): Promise<VimState> {
// Since editor.action.addSelectionToNextFindMatch uses the selection to
// determine where to add a word, we need to do a hack and manually set the
// selections to the word boundaries before we make the api call.
vscode.window.activeTextEditor!.selections =
vscode.window.activeTextEditor!.selections.map(x => {
const curPos = Position.FromVSCodePosition(x.active);
return new vscode.Selection(curPos.getWordLeft(true),
curPos.getLeft().getCurrentWordEnd(true).getRight());
});
await vscode.commands.executeCommand('editor.action.addSelectionToNextFindMatch');
vimState.allCursors = await allowVSCodeToPropagateCursorUpdatesAndReturnThem();
return vimState;
}
}

@RegisterAction
class ActionOverrideCmdAltDown extends BaseCommand {
modes = [ModeName.Normal, ModeName.Visual];
Expand Down
45 changes: 45 additions & 0 deletions src/cmd_line/commands/close.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"use strict";

import * as vscode from "vscode";
import * as node from "../node";
import * as error from '../../error';

export interface ICloseCommandArguments extends node.ICommandArgs {
bang?: boolean;
range?: node.LineRange;
quitAll?: boolean;
}

//
// Implements :close
// http://vimdoc.sourceforge.net/htmldoc/windows.html#:close
//
export class CloseCommand extends node.CommandBase {
protected _arguments : ICloseCommandArguments;

constructor(args : ICloseCommandArguments) {
super();
this._name = 'close';
this._arguments = args;
}

get arguments() : ICloseCommandArguments {
return this._arguments;
}

async execute() : Promise<void> {
if (this.activeTextEditor!.document.isDirty && !this.arguments.bang) {
throw error.VimError.fromCode(error.ErrorCode.E37);
}

if (vscode.window.visibleTextEditors.length === 1) {
throw error.VimError.fromCode(error.ErrorCode.E444);
}

let oldViewColumn = this.activeTextEditor!.viewColumn;
await vscode.commands.executeCommand('workbench.action.closeActiveEditor');

if (vscode.window.activeTextEditor !== undefined && vscode.window.activeTextEditor.viewColumn === oldViewColumn) {
await vscode.commands.executeCommand('workbench.action.previousEditor');
}
}}
6 changes: 3 additions & 3 deletions src/cmd_line/commands/tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@ export class TabCommand extends node.CommandBase {
case Tab.Next:
if (this._arguments.count /** not undefined or 0 */) {
vscode.commands.executeCommand("workbench.action.openEditorAtIndex1");
this.executeCommandWithCount(this._arguments.count! - 1, "workbench.action.nextEditor");
this.executeCommandWithCount(this._arguments.count! - 1, "workbench.action.nextEditorInGroup");
} else {
this.executeCommandWithCount(1, "workbench.action.nextEditor");
this.executeCommandWithCount(1, "workbench.action.nextEditorInGroup");
}
break;
case Tab.Previous:
if (this._arguments.count !== undefined && this._arguments.count <= 0) {
break;
}

this.executeCommandWithCount(this._arguments.count || 1, "workbench.action.previousEditor");
this.executeCommandWithCount(this._arguments.count || 1, "workbench.action.previousEditorInGroup");
break;
case Tab.First:
this.executeCommandWithCount(1, "workbench.action.openEditorAtIndex1");
Expand Down
4 changes: 4 additions & 0 deletions src/cmd_line/subparser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { parseReadCommandArgs } from './subparsers/read';
import { parseRegisterCommandArgs } from './subparsers/register';
import { parseDeleteRangeLinesCommandArgs } from './subparsers/deleteRange';
import { parseSortCommandArgs } from './subparsers/sort';
import { parseCloseCommandArgs } from './subparsers/close';

// maps command names to parsers for said commands.
export const commandParsers = {
Expand All @@ -27,6 +28,9 @@ export const commandParsers = {
noh: parseNohlCommandArgs,
nohl: parseNohlCommandArgs,

close: parseCloseCommandArgs,
clo: parseCloseCommandArgs,

quit: parseQuitCommandArgs,
q: parseQuitCommandArgs,

Expand Down
25 changes: 25 additions & 0 deletions src/cmd_line/subparsers/close.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"use strict";

import * as node from "../commands/close";
import {Scanner} from '../scanner';
import {VimError, ErrorCode} from '../../error';

export function parseCloseCommandArgs(args : string) : node.CloseCommand {
if (!args) {
return new node.CloseCommand({});
}
var scannedArgs : node.ICloseCommandArguments = {};
var scanner = new Scanner(args);
const c = scanner.next();
if (c === '!') {
scannedArgs.bang = true;
scanner.ignore();
} else if (c !== ' ') {
throw VimError.fromCode(ErrorCode.E488);
}
scanner.skipWhiteSpace();
if (!scanner.isAtEof) {
throw VimError.fromCode(ErrorCode.E488);
}
return new node.CloseCommand(scannedArgs);
}
12 changes: 7 additions & 5 deletions src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,25 @@

import * as util from "./util";

interface IVimErrors {
interface IErrorMessage {
[index: number] : string;
}

export enum ErrorCode {
E37 = 37,
E32 = 32,
E37 = 37,
E208 = 208,
E348 = 348,
E444 = 444,
E488 = 488
}

const errors : IVimErrors = {
export const ErrorMessage : IErrorMessage = {
32: "No file name",
37: "No write since last change (add ! to override)",
208: "Error writing to file",
348: "No string under cursor",
444: "Cannot close last window",
488: "Trailing characters"
};

Expand All @@ -33,8 +35,8 @@ export class VimError extends Error {
}

static fromCode(code : ErrorCode) : VimError {
if (errors[code]) {
return new VimError(code, errors[code]);
if (ErrorMessage[code]) {
return new VimError(code, ErrorMessage[code]);
}

throw new Error("unknown error code: " + code);
Expand Down
4 changes: 3 additions & 1 deletion src/mode/modeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,9 @@ export class ModeHandler implements vscode.Disposable {
key = "<copy>";
}
}

if (key === "<C-d>" && !Configuration.useCtrlKeys) {
key = "<D-d>";
}
this._vimState.cursorPositionJustBeforeAnythingHappened = this._vimState.allCursors.map(x => x.stop);
this._vimState.recordedState.commandList.push(key);

Expand Down
1 change: 0 additions & 1 deletion test/cmd_line/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ suite("command-line parser", () => {
assert.ok(cmd.isEmpty);
});

// TODO: Range tests follow -- should prolly create a suite for this
test("can parse left - dot", () => {
var cmd : node.CommandLine = parser.parse(".");
assert.equal(cmd.range.left[0].type, token.TokenType.Dot);
Expand Down
5 changes: 3 additions & 2 deletions test/cmd_line/read.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import { runCmdLine } from '../../src/cmd_line/main';
suite("read", () => {
let modeHandler: ModeHandler;

setup(async () => {
suiteSetup(async () => {
await setupWorkspace();
modeHandler = new ModeHandler();
});

teardown(cleanUpWorkspace);
suiteTeardown(cleanUpWorkspace);

test("Can read shell command output", async () => {
await runCmdLine('r! echo hey\\\\n\\\\tho', modeHandler);
Expand All @@ -22,4 +22,5 @@ suite("read", () => {
''
]);
});

});
Loading

0 comments on commit dc18a81

Please sign in to comment.