Skip to content

Commit

Permalink
Merge pull request #237 from VSCodeVim/dd-cc-yy-tests
Browse files Browse the repository at this point in the history
dd, cc & yy tests
  • Loading branch information
johnfn committed Jun 5, 2016
2 parents a6456da + 7e42166 commit 47e4e82
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 11 deletions.
17 changes: 15 additions & 2 deletions src/actions/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ export class DeleteOperator extends BaseOperator {
end = new Position(end.line, end.character + 1);
}

// TODO: This is a hack.
if (end.character === TextEditor.getLineAt(end).text.length) {
end = end.getDown(0);
}

// Imagine we have selected everything with an X in
// the following text (there is no character on the
// second line at all, just a block cursor):
Expand Down Expand Up @@ -805,8 +810,16 @@ class MoveDD extends BaseMovement {
key = "d";

public async execAction(position: Position, vimState: VimState): Promise<VimState> {
vimState.cursorStartPosition = position.getLineBegin();
vimState.cursorPosition = position.getNextLineBegin();
let start = position.getLineBegin();
let stop = position.getLineEnd();

if (start.line === TextEditor.getLineCount() - 1 && start.line > 0) {
start = position.getPreviousLineBegin().getLineEnd();
stop = position.getLineEnd();
}

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

return vimState;
}
Expand Down
11 changes: 3 additions & 8 deletions src/mode/modeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,19 +182,12 @@ export class ActionState {
}

export class ModeHandler implements vscode.Disposable {
private __motion: Motion;
private _motion: Motion;
private _modes: Mode[];
private _statusBarItem: vscode.StatusBarItem;
private _configuration: Configuration;
private _vimState: VimState;

private get _motion(): Motion {
return this.__motion;
}
private set _motion(m: Motion) {
this.__motion = m;
}

private get currentModeName(): ModeName {
return this.currentMode.name;
}
Expand Down Expand Up @@ -368,6 +361,8 @@ export class ModeHandler implements vscode.Disposable {
return;
}

// TODO: Draw cursor and/or selection.

// Updated desired column

const movement = actionState.movement, command = actionState.command;
Expand Down
13 changes: 12 additions & 1 deletion src/motion/position.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,22 @@ export class Position extends vscode.Position {
return new Position(this.line, 0);
}

/**
* Get the beginning of the next line.
*/
public getPreviousLineBegin(): Position {
if (this.line === 0) {
return this.getLineBegin();
}

return new Position(this.line - 1, 0);
}

/**
* Get the beginning of the next line.
*/
public getNextLineBegin(): Position {
if (this.line >= TextEditor.getLineCount()) {
if (this.line >= TextEditor.getLineCount() - 1) {
return this.getLineEnd();
}

Expand Down
51 changes: 51 additions & 0 deletions test/mode/modeNormal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,57 @@ suite("Mode Normal", () => {
await assertEqualLines(["text"]);
});

test("Can handle dd end-of-line", async () => {
await modeHandler.handleMultipleKeyEvents("ione\ntwo".split(""));
await modeHandler.handleMultipleKeyEvents([
'<esc>', '^',
'd', 'd'
]);

assertEqualLines(["one"]);
});

test("Can handle dd single line", async () => {
await modeHandler.handleMultipleKeyEvents("ione".split(""));
await modeHandler.handleMultipleKeyEvents([
'<esc>',
'd', 'd'
]);

assertEqualLines([""]);
});

test("Can handle dd", async () => {
await modeHandler.handleMultipleKeyEvents("ione\ntwo".split(""));
await modeHandler.handleMultipleKeyEvents([
'<esc>', 'g', 'g',
'd', 'd'
]);

assertEqualLines(["two"]);
});

test("Can handle cc", async () => {
await modeHandler.handleMultipleKeyEvents("ione\none two".split(""));
await modeHandler.handleMultipleKeyEvents([
'<esc>', '^',
'c', 'c', 'a', '<esc>'
]);

assertEqualLines(["one", "a"]);
});


test("Can handle yy", async () => {
await modeHandler.handleMultipleKeyEvents("ione".split(""));
await modeHandler.handleMultipleKeyEvents([
'<esc>', '^',
'y', 'y', 'O', '<esc>', 'p'
]);

assertEqualLines(["one", "one"]);
});

test("Can handle 'de'", async () => {
await modeHandler.handleMultipleKeyEvents(
'itext text'.split('')
Expand Down

0 comments on commit 47e4e82

Please sign in to comment.