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

J #251

Merged
merged 2 commits into from
Jun 8, 2016
Merged

J #251

Show file tree
Hide file tree
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
37 changes: 35 additions & 2 deletions src/actions/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,39 @@ class ActionDeleteLastChar extends BaseCommand {
}
}


@RegisterAction
class ActionJoin extends BaseCommand {
modes = [ModeName.Normal];
keys = ["J"];

public async exec(position: Position, vimState: VimState): Promise<VimState> {
if (position.line === TextEditor.getLineCount() - 1) {
return vimState; // TODO: bell
}

// TODO(whitespace): need a better way to check for whitespace
const char = TextEditor.getLineAt(position.getNextLineBegin()).text[0];
const nextLineStartsWithWhitespace =
char === ' ' || char === '\t';

const positionToDeleteTo =
nextLineStartsWithWhitespace ?
position.getNextLineBegin().getFirstLineNonBlankChar().getLeft().getLeft() :
position.getLineEnd();

if (!nextLineStartsWithWhitespace) {
await TextEditor.insertAt(" ", position.getNextLineBegin());
}

return await new DeleteOperator().run(
vimState,
position.getLineEnd(),
positionToDeleteTo
);
}
}

@RegisterAction
class MoveDD extends BaseMovement {
modes = [ModeName.Normal];
Expand Down Expand Up @@ -1096,7 +1129,7 @@ class MovementAWordTextObject extends BaseMovement {

const currentChar = TextEditor.getLineAt(position).text[position.character];

// TODO - this is a bad way to do this. we need some sort of global
// TODO(whitespace) - this is a bad way to do this. we need some sort of global
// white space checking function.
if (currentChar === ' ' || currentChar === '\t') {
vimState.cursorStartPosition = position.getLastWordEnd().getRight();
Expand Down Expand Up @@ -1132,7 +1165,7 @@ class MovementIWordTextObject extends BaseMovement {

const currentChar = TextEditor.getLineAt(position).text[position.character];

// TODO - this is a bad way to do this. we need some sort of global
// TODO(whitespace) - this is a bad way to do this. we need some sort of global
// white space checking function.
if (currentChar === ' ' || currentChar === '\t') {
vimState.cursorStartPosition = position.getLastWordEnd().getRight();
Expand Down
21 changes: 14 additions & 7 deletions src/mode/modeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,16 @@ export class VimState {
*/
public desiredColumn = 0;

public oldDotKeys = [];
/**
* The keystroke sequence that made up our last complete action (that can be
* repeated with '.').
*/
public previousFullAction = [];

public dotKeys = [];
/**
* The current full action we are building up.
*/
public currentFullAction = [];

/**
* The position the cursor will be when this action finishes.
Expand Down Expand Up @@ -302,7 +309,7 @@ export class ModeHandler implements vscode.Disposable {
let actionState = vimState.actionState;

actionState.actionKeys.push(key);
vimState.dotKeys.push(key);
vimState.currentFullAction.push(key);

let action = Actions.getRelevantAction(actionState.actionKeys, vimState);

Expand Down Expand Up @@ -361,11 +368,11 @@ export class ModeHandler implements vscode.Disposable {
// Update dot keys

if (vimState.isFullDotAction()) {
vimState.oldDotKeys = vimState.dotKeys;
vimState.previousFullAction = vimState.currentFullAction;
}

if (vimState.shouldResetCurrentDotKeys()) {
vimState.dotKeys = [];
vimState.currentFullAction = [];
}

vimState.actionState = new ActionState(vimState);
Expand Down Expand Up @@ -432,10 +439,10 @@ export class ModeHandler implements vscode.Disposable {
case VimCommandActions.MoveFullPageDown: await vscode.commands.executeCommand("cursorPageUp"); break;
case VimCommandActions.MoveFullPageUp: await vscode.commands.executeCommand("cursorPageDown"); break;
case VimCommandActions.Dot:
const oldDotKeysCopy = vimState.oldDotKeys.slice(0);
const oldDotKeysCopy = vimState.previousFullAction.slice(0);

vimState.actionState = new ActionState(vimState);
vimState.dotKeys = [];
vimState.currentFullAction = [];

for (let key of oldDotKeysCopy) {
vimState = await this.handleKeyEventHelper(key, vimState);
Expand Down