Skip to content

Commit

Permalink
debt - simplify text editor options
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Jul 6, 2017
1 parent 93d755c commit 46057d3
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 100 deletions.
2 changes: 1 addition & 1 deletion src/vs/workbench/browser/parts/compositePart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ export abstract class CompositePart<T extends Composite> extends Part {

// Make sure that the user meanwhile did not open another composite or closed the part containing the composite
if (!this.activeComposite || composite.getId() !== this.activeComposite.getId()) {
return undefined;
return void 0;
}

// Take Composite on-DOM and show
Expand Down
3 changes: 2 additions & 1 deletion src/vs/workbench/browser/parts/editor/binaryEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ export abstract class BaseBinaryResourceEditor extends BaseEditor {
if (!didOpen) {
return this.windowsService.showItemInFolder(resource.fsPath);
}
return undefined;

return void 0;
});
},
(meta) => this.handleMetadataChanged(meta));
Expand Down
5 changes: 3 additions & 2 deletions src/vs/workbench/browser/parts/editor/editorActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ export class CloseAllEditorsAction extends Action {
// Otherwise ask for combined confirmation
const confirm = this.textFileService.confirmSave();
if (confirm === ConfirmResult.CANCEL) {
return undefined;
return void 0;
}

let saveOrRevertPromise: TPromise<boolean>;
Expand All @@ -686,7 +686,8 @@ export class CloseAllEditorsAction extends Action {
if (success) {
return this.editorService.closeAllEditors();
}
return undefined;

return void 0;
});
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/vs/workbench/browser/parts/editor/editorCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,8 @@ function registerOpenEditorAtIndexCommands(): void {
return editorService.openEditor(editor);
}
}
return undefined;

return void 0;
}
});
}
Expand All @@ -268,6 +269,7 @@ function registerOpenEditorAtIndexCommands(): void {
case 8: return KeyCode.KEY_8;
case 9: return KeyCode.KEY_9;
}
return undefined;

return void 0;
}
}
4 changes: 3 additions & 1 deletion src/vs/workbench/browser/parts/editor/sideBySideEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,13 @@ export class SideBySideEditor extends BaseEditor {
this.disposeEditors();
}
this.createEditorContainers();

