Skip to content

Commit

Permalink
Merge pull request #3318 from VSCodeVim/disableext
Browse files Browse the repository at this point in the history
refactor: disableExtension configuration should follow pattern of rest of configs
  • Loading branch information
jpoon authored Jan 2, 2019
2 parents 3dd6b48 + 48aae0c commit a505b47
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 45 deletions.
20 changes: 9 additions & 11 deletions extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export async function activate(context: vscode.ExtensionContext) {
event.contentChanges[0].range.start.line === event.contentChanges[0].range.end.line;

vscode.workspace.onDidChangeTextDocument(async event => {
if (configuration.disableExt) {
if (configuration.disableExtension) {
return;
}

Expand Down Expand Up @@ -165,7 +165,7 @@ export async function activate(context: vscode.ExtensionContext) {

// window events
vscode.window.onDidChangeActiveTextEditor(async () => {
if (configuration.disableExt) {
if (configuration.disableExtension) {
return;
}

Expand Down Expand Up @@ -297,8 +297,8 @@ export async function activate(context: vscode.ExtensionContext) {
});

registerCommand(context, 'toggleVim', async () => {
configuration.disableExt = !configuration.disableExt;
toggleExtension(configuration.disableExt, compositionState);
configuration.disableExtension = !configuration.disableExtension;
toggleExtension(configuration.disableExtension, compositionState);
});

for (const boundKey of configuration.boundKeyCombinations) {
Expand All @@ -316,7 +316,7 @@ export async function activate(context: vscode.ExtensionContext) {
globalState.load(),
configurationValidator.initialize(),
// This is called last because getAndUpdateModeHandler() will change cursor
toggleExtension(configuration.disableExt, compositionState),
toggleExtension(configuration.disableExtension, compositionState),
]);
}

Expand Down Expand Up @@ -349,9 +349,8 @@ function overrideCommand(
callback: (...args: any[]) => any
) {
const disposable = vscode.commands.registerCommand(command, async args => {
if (configuration.disableExt) {
await vscode.commands.executeCommand('default:' + command, args);
return;
if (configuration.disableExtension) {
return vscode.commands.executeCommand('default:' + command, args);
}

if (!vscode.window.activeTextEditor) {
Expand All @@ -362,11 +361,10 @@ function overrideCommand(
vscode.window.activeTextEditor.document &&
vscode.window.activeTextEditor.document.uri.toString() === 'debug:input'
) {
await vscode.commands.executeCommand('default:' + command, args);
return;
return vscode.commands.executeCommand('default:' + command, args);
}

callback(args);
return callback(args);
});
context.subscriptions.push(disposable);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@
},
"vim.disableExtension": {
"type": "boolean",
"description": "Disables the VSCodeVim extension.",
"description": "Disables the VSCodeVim extension. Extension will continue to be loaded and activated, but VIM functionality will be disabled.",
"default": false
},
"vim.enableNeovim": {
Expand Down
45 changes: 15 additions & 30 deletions src/configuration/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ interface IKeyBinding {
* 1. `:set {option}` on the fly
* 2. `vim.{option}`
* 3. VS Code configuration
* 4. VSCodeVim flavored Vim option default values
* 4. VSCodeVim configuration default values
*
*/
class Configuration implements IConfiguration {
Expand Down Expand Up @@ -81,7 +81,7 @@ class Configuration implements IConfiguration {
let val = vimConfigs[option] as any;
if (val !== null && val !== undefined) {
if (val.constructor.name === Object.name) {
val = this.unproxify(val);
val = Configuration.unproxify(val);
}
this[option] = val;
}
Expand Down Expand Up @@ -166,23 +166,9 @@ class Configuration implements IConfiguration {
VsCodeContext.Set('vim.overrideCtrlC', this.overrideCopy || this.useCtrlKeys);
}

unproxify(obj: Object): Object {
let result = {};
for (const key in obj) {
let val = obj[key] as any;
if (val !== null && val !== undefined) {
result[key] = val;
}
}
return result;
}

getConfiguration(section: string = ''): vscode.WorkspaceConfiguration {
let resource: vscode.Uri | undefined = undefined;
let activeTextEditor = vscode.window.activeTextEditor;
if (activeTextEditor) {
resource = activeTextEditor.document.uri;
}
let resource = activeTextEditor ? activeTextEditor.document.uri : undefined;
return vscode.workspace.getConfiguration(section, resource);
}

Expand Down Expand Up @@ -310,19 +296,7 @@ class Configuration implements IConfiguration {

foldfix = false;

private disableExtension: boolean = false;

get disableExt(): boolean {
return this.disableExtension;
}
set disableExt(isDisabled: boolean) {
this.disableExtension = isDisabled;
this.getConfiguration('vim').update(
'disableExtension',
isDisabled,
vscode.ConfigurationTarget.Global
);
}
disableExtension: boolean = false;

enableNeovim = false;
neovimPath = 'nvim';
Expand Down Expand Up @@ -356,6 +330,17 @@ class Configuration implements IConfiguration {
normalModeKeyBindingsNonRecursive: IKeyRemapping[] = [];
visualModeKeyBindings: IKeyRemapping[] = [];
visualModeKeyBindingsNonRecursive: IKeyRemapping[] = [];

private static unproxify(obj: Object): Object {
let result = {};
for (const key in obj) {
let val = obj[key] as any;
if (val !== null && val !== undefined) {
result[key] = val;
}
}
return result;
}
}

// handle mapped settings between vscode to vim
Expand Down
7 changes: 6 additions & 1 deletion src/configuration/iconfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,12 @@ export interface IConfiguration {
*/
foldfix: boolean;

disableExt: boolean;
/**
* "Soft"-disabling of extension.
* Differs from VS Code's disablng of the extension as the extension
* will still be loaded and activated, but all functionality will be disabled.
*/
disableExtension: boolean;

/**
* Neovim
Expand Down
2 changes: 1 addition & 1 deletion src/mode/modeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class ModeHandler implements vscode.Disposable {
// Handle scenarios where mouse used to change current position.
const onChangeTextEditorSelection = vscode.window.onDidChangeTextEditorSelection(
(e: vscode.TextEditorSelectionChangeEvent) => {
if (configuration.disableExt) {
if (configuration.disableExtension) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion test/testConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class Configuration implements IConfiguration {
mouseSelectionGoesIntoVisualMode = true;
changeWordIncludesWhitespace = false;
foldfix = false;
disableExt = false;
disableExtension = false;
enableNeovim = false;
neovimPath = 'nvim';
substituteGlobalFlag = false;
Expand Down

0 comments on commit a505b47

Please sign in to comment.