diff --git a/extension.ts b/extension.ts index 81293574642..799975a53d5 100644 --- a/extension.ts +++ b/extension.ts @@ -17,7 +17,13 @@ export function activate(context: vscode.ExtensionContext) { extensionContext = context; - registerCommand(context, 'extension.showCmdLine', () => showCmdLine("")); + registerCommand(context, 'extension.showCmdLine', () => { + if (!modeHandler) { + modeHandler = new ModeHandler(); + extensionContext.subscriptions.push(modeHandler); + } + showCmdLine("", modeHandler); + }); registerCommand(context, 'extension.vim_esc', () => handleKeyEvent("esc")); registerCommand(context, 'extension.vim_colon', () => handleKeyEvent(":")); diff --git a/src/cmd_line/commands/write.ts b/src/cmd_line/commands/write.ts index 953fce57920..296ff53d66b 100644 --- a/src/cmd_line/commands/write.ts +++ b/src/cmd_line/commands/write.ts @@ -2,10 +2,12 @@ // XXX: use graceful-fs ?? import * as fs from 'fs'; +import * as path from 'path'; import * as node from '../node'; import * as util from '../../util'; import * as error from '../../error'; +import {ModeHandler} from "../../mode/modeHandler"; export interface IWriteCommandArguments extends node.ICommandArgs { opt? : string; @@ -35,7 +37,7 @@ export class WriteCommand extends node.CommandBase { return this._arguments; } - execute() : void { + execute(modeHandler : ModeHandler) : void { if (this.arguments.opt) { util.showError("Not implemented."); return; @@ -59,30 +61,28 @@ export class WriteCommand extends node.CommandBase { if (this.arguments.bang) { fs.chmod(this.activeTextEditor.document.fileName, 666, (e) => { if (e) { - util.showError(e.message); + modeHandler.setupStatusBarItem(e.message); } else { - this.save(); + this.save(modeHandler); } }); } else { - util.showError(accessErr.message); + modeHandler.setupStatusBarItem(accessErr.message); } } else { - this.save(); + this.save(modeHandler); } }); } - private save() { + private save(modeHandler : ModeHandler) { this.activeTextEditor.document.save().then( (ok) => { - if (ok) { - util.showInfo("File saved."); - } else { - util.showError("File not saved."); - } + modeHandler.setupStatusBarItem('"' + path.basename(this.activeTextEditor.document.fileName) + + '" ' + this.activeTextEditor.document.lineCount + 'L ' + + this.activeTextEditor.document.getText().length + 'C written'); }, - (e) => util.showError(e) + (e) => modeHandler.setupStatusBarItem(e) ); } } diff --git a/src/cmd_line/main.ts b/src/cmd_line/main.ts index 42a8ce33280..22db132ea11 100644 --- a/src/cmd_line/main.ts +++ b/src/cmd_line/main.ts @@ -2,10 +2,10 @@ import * as vscode from "vscode"; import * as parser from "./parser"; -import * as util from "../util"; +import {ModeHandler} from "../mode/modeHandler"; // Shows the vim command line. -export async function showCmdLine(initialText: string): Promise<{}> { +export async function showCmdLine(initialText: string, modeHandler : ModeHandler): Promise<{}> { if (!vscode.window.activeTextEditor) { console.log("No active document."); return; @@ -17,13 +17,13 @@ export async function showCmdLine(initialText: string): Promise<{}> { }; try { - runCmdLine(await vscode.window.showInputBox(options)); + await runCmdLine(await vscode.window.showInputBox(options), modeHandler); } catch (e) { - return util.showError(e.toString()); + modeHandler.setupStatusBarItem(e.toString()); } } -function runCmdLine(command : string) : Promise<{}> { +function runCmdLine(command : string, modeHandler : ModeHandler) : Promise<{}> { if (!command || command.length === 0) { return; } @@ -34,8 +34,8 @@ function runCmdLine(command : string) : Promise<{}> { return; } - cmd.execute(vscode.window.activeTextEditor); + cmd.execute(vscode.window.activeTextEditor, modeHandler); } catch (e) { - return util.showError(e); + modeHandler.setupStatusBarItem(e.toString()); } } diff --git a/src/cmd_line/node.ts b/src/cmd_line/node.ts index 24c1eb7fd70..60c973bfdba 100644 --- a/src/cmd_line/node.ts +++ b/src/cmd_line/node.ts @@ -2,6 +2,7 @@ import * as vscode from "vscode"; import * as token from "./token"; +import {ModeHandler} from "../mode/modeHandler"; export class LineRange { left : token.Token[]; @@ -86,14 +87,14 @@ export class CommandLine { return ":" + this.range.toString() + " " + this.command.toString(); } - execute(document : vscode.TextEditor) : void { + execute(document : vscode.TextEditor, modeHandler : ModeHandler) : void { if (!this.command) { this.range.execute(document); return; } // TODO: calc range - this.command.execute(); + this.command.execute(modeHandler); } } @@ -123,5 +124,5 @@ export abstract class CommandBase { } protected _arguments : ICommandArgs; - abstract execute() : void; + abstract execute(modeHandler : ModeHandler) : void; } diff --git a/src/mode/modeHandler.ts b/src/mode/modeHandler.ts index 88d6aae2845..af4768ac761 100644 --- a/src/mode/modeHandler.ts +++ b/src/mode/modeHandler.ts @@ -49,7 +49,7 @@ export class ModeHandler implements vscode.Disposable { } const statusBarText = (this.currentMode.name === ModeName.Normal) ? '' : ModeName[modeName]; - this.setupStatusBarItem(statusBarText.toUpperCase()); + this.setupStatusBarItem(statusBarText ? `-- ${statusBarText.toUpperCase()} --` : ''); } handleKeyEvent(key : string) : void { @@ -81,12 +81,12 @@ export class ModeHandler implements vscode.Disposable { } } - private setupStatusBarItem(text : string) : void { + setupStatusBarItem(text : string) : void { if (!this._statusBarItem) { this._statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left); } - this._statusBarItem.text = text ? `--${text}--` : ''; + this._statusBarItem.text = text || ''; this._statusBarItem.show(); } diff --git a/src/mode/modeNormal.ts b/src/mode/modeNormal.ts index 66b9b75c3b5..06ed6be04c1 100644 --- a/src/mode/modeNormal.ts +++ b/src/mode/modeNormal.ts @@ -11,7 +11,7 @@ import {DeleteOperator} from './../operator/delete'; export class NormalMode extends Mode { protected keyHandler : { [key : string] : (motion : Motion) => Promise<{}>; } = { - ":" : async () => { return showCmdLine(""); }, + ":" : async () => { return showCmdLine("", this._modeHandler); }, "u" : async () => { return vscode.commands.executeCommand("undo"); }, "ctrl+r" : async () => { return vscode.commands.executeCommand("redo"); }, "h" : async (c) => { return c.left().move(); },