Skip to content

Commit

Permalink
Disabled mode tweaks, including modification of config value.
Browse files Browse the repository at this point in the history
  • Loading branch information
westim committed Nov 7, 2017
1 parent 4726172 commit f68b16f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ We have removed this option, due to it making VSCodeVim's performance suffer imm
#### `"vim.disableExtension"`
* VSCodeVim will be in "Disabled" mode
* This can be changed at any time using the `toggleVim` command in the Command Palette
* Note that this is not the same as disabling the VSCodeVim extension
* Note that this is not the same as disabling the VSCodeVim extension through VS Code
* Type: Boolean (Default: `false`)

### Neovim Integration
Expand Down
17 changes: 11 additions & 6 deletions extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,15 @@ export async function activate(context: vscode.ExtensionContext) {
}
});

async function toggleDisabledMode() {
if (Configuration.disableExtension) {
/**
* Toggles the VSCodeVim extension between Enabled mode and Disabled mode. This
* function is activated by calling the 'toggleVim' command from the Command Palette.
*
* @param isDisabled if true, sets VSCodeVim to Disabled mode; else sets to enabled mode
*/
async function toggleExtension(isDisabled: boolean | undefined) {
await vscode.commands.executeCommand('setContext', 'vim.active', !isDisabled);
if (isDisabled) {
let cursorStyle = await vscode.workspace
.getConfiguration('editor')
.get('cursorStyle', 'line');
Expand All @@ -332,11 +339,9 @@ export async function activate(context: vscode.ExtensionContext) {
}
editor.options = options;
});
await vscode.commands.executeCommand('setContext', 'vim.active', false);
let mh = await getAndUpdateModeHandler();
mh.setStatusBarText('-- VIM: DISABLED --');
} else {
await vscode.commands.executeCommand('setContext', 'vim.active', true);
compositionState = new CompositionState();
modeHandlerToEditorIdentity = {};
let mh = await getAndUpdateModeHandler();
Expand All @@ -346,7 +351,7 @@ export async function activate(context: vscode.ExtensionContext) {

registerCommand(context, 'toggleVim', async () => {
Configuration.disableExtension = !Configuration.disableExtension;
toggleDisabledMode();
toggleExtension(Configuration.disableExtension);
});

// Clear boundKeyCombinations array incase there are any entries in it so
Expand Down Expand Up @@ -387,7 +392,7 @@ export async function activate(context: vscode.ExtensionContext) {
}

// This is called last because getAndUpdateModeHandler() will change cursor
toggleDisabledMode();
toggleExtension(Configuration.disableExtension);
}

function overrideCommand(
Expand Down
32 changes: 24 additions & 8 deletions src/configuration/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export interface IModeSpecificStrings {
* Every Vim option we support should
* 1. Be added to contribution section of `package.json`.
* 2. Named as `vim.{optionName}`, `optionName` is the name we use in Vim.
* 3. Define a public property in `Configuration `with the same name and a default value.
* Or define a private propery and define customized Getter/Setter accessors for it.
* 3. Define a public property in `Configuration` with the same name and a default value.
* Or define a private property and define customized Getter/Setter accessors for it.
* Always remember to decorate Getter accessor as @enumerable()
* 4. If user doesn't set the option explicitly
* a. we don't have a similar setting in Code, initialize the option as default value.
Expand All @@ -35,9 +35,9 @@ export interface IModeSpecificStrings {
* Vim option override sequence.
* 1. `:set {option}` on the fly
* 2. TODO .vimrc.
* 2. `vim.{option}`
* 3. VS Code configuration
* 4. VSCodeVim flavored Vim option default values
* 3. `vim.{option}`
* 4. VS Code configuration
* 5. VSCodeVim flavored Vim option default values
*
*/
class ConfigurationClass {
Expand Down Expand Up @@ -84,15 +84,15 @@ class ConfigurationClass {
}

// Get configuration setting for handled keys, this allows user to disable
// certain key comboinations
// certain key combinations
const handleKeys = vscode.workspace
.getConfiguration('vim')
.get<IHandleKeys[]>('handleKeys', []);

for (const bracketedKey of this.boundKeyCombinations) {
// Set context for key that is not used
// This either happens when user sets useCtrlKeys to false (ctrl keys are not used then)
// Or if user usese vim.handleKeys configuration option to set certain combinations to false
// Or if user uses vim.handleKeys configuration option to set certain combinations to false
// By default, all key combinations are used so start with true
let useKey = true;

Expand Down Expand Up @@ -310,7 +310,23 @@ class ConfigurationClass {
/**
* Determines whether VSCodeVim is in Disabled mode or not.
*/
disableExtension = false;
private _disableExtension: boolean | undefined;

get disableExtension(): boolean | undefined {
if (this._disableExtension === undefined) {
this.disableExtension = vscode.workspace.getConfiguration('vim').get('disableExtension');
}
return this._disableExtension;
}
set disableExtension(isDisabled: boolean | undefined) {
this._disableExtension = isDisabled;
const config: vscode.WorkspaceConfiguration | undefined = vscode.workspace.getConfiguration(
'vim.disableExtension'
);
if (config) {
config.update('vim.disableExtension', isDisabled);
}
}

enableNeovim = true;

Expand Down

0 comments on commit f68b16f

Please sign in to comment.