return this.setNewInput(newInput, options);
} else {
this.detailsEditor.setInput(newInput.details);
this.masterEditor.setInput(newInput.master, options);
return undefined;

return void 0;
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/vs/workbench/browser/parts/editor/textResourceEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ export class TextResourceEditor extends BaseTextEditor {
if (!optionsGotApplied) {
this.restoreViewState(input);
}
return undefined;

return void 0;
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ export class QuickOpenController extends Component implements IQuickOpenService
if (valid && item) {
return lastValue === void 0 ? (options.value || '') : lastValue;
}
return undefined;

return void 0;
});
});
}
Expand Down
3 changes: 2 additions & 1 deletion src/vs/workbench/common/actionRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ export function triggerAndDisposeAction(instantitationService: IInstantiationSer
// don't run the action when not enabled
if (!actionInstance.enabled) {
actionInstance.dispose();
return undefined;

return void 0;
}

const from = args && args.from || 'keybinding';
Expand Down
115 changes: 35 additions & 80 deletions src/vs/workbench/common/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@ export class EditorOptions implements IEditorOptions {
*/
public static create(settings: IEditorOptions): EditorOptions {
const options = new EditorOptions();

options.preserveFocus = settings.preserveFocus;
options.forceOpen = settings.forceOpen;
options.revealIfVisible = settings.revealIfVisible;
Expand All @@ -518,21 +519,6 @@ export class EditorOptions implements IEditorOptions {
return options;
}

/**
* Inherit all options from other EditorOptions instance.
*/
public mixin(other: IEditorOptions): void {
if (other) {
this.preserveFocus = other.preserveFocus;
this.forceOpen = other.forceOpen;
this.revealIfVisible = other.revealIfVisible;
this.revealIfOpened = other.revealIfOpened;
this.pinned = other.pinned;
this.index = other.index;
this.inactive = other.inactive;
}
}

/**
* Tells the editor to not receive keyboard focus when the editor is being opened. By default,
* the editor will receive keyboard focus on open.
Expand Down Expand Up @@ -578,101 +564,70 @@ export class EditorOptions implements IEditorOptions {
* Base Text Editor Options.
*/
export class TextEditorOptions extends EditorOptions {
protected startLineNumber: number;
protected startColumn: number;
protected endLineNumber: number;
protected endColumn: number;
private startLineNumber: number;
private startColumn: number;
private endLineNumber: number;
private endColumn: number;

private revealInCenterIfOutsideViewport: boolean;
private editorViewState: IEditorViewState;

public static from(input: IBaseResourceInput): TextEditorOptions {
public static from(input?: IBaseResourceInput): TextEditorOptions {
if (!input || !input.options) {
return null;
}

let options: TextEditorOptions = null;
if (
input.options.selection ||
input.options.viewState ||
typeof input.options.forceOpen === 'boolean' ||
typeof input.options.revealIfVisible === 'boolean' ||
typeof input.options.revealIfOpened === 'boolean' ||
typeof input.options.preserveFocus === 'boolean' ||
typeof input.options.revealInCenterIfOutsideViewport === 'boolean' ||
typeof input.options.pinned === 'boolean' ||
typeof input.options.inactive === 'boolean' ||
typeof input.options.index === 'number'
) {
options = new TextEditorOptions();
}
return TextEditorOptions.create(input.options);
}

if (input.options.selection) {
const selection = input.options.selection;
options.selection(selection.startLineNumber, selection.startColumn, selection.endLineNumber, selection.endColumn);
}
/**
* Helper to convert options bag to real class
*/
public static create(options: ITextEditorOptions = Object.create(null)): TextEditorOptions {
const textEditorOptions = new TextEditorOptions();

if (input.options.viewState) {
options.editorViewState = input.options.viewState as IEditorViewState;
if (options.selection) {
const selection = options.selection;
textEditorOptions.selection(selection.startLineNumber, selection.startColumn, selection.endLineNumber, selection.endColumn);
}

if (input.options.forceOpen) {
options.forceOpen = true;
if (options.viewState) {
textEditorOptions.editorViewState = options.viewState as IEditorViewState;
}

if (input.options.revealIfVisible) {
options.revealIfVisible = true;
if (options.forceOpen) {
textEditorOptions.forceOpen = true;
}

if (input.options.revealIfOpened) {
options.revealIfOpened = true;
if (options.revealIfVisible) {
textEditorOptions.revealIfVisible = true;
}

if (input.options.preserveFocus) {
options.preserveFocus = true;
if (options.revealIfOpened) {
textEditorOptions.revealIfOpened = true;
}

if (input.options.revealInCenterIfOutsideViewport) {
options.revealInCenterIfOutsideViewport = true;
if (options.preserveFocus) {
textEditorOptions.preserveFocus = true;
}

if (input.options.pinned) {
options.pinned = true;
if (options.revealInCenterIfOutsideViewport) {
textEditorOptions.revealInCenterIfOutsideViewport = true;
}

if (input.options.inactive) {
options.inactive = true;
if (options.pinned) {
textEditorOptions.pinned = true;
}

if (typeof input.options.index === 'number') {
options.index = input.options.index;
if (options.inactive) {
textEditorOptions.inactive = true;
}

return options;
}

/**
* Helper to create TextEditorOptions inline.
*/
public static create(settings: ITextEditorOptions = Object.create(null)): TextEditorOptions {
const options = new TextEditorOptions();

options.preserveFocus = settings.preserveFocus;
options.forceOpen = settings.forceOpen;
options.revealIfVisible = settings.revealIfVisible;
options.revealIfOpened = settings.revealIfOpened;
options.pinned = settings.pinned;
options.index = settings.index;
options.inactive = settings.inactive;

if (settings.selection) {
options.startLineNumber = settings.selection.startLineNumber;
options.startColumn = settings.selection.startColumn;
options.endLineNumber = settings.selection.endLineNumber || settings.selection.startLineNumber;
options.endColumn = settings.selection.endColumn || settings.selection.startColumn;
if (typeof options.index === 'number') {
textEditorOptions.index = options.index;
}

return options;
return textEditorOptions;
}

/**
Expand Down
15 changes: 9 additions & 6 deletions src/vs/workbench/parts/files/browser/fileActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ export class TriggerRenameFileAction extends BaseFileAction {
});
}).done(null, errors.onUnexpectedError);

return undefined;
return void 0;
}
}

Expand Down Expand Up @@ -846,7 +846,7 @@ export class ImportFileAction extends BaseFileAction {
}

if (!overwrite) {
return undefined;
return void 0;
}

// Run import in sequence
Expand Down Expand Up @@ -879,7 +879,8 @@ export class ImportFileAction extends BaseFileAction {
return sequence(importPromisesFactory);
});
}
return undefined;

return void 0;
});

return importPromise.then(() => {
Expand Down Expand Up @@ -1042,7 +1043,8 @@ export class DuplicateFileAction extends BaseFileAction {
if (!stat.isDirectory) {
return this.editorService.openEditor({ resource: stat.resource, options: { pinned: true } });
}
return undefined;

return void 0;
}, error => this.onError(error));

return result;
Expand Down Expand Up @@ -1395,7 +1397,7 @@ export abstract class BaseSaveOneFileAction extends BaseSaveFileAction {

return savePromise.then((target) => {
if (!target || target.toString() === source.toString()) {
return undefined; // save canceled or same resource used
return void 0; // save canceled or same resource used
}

const replaceWith: IResourceInput = {
Expand Down Expand Up @@ -1566,7 +1568,8 @@ export abstract class BaseSaveAllAction extends BaseSaveFileAction {
if (untitledToReopen.length) {
return this.editorService.openEditors(untitledToReopen).then(() => true);
}
return undefined;

return void 0;
});
}

Expand Down
3 changes: 2 additions & 1 deletion src/vs/workbench/parts/files/browser/views/explorerView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,8 @@ export class ExplorerView extends CollapsibleView {
this.openFocusedElement();
});
}
return undefined;

return void 0;
});
}

Expand Down
7 changes: 4 additions & 3 deletions src/vs/workbench/services/textfile/common/textFileService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ export abstract class TextFileService implements ITextFileService {
// Otherwise just confirm from the user what to do with the dirty files
return this.confirmBeforeShutdown();
}
return undefined;

return void 0;
});
}

Expand Down Expand Up @@ -277,7 +278,7 @@ export abstract class TextFileService implements ITextFileService {
return true; // veto
}

return undefined;
return void 0;
}

private noVeto(options: { cleanUpBackups: boolean }): boolean | TPromise<boolean> {
Expand Down Expand Up @@ -663,7 +664,7 @@ export abstract class TextFileService implements ITextFileService {
return TPromise.wrapError(error);
}

return undefined;
return void 0;
});
})).then(r => {
return {
Expand Down

0 comments on commit 46057d3

Please sign in to comment.