Skip to content

Commit

Permalink
Convert 4 space tab to 2 space tab. (#460)
Browse files Browse the repository at this point in the history
* Convert 4 space tab to 2 space tab.

* Add tab config to workspace settings.
  • Loading branch information
rebornix authored and jpoon committed Jul 16, 2016
1 parent aa8f605 commit 9c1ec4b
Show file tree
Hide file tree
Showing 57 changed files with 5,429 additions and 5,428 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"search.exclude": {
"out": true // set this to false to include "out" folder in search results
},
"typescript.tsdk": "./node_modules/typescript/lib" // we want to use the TS server from our node_modules folder to control its version
"typescript.tsdk": "./node_modules/typescript/lib", // we want to use the TS server from our node_modules folder to control its version
"editor.tabSize": 2
}
134 changes: 67 additions & 67 deletions extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,103 +24,103 @@ let previousActiveFilename: string | undefined = undefined;
let taskQueue = new TaskQueue();

function activeFileName(): string {
return vscode.window.activeTextEditor.document.fileName;
return vscode.window.activeTextEditor.document.fileName;
}

export async function getAndUpdateModeHandler(): Promise<ModeHandler> {
const oldHandler = previousActiveFilename ? modeHandlerToFilename[previousActiveFilename] : undefined;
const oldHandler = previousActiveFilename ? modeHandlerToFilename[previousActiveFilename] : undefined;

if (!modeHandlerToFilename[activeFileName()]) {
const newModeHandler = new ModeHandler(false, activeFileName());
if (!modeHandlerToFilename[activeFileName()]) {
const newModeHandler = new ModeHandler(false, activeFileName());

modeHandlerToFilename[activeFileName()] = newModeHandler;
extensionContext.subscriptions.push(newModeHandler);
modeHandlerToFilename[activeFileName()] = newModeHandler;
extensionContext.subscriptions.push(newModeHandler);

console.log('make new mode handler for ', activeFileName());
}
console.log('make new mode handler for ', activeFileName());
}

const handler = modeHandlerToFilename[activeFileName()];
const handler = modeHandlerToFilename[activeFileName()];

if (previousActiveFilename !== activeFileName()) {
previousActiveFilename = activeFileName();
if (previousActiveFilename !== activeFileName()) {
previousActiveFilename = activeFileName();

await handler.updateView(handler.vimState);
}
await handler.updateView(handler.vimState);
}

if (oldHandler && oldHandler.vimState.focusChanged) {
oldHandler.vimState.focusChanged = false;
handler.vimState.focusChanged = true;
}
if (oldHandler && oldHandler.vimState.focusChanged) {
oldHandler.vimState.focusChanged = false;
handler.vimState.focusChanged = true;
}

return handler;
return handler;
}

