Skip to content

Commit

Permalink
Register info (#756)
Browse files Browse the repository at this point in the history
* show the content of registers

* update roadmap for register

* make tslint happy
  • Loading branch information
rebornix authored Sep 13, 2016
1 parent e5592e5 commit 436166d
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 3 deletions.
4 changes: 2 additions & 2 deletions ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@ Status | Command | Description | Note
---|--------|-------------|-----------------
:running: | "{char} | use register {char} for the next delete, yank, or put | read only registers are not supported yet
:white_check_mark: | "* | use register `*` to access system clipboard
| :reg | show the contents of all registers
| :reg {arg} | show the contents of registers mentioned in {arg}
:white_check_mark: | :reg | show the contents of all registers
:white_check_mark: | :reg {arg} | show the contents of registers mentioned in {arg}
:white_check_mark: | :1234: y{motion} | yank the text moved over with {motion} into a register
:white_check_mark: | {visual}y | yank the highlighted text into a register
:white_check_mark: | :1234: yy | yank N lines into a register
Expand Down
43 changes: 43 additions & 0 deletions src/cmd_line/commands/register.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"use strict";

import * as vscode from "vscode";
import * as node from "../node";
import {ModeHandler} from "../../mode/modeHandler";
import { Register} from '../../register/register';

export interface IRegisterCommandArguments extends node.ICommandArgs {
arg?: string;
}

export class RegisterCommand extends node.CommandBase {
protected _arguments : IRegisterCommandArguments;

constructor(args : IRegisterCommandArguments) {
super();
this._name = 'register';
this._shortName = 'reg';
this._arguments = args;
}

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

async displayRegisterValue(register: string): Promise<void> {
let result = (await Register.getByKey(register)).text;
if (result instanceof Array) {
result = result.join("\n").substr(0, 100);
}
vscode.window.showInformationMessage(`${register} ${result}`);
}

async execute(modeHandler: ModeHandler): Promise<void> {
if (this.arguments.arg !== undefined && this.arguments.arg.length > 0) {
await this.displayRegisterValue(this.arguments.arg);
} else {
vscode.window.showQuickPick(Register.getKeys()).then(async (val) => {
await this.displayRegisterValue(val);
});
}
}
}
5 changes: 4 additions & 1 deletion src/cmd_line/subparser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as tabCmd from './subparsers/tab';
import * as fileCmd from './subparsers/file';
import {parseOptionsCommandArgs} from './subparsers/setoptions';
import {parseSubstituteCommandArgs} from './subparsers/substitute';
import {parseRegisterCommandArgs} from './subparsers/register';

// maps command names to parsers for said commands.
export const commandParsers = {
Expand Down Expand Up @@ -58,5 +59,7 @@ export const commandParsers = {
vnew: fileCmd.parseEditNewFileInNewWindowCommandArgs,

set: parseOptionsCommandArgs,
se: parseOptionsCommandArgs
se: parseOptionsCommandArgs,

reg: parseRegisterCommandArgs
};
17 changes: 17 additions & 0 deletions src/cmd_line/subparsers/register.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"use strict";

import * as node from "../commands/register";
import {Scanner} from '../scanner';

export function parseRegisterCommandArgs(args: string): node.RegisterCommand {
if (!args) {
return new node.RegisterCommand({});
}

let scanner = new Scanner(args);
let name = scanner.nextWord();

return new node.RegisterCommand({
arg: name
});
}
7 changes: 7 additions & 0 deletions src/register/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ export class Register {
*/
public static async get(vimState: VimState): Promise<IRegisterContent> {
const register = vimState.recordedState.registerName;
return Register.getByKey(register);
}

public static async getByKey(register: string): Promise<IRegisterContent> {
if (!Register.isValidRegister(register)) {
throw new Error(`Invalid register ${register}`);
}
Expand All @@ -89,4 +92,8 @@ export class Register {

return Register.registers[register];
}

public static getKeys(): string[] {
return Object.keys(Register.registers);
}
}

0 comments on commit 436166d

Please sign in to comment.