diff --git a/src/Actions/Indent.ts b/src/Actions/Indent.ts index ad254d24..efecabfa 100644 --- a/src/Actions/Indent.ts +++ b/src/Actions/Indent.ts @@ -1,6 +1,7 @@ import {window, Range} from 'vscode'; import {StaticReflect} from '../LanguageExtensions/StaticReflect'; import {SymbolMetadata} from '../Symbols/Metadata'; +import {Configuration} from '../Configuration'; import {RangeOffset} from '../Types/RangeOffset'; import {ActionSelection} from './Selection'; import {ActionMoveCursor} from './MoveCursor'; @@ -11,10 +12,8 @@ import {UtilText} from '../Utils/Text'; export class ActionIndent { private static getIndentUnit(): string { - const options = window.activeTextEditor.options; - - if (options.insertSpaces) { - return ' '.repeat(options.tabSize as number); + if (Configuration.getInsertSpace()) { + return ' '.repeat(Configuration.getTabSize() as number); } else { return '\t'; @@ -28,8 +27,7 @@ export class ActionIndent { return 0; } - const options = window.activeTextEditor.options; - const tabSize = options.tabSize as number; + const tabSize = Configuration.getTabSize(); const line = document.lineAt(lineNumber); diff --git a/src/Configuration.ts b/src/Configuration.ts index f99e83d7..7122947d 100644 --- a/src/Configuration.ts +++ b/src/Configuration.ts @@ -1,4 +1,4 @@ -import {commands, workspace, WorkspaceConfiguration, Disposable} from 'vscode'; +import {commands, window, workspace, WorkspaceConfiguration, Disposable} from 'vscode'; import {UtilWord} from './Utils/Word'; export class Configuration { @@ -46,6 +46,34 @@ export class Configuration { return this.editorNamespace.get(section, defaultValue); } + /** + * Remarks: Workaround undefined bug in native API. + */ + static getInsertSpace(): boolean { + if (window.activeTextEditor) { + const options = window.activeTextEditor.options; + if (options.insertSpaces !== undefined) { + return options.insertSpaces as boolean; + } + } + + return this.getEditorSetting('insertSpaces'); + } + + /** + * Remarks: Workaround undefined bug in native API. + */ + static getTabSize(): number { + if (window.activeTextEditor) { + const options = window.activeTextEditor.options; + if (options.tabSize !== undefined) { + return options.tabSize as number; + } + } + + return this.getEditorSetting('tabSize'); + } + static dispose(): void { Disposable.from(...this.disposables).dispose(); }