diff --git a/src/vs/editor/contrib/indentation/browser/indentation.ts b/src/vs/editor/contrib/indentation/browser/indentation.ts index fcb7848bf4e634..68827ee71f2af5 100644 --- a/src/vs/editor/contrib/indentation/browser/indentation.ts +++ b/src/vs/editor/contrib/indentation/browser/indentation.ts @@ -25,6 +25,7 @@ import * as nls from 'vs/nls'; import { IQuickInputService } from 'vs/platform/quickinput/common/quickInput'; import { normalizeIndentation } from 'vs/editor/common/core/indentation'; import { getGoodIndentForLine, getIndentMetadata } from 'vs/editor/common/languages/autoIndent'; +import { ContextKeyExpr, ContextKeyFalseExpr } from 'vs/platform/contextkey/common/contextkey'; export function getReindentEditOperations(model: ITextModel, languageConfigurationService: ILanguageConfigurationService, startLineNumber: number, endLineNumber: number, inheritedIndent?: string): ISingleEditOperation[] { if (model.getLineCount() === 1 && model.getLineMaxColumn(1) === 1) { @@ -208,7 +209,7 @@ export class IndentationToTabsAction extends EditorAction { export class ChangeIndentationSizeAction extends EditorAction { - constructor(private readonly insertSpaces: boolean, opts: IActionOptions) { + constructor(private readonly insertSpaces: boolean, private readonly displaySizeOnly: boolean, opts: IActionOptions) { super(opts); } @@ -222,11 +223,20 @@ export class ChangeIndentationSizeAction extends EditorAction { } const creationOpts = modelService.getCreationOptions(model.getLanguageId(), model.uri, model.isForSimpleWidget); + const modelOpts = model.getOptions(); const picks = [1, 2, 3, 4, 5, 6, 7, 8].map(n => ({ id: n.toString(), label: n.toString(), // add description for tabSize value set in the configuration - description: n === creationOpts.tabSize ? nls.localize('configuredTabSize', "Configured Tab Size") : undefined + description: ( + n === creationOpts.tabSize && n === modelOpts.tabSize + ? nls.localize('configuredTabSize', "Configured Tab Size") + : n === creationOpts.tabSize + ? nls.localize('defaultTabSize', "Default Tab Size") + : n === modelOpts.tabSize + ? nls.localize('selectedTabSize', "Selected Tab Size") + : undefined + ) })); // auto focus the tabSize set for the current editor @@ -236,10 +246,18 @@ export class ChangeIndentationSizeAction extends EditorAction { quickInputService.pick(picks, { placeHolder: nls.localize({ key: 'selectTabWidth', comment: ['Tab corresponds to the tab key'] }, "Select Tab Size for Current File"), activeItem: picks[autoFocusIndex] }).then(pick => { if (pick) { if (model && !model.isDisposed()) { - model.updateOptions({ - tabSize: parseInt(pick.label, 10), - insertSpaces: this.insertSpaces - }); + const pickedVal = parseInt(pick.label, 10); + if (this.displaySizeOnly) { + model.updateOptions({ + tabSize: pickedVal + }); + } else { + model.updateOptions({ + tabSize: this.insertSpaces ? undefined : pickedVal, + indentSize: pickedVal, + insertSpaces: this.insertSpaces + }); + } } } }); @@ -252,7 +270,7 @@ export class IndentUsingTabs extends ChangeIndentationSizeAction { public static readonly ID = 'editor.action.indentUsingTabs'; constructor() { - super(false, { + super(false, false, { id: IndentUsingTabs.ID, label: nls.localize('indentUsingTabs', "Indent Using Tabs"), alias: 'Indent Using Tabs', @@ -266,7 +284,7 @@ export class IndentUsingSpaces extends ChangeIndentationSizeAction { public static readonly ID = 'editor.action.indentUsingSpaces'; constructor() { - super(true, { + super(true, false, { id: IndentUsingSpaces.ID, label: nls.localize('indentUsingSpaces', "Indent Using Spaces"), alias: 'Indent Using Spaces', @@ -275,6 +293,20 @@ export class IndentUsingSpaces extends ChangeIndentationSizeAction { } } +export class ChangeTabDisplaySize extends ChangeIndentationSizeAction { + + public static readonly ID = 'editor.action.changeTabDisplaySize'; + + constructor() { + super(true, true, { + id: ChangeTabDisplaySize.ID, + label: nls.localize('changeTabDisplaySize', "Change Tab Display Size"), + alias: 'Change Tab Display Size', + precondition: undefined + }); + } +} + export class DetectIndentation extends EditorAction { public static readonly ID = 'editor.action.detectIndentation'; @@ -694,6 +726,7 @@ registerEditorAction(IndentationToSpacesAction); registerEditorAction(IndentationToTabsAction); registerEditorAction(IndentUsingTabs); registerEditorAction(IndentUsingSpaces); +registerEditorAction(ChangeTabDisplaySize); registerEditorAction(DetectIndentation); registerEditorAction(ReindentLinesAction); registerEditorAction(ReindentSelectedLinesAction); diff --git a/src/vs/workbench/browser/parts/editor/editorStatus.ts b/src/vs/workbench/browser/parts/editor/editorStatus.ts index 48245d942a3ce6..47c43a0b3328c3 100644 --- a/src/vs/workbench/browser/parts/editor/editorStatus.ts +++ b/src/vs/workbench/browser/parts/editor/editorStatus.ts @@ -19,7 +19,7 @@ import { Disposable, MutableDisposable, DisposableStore } from 'vs/base/common/l import { IEditorAction } from 'vs/editor/common/editorCommon'; import { EndOfLineSequence } from 'vs/editor/common/model'; import { TrimTrailingWhitespaceAction } from 'vs/editor/contrib/linesOperations/browser/linesOperations'; -import { IndentUsingSpaces, IndentUsingTabs, DetectIndentation, IndentationToSpacesAction, IndentationToTabsAction } from 'vs/editor/contrib/indentation/browser/indentation'; +import { IndentUsingSpaces, IndentUsingTabs, ChangeTabDisplaySize, DetectIndentation, IndentationToSpacesAction, IndentationToTabsAction } from 'vs/editor/contrib/indentation/browser/indentation'; import { BaseBinaryResourceEditor } from 'vs/workbench/browser/parts/editor/binaryEditor'; import { BinaryResourceDiffEditor } from 'vs/workbench/browser/parts/editor/binaryDiffEditor'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; @@ -381,6 +381,7 @@ export class EditorStatus extends Disposable implements IWorkbenchContribution { const picks: QuickPickInput[] = [ activeTextEditorControl.getAction(IndentUsingSpaces.ID), activeTextEditorControl.getAction(IndentUsingTabs.ID), + activeTextEditorControl.getAction(ChangeTabDisplaySize.ID), activeTextEditorControl.getAction(DetectIndentation.ID), activeTextEditorControl.getAction(IndentationToSpacesAction.ID), activeTextEditorControl.getAction(IndentationToTabsAction.ID), @@ -756,7 +757,9 @@ export class EditorStatus extends Disposable implements IWorkbenchContribution { const modelOpts = model.getOptions(); update.indentation = ( modelOpts.insertSpaces - ? localize('spacesSize', "Spaces: {0}", modelOpts.indentSize) + ? modelOpts.tabSize === modelOpts.indentSize + ? localize('spacesSize', "Spaces: {0}", modelOpts.indentSize) + : localize('spacesAndTabsSize', "Spaces: {0} (Tab Size: {1})", modelOpts.indentSize, modelOpts.tabSize) : localize({ key: 'tabSize', comment: ['Tab corresponds to the tab key'] }, "Tab Size: {0}", modelOpts.tabSize) ); }