export function activate(context: vscode.ExtensionContext) {
extensionContext = context;

registerCommand(context, 'type', async (args) => {
if (!vscode.window.activeTextEditor) {
return;
}

taskQueue.enqueueTask({
promise: async () => {
const mh = await getAndUpdateModeHandler();
await mh.handleKeyEvent(args.text);
},
isRunning : false
});
extensionContext = context;

registerCommand(context, 'type', async (args) => {
if (!vscode.window.activeTextEditor) {
return;
}

taskQueue.enqueueTask({
promise: async () => {
const mh = await getAndUpdateModeHandler();
await mh.handleKeyEvent(args.text);
},
isRunning : false
});
});

registerCommand(context, 'replacePreviousChar', async (args) => {
if (!vscode.window.activeTextEditor) {
return;
}

taskQueue.enqueueTask({
promise: async () => {
const mh = await getAndUpdateModeHandler();
await vscode.commands.executeCommand('default:replacePreviousChar', {
text: args.text,
replaceCharCnt: args.replaceCharCnt
});
mh.vimState.cursorPosition = Position.FromVSCodePosition(vscode.window.activeTextEditor.selection.start);
mh.vimState.cursorStartPosition = Position.FromVSCodePosition(vscode.window.activeTextEditor.selection.start);
},
isRunning : false
registerCommand(context, 'replacePreviousChar', async (args) => {
if (!vscode.window.activeTextEditor) {
return;
}

taskQueue.enqueueTask({
promise: async () => {
const mh = await getAndUpdateModeHandler();
await vscode.commands.executeCommand('default:replacePreviousChar', {
text: args.text,
replaceCharCnt: args.replaceCharCnt
});
mh.vimState.cursorPosition = Position.FromVSCodePosition(vscode.window.activeTextEditor.selection.start);
mh.vimState.cursorStartPosition = Position.FromVSCodePosition(vscode.window.activeTextEditor.selection.start);
},
isRunning : false
});
});

registerCommand(context, 'extension.vim_esc', () => handleKeyEvent("<esc>"));
registerCommand(context, 'extension.vim_backspace', () => handleKeyEvent("<backspace>"));
registerCommand(context, 'extension.vim_esc', () => handleKeyEvent("<esc>"));
registerCommand(context, 'extension.vim_backspace', () => handleKeyEvent("<backspace>"));

registerCommand(context, 'extension.showCmdLine', () => {
showCmdLine("", modeHandlerToFilename[activeFileName()]);
});
registerCommand(context, 'extension.showCmdLine', () => {
showCmdLine("", modeHandlerToFilename[activeFileName()]);
});

'rfbducw['.split('').forEach(key => {
registerCommand(context, `extension.vim_ctrl+${key}`, () => handleKeyEvent(`ctrl+${key}`));
});
'rfbducw['.split('').forEach(key => {
registerCommand(context, `extension.vim_ctrl+${key}`, () => handleKeyEvent(`ctrl+${key}`));
});

['left', 'right', 'up', 'down'].forEach(key => {
registerCommand(context, `extension.vim_${key}`, () => handleKeyEvent(`<${key}>`));
});
['left', 'right', 'up', 'down'].forEach(key => {
registerCommand(context, `extension.vim_${key}`, () => handleKeyEvent(`<${key}>`));
});
}

function registerCommand(context: vscode.ExtensionContext, command: string, callback: (...args: any[]) => any) {
let disposable = vscode.commands.registerCommand(command, callback);
context.subscriptions.push(disposable);
let disposable = vscode.commands.registerCommand(command, callback);
context.subscriptions.push(disposable);
}

async function handleKeyEvent(key: string): Promise<void> {
const mh = await getAndUpdateModeHandler();
const mh = await getAndUpdateModeHandler();

taskQueue.enqueueTask({
promise : async () => { await mh.handleKeyEvent(key); },
isRunning : false
});
taskQueue.enqueueTask({
promise : async () => { await mh.handleKeyEvent(key); },
isRunning : false
});
}

process.on('unhandledRejection', function(reason: any, p: any) {
console.log("Unhandled Rejection at: Promise ", p, " reason: ", reason);
console.log("Unhandled Rejection at: Promise ", p, " reason: ", reason);
});
110 changes: 55 additions & 55 deletions src/cmd_line/commands/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,78 +5,78 @@ import * as path from "path";
import * as node from "../node";

export enum FilePosition {
CurrentWindow,
NewWindow
CurrentWindow,
NewWindow
}

export interface IFileCommandArguments extends node.ICommandArgs {
name?: string;
position?: FilePosition;
name?: string;
position?: FilePosition;
}


export class FileCommand extends node.CommandBase {
protected _arguments: IFileCommandArguments;
protected _arguments: IFileCommandArguments;

constructor(args : IFileCommandArguments) {
super();
this._name = 'file';
this._shortName = 'file';
this._arguments = args;
}

get arguments() : IFileCommandArguments {
return this._arguments;
}
constructor(args : IFileCommandArguments) {
super();
this._name = 'file';
this._shortName = 'file';
this._arguments = args;
}

getActiveViewColumn(): vscode.ViewColumn {
const active = vscode.window.activeTextEditor;
get arguments() : IFileCommandArguments {
return this._arguments;
}

if (!active) {
return vscode.ViewColumn.One;
}
getActiveViewColumn(): vscode.ViewColumn {
const active = vscode.window.activeTextEditor;

return active.viewColumn;
if (!active) {
return vscode.ViewColumn.One;
}

getViewColumnToRight() : vscode.ViewColumn {
const active = vscode.window.activeTextEditor;
return active.viewColumn;
}

if (!active) {
return vscode.ViewColumn.One;
}
getViewColumnToRight() : vscode.ViewColumn {
const active = vscode.window.activeTextEditor;

switch (active.viewColumn) {
case vscode.ViewColumn.One:
return vscode.ViewColumn.Two;
case vscode.ViewColumn.Two:
return vscode.ViewColumn.Three;
}
if (!active) {
return vscode.ViewColumn.One;
}

return active.viewColumn;
switch (active.viewColumn) {
case vscode.ViewColumn.One:
return vscode.ViewColumn.Two;
case vscode.ViewColumn.Two:
return vscode.ViewColumn.Three;
}

async execute(): Promise<void> {
if (!this._arguments.name) {
// Open an empty file
if (this._arguments.position === FilePosition.CurrentWindow) {
await vscode.commands.executeCommand("workbench.action.files.newUntitledFile");
} else {
await vscode.commands.executeCommand("workbench.action.splitEditor");
await vscode.commands.executeCommand("workbench.action.files.newUntitledFile");
await vscode.commands.executeCommand("workbench.action.closeOtherEditors");
}

return;
}

let currentFilePath = vscode.window.activeTextEditor.document.uri.path;
let newFilePath = path.join(path.dirname(currentFilePath), this._arguments.name);

if (newFilePath !== currentFilePath) {
let folder = vscode.Uri.file(newFilePath);
await vscode.commands.executeCommand("vscode.open", folder,
this._arguments.position === FilePosition.NewWindow ? this.getViewColumnToRight() : this.getActiveViewColumn());
}
return active.viewColumn;
}

async execute(): Promise<void> {
if (!this._arguments.name) {
// Open an empty file
if (this._arguments.position === FilePosition.CurrentWindow) {
await vscode.commands.executeCommand("workbench.action.files.newUntitledFile");
} else {
await vscode.commands.executeCommand("workbench.action.splitEditor");
await vscode.commands.executeCommand("workbench.action.files.newUntitledFile");
await vscode.commands.executeCommand("workbench.action.closeOtherEditors");
}

return;
}

let currentFilePath = vscode.window.activeTextEditor.document.uri.path;
let newFilePath = path.join(path.dirname(currentFilePath), this._arguments.name);

if (newFilePath !== currentFilePath) {
let folder = vscode.Uri.file(newFilePath);
await vscode.commands.executeCommand("vscode.open", folder,
this._arguments.position === FilePosition.NewWindow ? this.getViewColumnToRight() : this.getActiveViewColumn());
}
}
}
36 changes: 18 additions & 18 deletions src/cmd_line/commands/quit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,33 @@ import * as node from "../node";
import * as error from '../../error';

export interface IQuitCommandArguments extends node.ICommandArgs {
bang?: boolean;
range?: node.LineRange;
bang?: boolean;
range?: node.LineRange;
}

//
// Implements :quit
// http://vimdoc.sourceforge.net/htmldoc/editing.html#:quit
//
export class QuitCommand extends node.CommandBase {
protected _arguments : IQuitCommandArguments;
protected _arguments : IQuitCommandArguments;

constructor(args : IQuitCommandArguments) {
super();
this._name = 'quit';
this._shortName = 'q';
this._arguments = args;
}

get arguments() : IQuitCommandArguments {
return this._arguments;
}
constructor(args : IQuitCommandArguments) {
super();
this._name = 'quit';
this._shortName = 'q';
this._arguments = args;
}

execute() : void {
if (this.activeTextEditor.document.isDirty && !this.arguments.bang) {
throw error.VimError.fromCode(error.ErrorCode.E37);
}
get arguments() : IQuitCommandArguments {
return this._arguments;
}

vscode.commands.executeCommand('workbench.action.closeActiveEditor');
execute() : void {
if (this.activeTextEditor.document.isDirty && !this.arguments.bang) {
throw error.VimError.fromCode(error.ErrorCode.E37);
}

vscode.commands.executeCommand('workbench.action.closeActiveEditor');
}
}
Loading

0 comments on commit 9c1ec4b

Please sign in to comment.