mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-29 04:53:33 +01:00
Merge pull request #62079 from dlech/issue10339
add editor.indentSize option
This commit is contained in:
@@ -176,6 +176,7 @@ export interface MainThreadDocumentsShape extends IDisposable {
|
||||
|
||||
export interface ITextEditorConfigurationUpdate {
|
||||
tabSize?: number | 'auto';
|
||||
indentSize?: number | 'tabSize';
|
||||
insertSpaces?: boolean | 'auto';
|
||||
cursorStyle?: TextEditorCursorStyle;
|
||||
lineNumbers?: TextEditorLineNumbersStyle;
|
||||
@@ -183,6 +184,7 @@ export interface ITextEditorConfigurationUpdate {
|
||||
|
||||
export interface IResolvedTextEditorConfiguration {
|
||||
tabSize: number;
|
||||
indentSize: number;
|
||||
insertSpaces: boolean;
|
||||
cursorStyle: TextEditorCursorStyle;
|
||||
lineNumbers: TextEditorLineNumbersStyle;
|
||||
|
||||
@@ -142,6 +142,7 @@ export class ExtHostTextEditorOptions implements vscode.TextEditorOptions {
|
||||
private _id: string;
|
||||
|
||||
private _tabSize: number;
|
||||
private _indentSize: number;
|
||||
private _insertSpaces: boolean;
|
||||
private _cursorStyle: TextEditorCursorStyle;
|
||||
private _lineNumbers: TextEditorLineNumbersStyle;
|
||||
@@ -154,6 +155,7 @@ export class ExtHostTextEditorOptions implements vscode.TextEditorOptions {
|
||||
|
||||
public _accept(source: IResolvedTextEditorConfiguration): void {
|
||||
this._tabSize = source.tabSize;
|
||||
this._indentSize = source.indentSize;
|
||||
this._insertSpaces = source.insertSpaces;
|
||||
this._cursorStyle = source.cursorStyle;
|
||||
this._lineNumbers = source.lineNumbers;
|
||||
@@ -200,6 +202,47 @@ export class ExtHostTextEditorOptions implements vscode.TextEditorOptions {
|
||||
}));
|
||||
}
|
||||
|
||||
public get indentSize(): number | string {
|
||||
return this._indentSize;
|
||||
}
|
||||
|
||||
private _validateIndentSize(value: number | string): number | 'tabSize' | null {
|
||||
if (value === 'tabSize') {
|
||||
return 'tabSize';
|
||||
}
|
||||
if (typeof value === 'number') {
|
||||
let r = Math.floor(value);
|
||||
return (r > 0 ? r : null);
|
||||
}
|
||||
if (typeof value === 'string') {
|
||||
let r = parseInt(value, 10);
|
||||
if (isNaN(r)) {
|
||||
return null;
|
||||
}
|
||||
return (r > 0 ? r : null);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public set indentSize(value: number | string) {
|
||||
let indentSize = this._validateIndentSize(value);
|
||||
if (indentSize === null) {
|
||||
// ignore invalid call
|
||||
return;
|
||||
}
|
||||
if (typeof indentSize === 'number') {
|
||||
if (this._indentSize === indentSize) {
|
||||
// nothing to do
|
||||
return;
|
||||
}
|
||||
// reflect the new indentSize value immediately
|
||||
this._indentSize = indentSize;
|
||||
}
|
||||
warnOnError(this._proxy.$trySetOptions(this._id, {
|
||||
indentSize: indentSize
|
||||
}));
|
||||
}
|
||||
|
||||
public get insertSpaces(): boolean | string {
|
||||
return this._insertSpaces;
|
||||
}
|
||||
@@ -273,6 +316,19 @@ export class ExtHostTextEditorOptions implements vscode.TextEditorOptions {
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof newOptions.indentSize !== 'undefined') {
|
||||
let indentSize = this._validateIndentSize(newOptions.indentSize);
|
||||
if (indentSize === 'tabSize') {
|
||||
hasUpdate = true;
|
||||
bulkConfigurationUpdate.indentSize = indentSize;
|
||||
} else if (typeof indentSize === 'number' && this._indentSize !== indentSize) {
|
||||
// reflect the new indentSize value immediately
|
||||
this._indentSize = indentSize;
|
||||
hasUpdate = true;
|
||||
bulkConfigurationUpdate.indentSize = indentSize;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof newOptions.insertSpaces !== 'undefined') {
|
||||
let insertSpaces = this._validateInsertSpaces(newOptions.insertSpaces);
|
||||
if (insertSpaces === 'auto') {
|
||||
|
||||
Reference in New Issue
Block a user