Incomplete implementation of :hist

Covers 90% of use cases, and I don't think many people use this anyway
Fixes #3949
This commit is contained in:
Jason Fields 2019-09-28 00:25:23 -04:00
parent 2f2ff1303d
commit 72554fad89
4 changed files with 96 additions and 14 deletions

View File

@ -665,10 +665,9 @@ abstract class CommandEditorScroll extends BaseCommand {
by: this.by,
value: timesToRepeat,
revealCursor: true,
select:
[ModeName.Visual, ModeName.VisualBlock, ModeName.VisualLine].includes(
vimState.currentMode
),
select: [ModeName.Visual, ModeName.VisualBlock, ModeName.VisualLine].includes(
vimState.currentMode
),
},
});
return vimState;
@ -724,10 +723,9 @@ class CommandMoveHalfPageDown extends CommandEditorScroll {
by: this.by,
value: timesToRepeat,
revealCursor: smoothScrolling,
select:
[ModeName.Visual, ModeName.VisualBlock, ModeName.VisualLine].includes(
vimState.currentMode
),
select: [ModeName.Visual, ModeName.VisualBlock, ModeName.VisualLine].includes(
vimState.currentMode
),
});
let newPosition: Position;
@ -778,10 +776,9 @@ class CommandMoveHalfPageUp extends CommandEditorScroll {
by: this.by,
value: timesToRepeat,
revealCursor: smoothScrolling,
select:
[ModeName.Visual, ModeName.VisualBlock, ModeName.VisualLine].includes(
vimState.currentMode
),
select: [ModeName.Visual, ModeName.VisualBlock, ModeName.VisualLine].includes(
vimState.currentMode
),
});
let newPosition: Position;
@ -2261,7 +2258,7 @@ class CommandPasteInCommandline extends BaseCommand {
}
@RegisterAction
class CommandShowCommandHistory extends BaseCommand {
export class CommandShowCommandHistory extends BaseCommand {
modes = [ModeName.Normal, ModeName.Visual, ModeName.VisualLine, ModeName.VisualBlock];
keys = ['q', ':'];
@ -2286,7 +2283,7 @@ class CommandShowCommandHistory extends BaseCommand {
}
@RegisterAction
class CommandShowSearchHistory extends BaseCommand {
export class CommandShowSearchHistory extends BaseCommand {
modes = [ModeName.Normal, ModeName.Visual, ModeName.VisualLine, ModeName.VisualBlock];
keys = [['q', '/'], ['q', '?']];

View File

@ -0,0 +1,61 @@
import { CommandBase, ICommandArgs } from '../node';
import { VimState } from '../../state/vimState';
import { globalState } from '../../state/globalState';
import {
CommandShowSearchHistory,
CommandShowCommandHistory,
} from '../../actions/commands/actions';
import { SearchDirection } from '../../state/searchState';
export enum HistoryCommandType {
Cmd,
Search,
Expr,
Input,
Debug,
All,
}
export interface IHistoryCommandArguments extends ICommandArgs {
type: HistoryCommandType;
// TODO: :history can accept multiple types
// TODO: :history can also accept a range
}
// http://vimdoc.sourceforge.net/htmldoc/cmdline.html#:history
export class HistoryCommand extends CommandBase {
protected _arguments: IHistoryCommandArguments;
constructor(args: IHistoryCommandArguments) {
super();
this._name = 'history';
this._arguments = args;
}
get arguments(): IHistoryCommandArguments {
return this._arguments;
}
async execute(vimState: VimState): Promise<void> {
switch (this._arguments.type) {
case HistoryCommandType.Cmd:
await new CommandShowCommandHistory().exec(vimState.cursorStopPosition, vimState);
break;
case HistoryCommandType.Search:
await new CommandShowSearchHistory(SearchDirection.Forward).exec(
vimState.cursorStopPosition,
vimState
);
break;
// TODO: Implement these
case HistoryCommandType.Expr:
throw new Error("Not implemented");
case HistoryCommandType.Input:
throw new Error("Not implemented");
case HistoryCommandType.Debug:
throw new Error("Not implemented");
case HistoryCommandType.All:
throw new Error("Not implemented");
}
}
}

View File

@ -19,6 +19,7 @@ import { parseFileInfoCommandArgs } from './subparsers/fileInfo';
import { parseMarksCommandArgs } from './subparsers/marks';
import { parseSmileCommandArgs } from './subparsers/smile';
import { CommandBase } from './node';
import { parseHistoryCommandArgs } from './subparsers/history';
// Associates a name and an abbreviation with a command parser
export type CommandParserMapping = {
@ -219,6 +220,11 @@ export const commandParsers = {
marks: {
parser: parseMarksCommandArgs,
},
history: {
abbrev: 'his',
parser: parseHistoryCommandArgs,
},
};
/**

View File

@ -0,0 +1,18 @@
import { HistoryCommand, HistoryCommandType, IHistoryCommandArguments } from '../commands/history';
import { Scanner } from '../scanner';
export function parseHistoryCommandArgs(input?: string): HistoryCommand {
const args: IHistoryCommandArguments = { type: HistoryCommandType.Cmd };
if (input) {
const scanner = new Scanner(input);
scanner.skipWhiteSpace();
const type = scanner.nextWord();
if (type === '/' || (type.startsWith('s') && 'search'.startsWith(type))) {
args.type = HistoryCommandType.Search;
}
}
return new HistoryCommand(args);
}