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

Add cc/yy/dd. #236

Merged
merged 1 commit into from
Jun 5, 2016
Merged
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
Add cc/yy/dd.
  • Loading branch information
johnfn committed Jun 5, 2016
commit d6dc6cc62c89f60927017ff59ceb8182c26f6e70
46 changes: 44 additions & 2 deletions src/actions/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ export class BaseAction {
if (this.modes.indexOf(vimState.currentMode) === -1) { return false; }
if (this.key !== key) { return false; }
// TODO - this is not exactly correct and will eventually make me rage
// It's for cases like daw where a would otherwise by treated as append and insert.
if (this instanceof BaseCommand && !vimState.actionState.isInInitialState) { return false; }
if (this instanceof BaseOperator && vimState.actionState.operator) { return false; }

return true;
}
Expand All @@ -35,6 +37,7 @@ export class BaseAction {
if (this.modes.indexOf(vimState.currentMode) === -1) { return false; }
if (!this.key.startsWith(key)) { return false; }
if (this instanceof BaseCommand && !vimState.actionState.isInInitialState) { return false; }
if (this instanceof BaseOperator && vimState.actionState.operator) { return false; }

return true;
}
Expand All @@ -56,7 +59,7 @@ export abstract class BaseMovement extends BaseAction {
public setsDesiredColumnToEOL = false;

/**
* Run the action.
* Run the movement.
*/
public abstract async execAction(position: Position, vimState: VimState): Promise<VimState>;

Expand Down Expand Up @@ -228,7 +231,7 @@ export class PutCommand extends BaseCommand {

@RegisterAction
export class YankOperator extends BaseOperator {
public key: string = "y";
public key = "y";
public modes = [ModeName.Normal, ModeName.Visual, ModeName.VisualLine];

/**
Expand Down Expand Up @@ -796,6 +799,45 @@ class ActionDeleteLastChar extends BaseCommand {
}
}

@RegisterAction
class MoveDD extends BaseMovement {
modes = [ModeName.Normal];
key = "d";

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

return vimState;
}
}

@RegisterAction
class MoveYY extends BaseMovement {
modes = [ModeName.Normal];
key = "y";

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

return vimState;
}
}

@RegisterAction
class MoveCC extends BaseMovement {
modes = [ModeName.Normal];
key = "c";

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

return vimState;
}
}

@RegisterAction
class ActionDeleteLineVisualMode extends BaseCommand {
modes = [ModeName.Visual];
Expand Down
16 changes: 15 additions & 1 deletion src/motion/position.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,24 @@ export class Position extends vscode.Position {
return pos.getLineBegin();
}

public getLineBegin() : Position {
/**
* Get the beginning of the current line.
*/
public getLineBegin(): Position {
return new Position(this.line, 0);
}

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

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

/**
* Returns a new position at the end of this position's line.
*/
Expand Down