Skip to content

Commit

Permalink
Update indentation action items and status bar text
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
zeroimpl committed Jul 19, 2022
1 parent 523743b commit 6544b75
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 10 deletions.
48 changes: 40 additions & 8 deletions src/vs/editor/contrib/indentation/browser/indentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,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);
}

Expand All @@ -222,11 +222,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
Expand All @@ -236,10 +245,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
});
}
}
}
});
Expand All @@ -252,7 +269,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',
Expand All @@ -266,7 +283,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',
Expand All @@ -275,6 +292,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';
Expand Down Expand Up @@ -694,6 +725,7 @@ registerEditorAction(IndentationToSpacesAction);
registerEditorAction(IndentationToTabsAction);
registerEditorAction(IndentUsingTabs);
registerEditorAction(IndentUsingSpaces);
registerEditorAction(ChangeTabDisplaySize);
registerEditorAction(DetectIndentation);
registerEditorAction(ReindentLinesAction);
registerEditorAction(ReindentSelectedLinesAction);
7 changes: 5 additions & 2 deletions src/vs/workbench/browser/parts/editor/editorStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -381,6 +381,7 @@ export class EditorStatus extends Disposable implements IWorkbenchContribution {
const picks: QuickPickInput<IQuickPickItem & { run(): void }>[] = [
activeTextEditorControl.getAction(IndentUsingSpaces.ID),
activeTextEditorControl.getAction(IndentUsingTabs.ID),
activeTextEditorControl.getAction(ChangeTabDisplaySize.ID),
activeTextEditorControl.getAction(DetectIndentation.ID),
activeTextEditorControl.getAction(IndentationToSpacesAction.ID),
activeTextEditorControl.getAction(IndentationToTabsAction.ID),
Expand Down Expand Up @@ -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)
);
}
Expand Down

0 comments on commit 6544b75

Please sign in to comment.