Skip to content

Commit

Permalink
Merge remote-tracking branch 'vscode-lean3/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
gebner committed Feb 2, 2021
2 parents 678fe4a + b148537 commit e116fc6
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/abbreviation/rewriter/AbbreviationRewriterFeature.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { observable } from 'mobx';
import { Disposable, TextEditor, window } from 'vscode';
import { Disposable, languages, TextEditor, window } from 'vscode';
import { autorunDisposable } from '../../utils/autorunDisposable';
import { AbbreviationProvider } from '../AbbreviationProvider';
import { AbbreviationConfig } from '../config';
Expand All @@ -16,7 +16,7 @@ export class AbbreviationRewriterFeature {
private activeTextEditor: TextEditor | undefined;

constructor(
config: AbbreviationConfig,
private readonly config: AbbreviationConfig,
abbreviationProvider: AbbreviationProvider
) {
this.activeTextEditor = window.activeTextEditor;
Expand All @@ -26,7 +26,7 @@ export class AbbreviationRewriterFeature {
this.activeTextEditor = e;
}),
autorunDisposable((disposables) => {
if (this.activeTextEditor && config.inputModeEnabled) {
if (this.activeTextEditor && this.shouldEnableRewriterForEditor(this.activeTextEditor)) {
// This creates an abbreviation rewriter for the active text editor.
// Old rewriters are disposed automatically.
// This is also updated when this feature is turned off/on.
Expand All @@ -42,6 +42,16 @@ export class AbbreviationRewriterFeature {
);
}

private shouldEnableRewriterForEditor(editor: TextEditor): boolean {
if (!this.config.inputModeEnabled) {
return false;
}
if (!languages.match(this.config.languages.get(), editor.document)) {
return false;
}
return true;
}

dispose(): void {
for (const d of this.disposables) {
d.dispose();
Expand Down

0 comments on commit e116fc6

Please sign in to comment.