Register info (#756)

* show the content of registers

* update roadmap for register

* make tslint happy
This commit is contained in:
Peng Lyu 2016-09-13 07:51:58 -07:00 committed by GitHub
parent e5592e5c9e
commit 436166d55c
5 changed files with 73 additions and 3 deletions

View File

@ -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

View File

@ -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);
});
}
}
}

View File

@ -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 = {
@ -58,5 +59,7 @@ export const commandParsers = {
vnew: fileCmd.parseEditNewFileInNewWindowCommandArgs,
set: parseOptionsCommandArgs,
se: parseOptionsCommandArgs
se: parseOptionsCommandArgs,
reg: parseRegisterCommandArgs
};

View File

@ -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
});
}

View File

@ -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}`);
}
@ -89,4 +92,8 @@ export class Register {
return Register.registers[register];
}
public static getKeys(): string[] {
return Object.keys(Register.registers);
}
}