Skip to content

Commit 4b7774b

Browse files
committed
Update indentation action items and status bar text
Make the "Indent Using Spaces" action not affect the displayed tab width. Add a new "Change Tab Display Size" action to change that independently. If the indentSize and tabSize are different, show both in the status bar. Also for the indentation actions, replace the "Configured Tab Size" hint with a "Selected Tab Size" and "Default Tab Size" options, when it is ambiguous.
1 parent cd73b23 commit 4b7774b

File tree

2 files changed

+45
-10
lines changed

2 files changed

+45
-10
lines changed

src/vs/editor/contrib/indentation/browser/indentation.ts

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ export class IndentationToTabsAction extends EditorAction {
208208

209209
export class ChangeIndentationSizeAction extends EditorAction {
210210

211-
constructor(private readonly insertSpaces: boolean, opts: IActionOptions) {
211+
constructor(private readonly insertSpaces: boolean, private readonly displaySizeOnly: boolean, opts: IActionOptions) {
212212
super(opts);
213213
}
214214

@@ -222,11 +222,20 @@ export class ChangeIndentationSizeAction extends EditorAction {
222222
}
223223

224224
const creationOpts = modelService.getCreationOptions(model.getLanguageId(), model.uri, model.isForSimpleWidget);
225+
const modelOpts = model.getOptions();
225226
const picks = [1, 2, 3, 4, 5, 6, 7, 8].map(n => ({
226227
id: n.toString(),
227228
label: n.toString(),
228229
// add description for tabSize value set in the configuration
229-
description: n === creationOpts.tabSize ? nls.localize('configuredTabSize', "Configured Tab Size") : undefined
230+
description: (
231+
n === creationOpts.tabSize && n === modelOpts.tabSize
232+
? nls.localize('configuredTabSize', "Configured Tab Size")
233+
: n === creationOpts.tabSize
234+
? nls.localize('defaultTabSize', "Default Tab Size")
235+
: n === modelOpts.tabSize
236+
? nls.localize('selectedTabSize', "Selected Tab Size")
237+
: undefined
238+
)
230239
}));
231240

232241
// auto focus the tabSize set for the current editor
@@ -236,10 +245,18 @@ export class ChangeIndentationSizeAction extends EditorAction {
236245
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 => {
237246
if (pick) {
238247
if (model && !model.isDisposed()) {
239-
model.updateOptions({
240-
tabSize: parseInt(pick.label, 10),
241-
insertSpaces: this.insertSpaces
242-
});
248+
const pickedVal = parseInt(pick.label, 10);
249+
if (this.displaySizeOnly) {
250+
model.updateOptions({
251+
tabSize: pickedVal
252+
});
253+
} else {
254+
model.updateOptions({
255+
tabSize: this.insertSpaces ? undefined : pickedVal,
256+
indentSize: pickedVal,
257+
insertSpaces: this.insertSpaces
258+
});
259+
}
243260
}
244261
}
245262
});
@@ -252,7 +269,7 @@ export class IndentUsingTabs extends ChangeIndentationSizeAction {
252269
public static readonly ID = 'editor.action.indentUsingTabs';
253270

254271
constructor() {
255-
super(false, {
272+
super(false, false, {
256273
id: IndentUsingTabs.ID,
257274
label: nls.localize('indentUsingTabs', "Indent Using Tabs"),
258275
alias: 'Indent Using Tabs',
@@ -266,7 +283,7 @@ export class IndentUsingSpaces extends ChangeIndentationSizeAction {
266283
public static readonly ID = 'editor.action.indentUsingSpaces';
267284

268285
constructor() {
269-
super(true, {
286+
super(true, false, {
270287
id: IndentUsingSpaces.ID,
271288
label: nls.localize('indentUsingSpaces', "Indent Using Spaces"),
272289
alias: 'Indent Using Spaces',
@@ -275,6 +292,20 @@ export class IndentUsingSpaces extends ChangeIndentationSizeAction {
275292
}
276293
}
277294

295+
export class ChangeTabDisplaySize extends ChangeIndentationSizeAction {
296+
297+
public static readonly ID = 'editor.action.changeTabDisplaySize';
298+
299+
constructor() {
300+
super(true, true, {
301+
id: ChangeTabDisplaySize.ID,
302+
label: nls.localize('changeTabDisplaySize', "Change Tab Display Size"),
303+
alias: 'Change Tab Display Size',
304+
precondition: undefined
305+
});
306+
}
307+
}
308+
278309
export class DetectIndentation extends EditorAction {
279310

280311
public static readonly ID = 'editor.action.detectIndentation';
@@ -694,6 +725,7 @@ registerEditorAction(IndentationToSpacesAction);
694725
registerEditorAction(IndentationToTabsAction);
695726
registerEditorAction(IndentUsingTabs);
696727
registerEditorAction(IndentUsingSpaces);
728+
registerEditorAction(ChangeTabDisplaySize);
697729
registerEditorAction(DetectIndentation);
698730
registerEditorAction(ReindentLinesAction);
699731
registerEditorAction(ReindentSelectedLinesAction);

src/vs/workbench/browser/parts/editor/editorStatus.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { Disposable, MutableDisposable, DisposableStore } from 'vs/base/common/l
1919
import { IEditorAction } from 'vs/editor/common/editorCommon';
2020
import { EndOfLineSequence } from 'vs/editor/common/model';
2121
import { TrimTrailingWhitespaceAction } from 'vs/editor/contrib/linesOperations/browser/linesOperations';
22-
import { IndentUsingSpaces, IndentUsingTabs, DetectIndentation, IndentationToSpacesAction, IndentationToTabsAction } from 'vs/editor/contrib/indentation/browser/indentation';
22+
import { IndentUsingSpaces, IndentUsingTabs, ChangeTabDisplaySize, DetectIndentation, IndentationToSpacesAction, IndentationToTabsAction } from 'vs/editor/contrib/indentation/browser/indentation';
2323
import { BaseBinaryResourceEditor } from 'vs/workbench/browser/parts/editor/binaryEditor';
2424
import { BinaryResourceDiffEditor } from 'vs/workbench/browser/parts/editor/binaryDiffEditor';
2525
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
@@ -381,6 +381,7 @@ export class EditorStatus extends Disposable implements IWorkbenchContribution {
381381
const picks: QuickPickInput<IQuickPickItem & { run(): void }>[] = [
382382
activeTextEditorControl.getAction(IndentUsingSpaces.ID),
383383
activeTextEditorControl.getAction(IndentUsingTabs.ID),
384+
activeTextEditorControl.getAction(ChangeTabDisplaySize.ID),
384385
activeTextEditorControl.getAction(DetectIndentation.ID),
385386
activeTextEditorControl.getAction(IndentationToSpacesAction.ID),
386387
activeTextEditorControl.getAction(IndentationToTabsAction.ID),
@@ -756,7 +757,9 @@ export class EditorStatus extends Disposable implements IWorkbenchContribution {
756757
const modelOpts = model.getOptions();
757758
update.indentation = (
758759
modelOpts.insertSpaces
759-
? localize('spacesSize', "Spaces: {0}", modelOpts.indentSize)
760+
? modelOpts.tabSize === modelOpts.indentSize
761+
? localize('spacesSize', "Spaces: {0}", modelOpts.indentSize)
762+
: localize('spacesAndTabsSize', "Spaces: {0} (Tab Size: {1})", modelOpts.indentSize, modelOpts.tabSize)
760763
: localize({ key: 'tabSize', comment: ['Tab corresponds to the tab key'] }, "Tab Size: {0}", modelOpts.tabSize)
761764
);
762765
}

0 commit comments

Comments
 (0)