Skip to content

Commit

Permalink
Merge pull request #20 from JunbaeJs/enabled
Browse files Browse the repository at this point in the history
fix: working enabled, disabled
  • Loading branch information
changchanghwang authored Feb 16, 2024
2 parents 900f3d5 + db015f0 commit c0b0eb0
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 5 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "junbae-mode",
"displayName": "Junbae Mode",
"icon": "images/junbae-logo.png",
"version": "1.0.1",
"version": "1.0.2",
"description": "Junbae is caique parrot!",
"main": "./dist/extension.js",
"publisher": "JunbaeJs",
Expand Down
Binary file added package/junbae-mode-1.0.2.vsix
Binary file not shown.
22 changes: 20 additions & 2 deletions src/core/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const configurationSection = ['enabled'] as const;
type ConfigurationSection = (typeof configurationSection)[number];
export class JunbaeMode {
// configurations
enabled: boolean = vscode.workspace.getConfiguration('junbae-mode').get('enabled') ?? true;
enabled: boolean = true;

modes: Mode[] = [];

Expand Down Expand Up @@ -40,6 +40,24 @@ export class JunbaeMode {
}

onDidChangeTextDocument = (event: vscode.TextDocumentChangeEvent) => {
this.modes.forEach((mode) => mode.onDidChangeTextDocument(event));
if (this.enabled) {
this.modes.forEach((mode) => mode.onDidChangeTextDocument(event));
}
};

/**
* Reset when configuration changed
*/
onDidChangeConfiguration = () => {
this.reset();
};

private reset() {
this.dispose();
this.enabled = vscode.workspace.getConfiguration('junbae-mode').get('enabled')!;
}

private dispose() {
this.modes.forEach((mode) => mode.dispose());
}
}
2 changes: 2 additions & 0 deletions src/core/modes/mode.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ import * as vscode from 'vscode';

export interface Mode {
onDidChangeTextDocument(event: vscode.TextDocumentChangeEvent): void;

dispose(): void;
}
1 change: 1 addition & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export function activate(context: vscode.ExtensionContext) {
const enable = vscode.commands.registerCommand('junbae-mode.enable', () => mode.setEnabled(true));
const disable = vscode.commands.registerCommand('junbae-mode.disable', () => mode.setEnabled(false));
vscode.workspace.onDidChangeTextDocument(mode.onDidChangeTextDocument);
vscode.workspace.onDidChangeConfiguration(mode.onDidChangeConfiguration);

context.subscriptions.push(enable);
context.subscriptions.push(disable);
Expand Down

0 comments on commit c0b0eb0

Please sign in to comment.