mirror of
https://github.com/microsoft/vscode-extension-samples.git
synced 2026-04-27 16:55:44 +08:00
Normalize the vim sample
This commit is contained in:
@ -4,7 +4,6 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import { MotionState, Motion } from './motions';
|
||||
|
||||
export enum Mode {
|
||||
@ -14,9 +13,9 @@ export enum Mode {
|
||||
}
|
||||
|
||||
export interface ModifierKeys {
|
||||
ctrl?: boolean,
|
||||
alt?: boolean,
|
||||
shifit?: boolean
|
||||
ctrl?: boolean;
|
||||
alt?: boolean;
|
||||
shifit?: boolean;
|
||||
}
|
||||
|
||||
export class DeleteRegister {
|
||||
@ -48,6 +47,6 @@ export abstract class AbstractCommandDescriptor {
|
||||
}
|
||||
|
||||
export interface Command {
|
||||
commandId: string,
|
||||
args?: any[]
|
||||
commandId: string;
|
||||
args?: any[];
|
||||
}
|
||||
|
||||
@ -4,15 +4,7 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import {
|
||||
TextEditorCursorStyle,
|
||||
Position,
|
||||
Range,
|
||||
Selection,
|
||||
TextEditor,
|
||||
TextEditorRevealType,
|
||||
window
|
||||
} from 'vscode';
|
||||
import { TextEditorCursorStyle, Position, Range, Selection, TextEditor, TextEditorRevealType, window } from 'vscode';
|
||||
|
||||
import { Words } from './words';
|
||||
import { MotionState, Motion } from './motions';
|
||||
|
||||
@ -6,11 +6,7 @@
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
import { Words } from './words';
|
||||
import { MotionState, Motion, Motions } from './motions';
|
||||
import { Operator, Operators } from './operators';
|
||||
import { Mode, IController, ModifierKeys } from './common';
|
||||
import { Mappings } from './mappings';
|
||||
import { Mode, ModifierKeys } from './common';
|
||||
import { Controller } from './controller';
|
||||
|
||||
export function activate(context: vscode.ExtensionContext) {
|
||||
@ -95,7 +91,7 @@ class VimExt {
|
||||
this._hasInput = new ContextKey('vim.hasInput');
|
||||
this._statusBar = new StatusBar();
|
||||
|
||||
this._controller = new Controller()
|
||||
this._controller = new Controller();
|
||||
|
||||
vscode.window.onDidChangeActiveTextEditor((textEditor) => {
|
||||
if (!textEditor) {
|
||||
|
||||
@ -13,39 +13,39 @@ const CHAR_TO_BINDING: { [char: string]: any; } = {};
|
||||
function defineBinding(char: string, value: any, modifierKeys: ModifierKeys): void {
|
||||
let key = modifierKeys.ctrl ? 'CTRL + ' + char : char;
|
||||
CHAR_TO_BINDING[key] = value;
|
||||
};
|
||||
}
|
||||
function getBinding(char: string, modifierKeys: ModifierKeys): any {
|
||||
let key = modifierKeys.ctrl ? 'CTRL + ' + char : char;
|
||||
return CHAR_TO_BINDING[key];
|
||||
};
|
||||
}
|
||||
|
||||
function defineOperator(char: string, operator: Operator, modifierKeys: ModifierKeys = {}): void {
|
||||
defineBinding(char + '__operator__', operator, modifierKeys);
|
||||
};
|
||||
}
|
||||
function getOperator(char: string, modifierKeys: ModifierKeys = {}): Operator {
|
||||
return getBinding(char + '__operator__', modifierKeys);
|
||||
};
|
||||
}
|
||||
|
||||
function defineCommand(char: string, commandId: string, modifierKeys: ModifierKeys = {}): void {
|
||||
defineBinding(char + '__command__', { commandId: commandId }, modifierKeys);
|
||||
};
|
||||
}
|
||||
function getCommand(char: string, modifierKeys: ModifierKeys = {}): Command {
|
||||
return getBinding(char + '__command__', modifierKeys);
|
||||
};
|
||||
}
|
||||
|
||||
function defineMotion(char: string, motion: Motion, modifierKeys: ModifierKeys = {}): void {
|
||||
defineBinding(char + '__motion__', motion, modifierKeys);
|
||||
};
|
||||
}
|
||||
function getMotion(char: string, modifierKeys: ModifierKeys = {}): Motion {
|
||||
return getBinding(char + '__motion__', modifierKeys);
|
||||
};
|
||||
}
|
||||
|
||||
function defineMotionCommand(char: string, motionCommand: AbstractCommandDescriptor, modifierKeys: ModifierKeys = {}): void {
|
||||
defineBinding(char + '__motioncommand__', motionCommand, modifierKeys);
|
||||
};
|
||||
}
|
||||
function getMotionCommand(char: string, modifierKeys: ModifierKeys = {}): AbstractCommandDescriptor {
|
||||
return getBinding(char + '__motioncommand__', modifierKeys);
|
||||
};
|
||||
}
|
||||
|
||||
// Operators
|
||||
defineOperator('x', Operators.DeleteCharUnderCursor);
|
||||
@ -223,7 +223,7 @@ function _parseNumberAndString(input: string, numberAtBeginning: boolean = true)
|
||||
hasRepeatCount: false,
|
||||
repeatCount: 1,
|
||||
input: input
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
interface INumberAndString {
|
||||
|
||||
@ -256,7 +256,7 @@ class CursorMoveCommand extends AbstractCommandDescriptor {
|
||||
by: this.by,
|
||||
value: args.repeat || 1,
|
||||
select: !!args.isVisual
|
||||
}
|
||||
};
|
||||
return {
|
||||
commandId: 'cursorMove',
|
||||
args: cursorMoveArgs
|
||||
@ -276,7 +276,7 @@ class EditorScrollCommand extends AbstractCommandDescriptor {
|
||||
by: this.by,
|
||||
value: args.repeat || 1,
|
||||
revealCursor: true
|
||||
}
|
||||
};
|
||||
return {
|
||||
commandId: 'editorScroll',
|
||||
args: editorScrollArgs
|
||||
@ -313,7 +313,7 @@ class MoveActiveEditorCommandByPosition extends AbstractCommandDescriptor {
|
||||
let moveActiveEditorArgs: any = {
|
||||
to: args.repeat === void 0 ? 'last' : 'position',
|
||||
value: args.repeat !== void 0 ? args.repeat + 1 : undefined
|
||||
}
|
||||
};
|
||||
return {
|
||||
commandId: 'moveActiveEditor',
|
||||
args: moveActiveEditorArgs
|
||||
@ -331,7 +331,7 @@ class MoveActiveEditorCommand extends AbstractCommandDescriptor {
|
||||
let moveActiveEditorArgs: any = {
|
||||
to: this.to,
|
||||
value: args.repeat ? args.repeat : 1
|
||||
}
|
||||
};
|
||||
return {
|
||||
commandId: 'moveActiveEditor',
|
||||
args: moveActiveEditorArgs
|
||||
@ -348,7 +348,7 @@ class FoldCommand extends AbstractCommandDescriptor {
|
||||
let foldEditorArgs: any = {
|
||||
levels: args.repeat ? args.repeat : 1,
|
||||
direction: 'up'
|
||||
}
|
||||
};
|
||||
return {
|
||||
commandId: 'editor.fold',
|
||||
args: foldEditorArgs
|
||||
@ -366,7 +366,7 @@ class UnfoldCommand extends AbstractCommandDescriptor {
|
||||
let foldEditorArgs: any = {
|
||||
levels: args.repeat ? args.repeat : 1,
|
||||
direction: 'up'
|
||||
}
|
||||
};
|
||||
return {
|
||||
commandId: 'editor.unfold',
|
||||
args: foldEditorArgs
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
'use strict';
|
||||
|
||||
import { Position, Selection, Range, TextDocument, TextEditor, TextEditorRevealType } from 'vscode';
|
||||
import { MotionState, Motion, Motions } from './motions';
|
||||
import { Motion, Motions } from './motions';
|
||||
import { Mode, IController, DeleteRegister } from './common';
|
||||
|
||||
export abstract class Operator {
|
||||
|
||||
Reference in New Issue
Block a user