Skip to content

Commit

Permalink
Merge pull request #262 from VSCodeVim/paste-before
Browse files Browse the repository at this point in the history
Add P.
  • Loading branch information
johnfn committed Jun 9, 2016
2 parents 04b08bf + 0525ae8 commit 710ced7
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/actions/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,18 +315,19 @@ export class PutCommand extends BaseCommand {
public keys = ["p"];
public modes = [ModeName.Normal, ModeName.Visual, ModeName.VisualLine];

/**
* Run this operator on a range.
*/
public async exec(position: Position, vimState: VimState): Promise<VimState> {
public async exec(position: Position, vimState: VimState, before: boolean = false): Promise<VimState> {
const register = Register.get(vimState);
const text = register.text;
const dest = position.getRight();
const dest = before ? position : position.getRight();

if (register.registerMode === RegisterMode.CharacterWise) {
await TextEditor.insertAt(text, dest);
} else {
await TextEditor.insertAt("\n" + text, dest.getLineEnd());
if (before) {
await TextEditor.insertAt(text + "\n", dest.getLineBegin());
} else {
await TextEditor.insertAt("\n" + text, dest.getLineEnd());
}
}

// More vim weirdness: If the thing you're pasting has a newline, the cursor
Expand All @@ -346,6 +347,17 @@ export class PutCommand extends BaseCommand {
}
}


@RegisterAction
export class PutBeforeCommand extends BaseCommand {
public keys = ["P"];
public modes = [ModeName.Normal];

public async exec(position: Position, vimState: VimState): Promise<VimState> {
return await new PutCommand().exec(position, vimState, true);
}
}

@RegisterAction
class CommandShowCommandLine extends BaseCommand {
modes = [ModeName.Normal];
Expand Down

0 comments on commit 710ced7

Please sign in to comment.