-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
113 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,18 +5,28 @@ import * as vscode from 'vscode'; | |
|
||
import {showCmdLine} from './src/cmd_line/main'; | ||
import * as cc from './src/cmd_line/lexer'; | ||
import {ModeHandler} from "./src/mode/mode_handler"; | ||
import {ModeName} from "./src/mode/mode"; | ||
|
||
// this method is called when your extension is activated | ||
// your extension is activated the very first time the command is executed | ||
export function activate(context: vscode.ExtensionContext) { | ||
|
||
var modeHandler = new ModeHandler(); | ||
|
||
// Use the console to output diagnostic information (console.log) and errors (console.error) | ||
// This line of code will only be executed once when your extension is activated | ||
console.log('Congratulations, your extension "vim" is now active!'); | ||
|
||
var cmdLineDisposable = vscode.commands.registerCommand('extension.showCmdLine', () => { | ||
showCmdLine(); | ||
}); | ||
|
||
|
||
vscode.commands.registerCommand('extension.vimMode_esc', () => modeHandler.HandleKeyEvent("esc")); | ||
vscode.commands.registerCommand('extension.vimMode_h', () => modeHandler.HandleKeyEvent("h")); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jpoon
Author
Member
|
||
vscode.commands.registerCommand('extension.vimMode_j', () => modeHandler.HandleKeyEvent("j")); | ||
vscode.commands.registerCommand('extension.vimMode_k', () => modeHandler.HandleKeyEvent("k")); | ||
vscode.commands.registerCommand('extension.vimMode_l', () => modeHandler.HandleKeyEvent("l")); | ||
|
||
context.subscriptions.push(cmdLineDisposable); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
export enum ModeName { | ||
Normal, | ||
Insert, | ||
Visual, | ||
} | ||
|
||
export abstract class Mode { | ||
private _isActive : boolean; | ||
private _name : ModeName; | ||
|
||
constructor(name: ModeName, isActive: boolean) { | ||
this._name = name; | ||
this._isActive = isActive || false; | ||
} | ||
|
||
get Name(): ModeName { | ||
return this._name; | ||
} | ||
|
||
get IsActive():boolean { | ||
return this._isActive; | ||
} | ||
|
||
set IsActive(val:boolean) { | ||
this._isActive = val; | ||
} | ||
|
||
abstract HandleKeyEvent(key:string) : void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import * as baseMode from './mode'; | ||
import * as vscode from 'vscode'; | ||
|
||
export class CommandMode extends baseMode.Mode { | ||
_keyHistory: string[]; | ||
|
||
constructor(isActive?: boolean) { | ||
super(baseMode.ModeName.Normal, isActive); | ||
|
||
this._keyHistory = []; | ||
} | ||
|
||
HandleKeyEvent(key:string) : void { | ||
this._keyHistory.push(key); | ||
|
||
switch(key) { | ||
case 'h': | ||
vscode.commands.executeCommand("cursorLeft"); | ||
break; | ||
case 'j': | ||
vscode.commands.executeCommand("cursorDown"); | ||
break; | ||
case 'k': | ||
vscode.commands.executeCommand("cursorUp"); | ||
break; | ||
case 'l': | ||
vscode.commands.executeCommand("cursorRight"); | ||
break; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//import * as vscode from 'vscode'; | ||
import {commands, window, workspace, ExtensionContext, TextEditorOptions, TextEditor, TextDocument, Disposable} from 'vscode'; | ||
import {Mode, ModeName} from './mode'; | ||
import {CommandMode} from './mode_command'; | ||
|
||
export class ModeHandler { | ||
private _modes: Mode[]; | ||
|
||
constructor() { | ||
this._modes = [ | ||
new CommandMode(true), | ||
]; | ||
|
||
} | ||
|
||
get CurrentMode(): Mode { | ||
var currentMode = this._modes.find((mode, index) => { | ||
return mode.IsActive; | ||
}); | ||
|
||
return currentMode; | ||
} | ||
|
||
SetCurrentModeByName(modeName:ModeName) { | ||
this._modes.forEach(mode => { | ||
mode.IsActive = (mode.Name == modeName); | ||
}); | ||
} | ||
|
||
HandleKeyEvent(key:string) : void { | ||
if (key == "esc") { | ||
|
||
} | ||
this.CurrentMode.HandleKeyEvent(key); | ||
} | ||
} |
curious, does this prevent the the 'h' from being inserted in the text buffer?