From 9843623452cbb9eea0c57e2ccc371b4d2c3c2d37 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Tue, 16 May 2017 22:20:12 -0700 Subject: [PATCH] Make TextEditorOptions.fromEditor static (#26779) Refactors TextEditorOptions.fromEditor to a static method instead of an instance method. This method is only called after creation of the options object and currently requires using a weird cast in a few places --- .../browser/parts/editor/editorActions.ts | 7 ++----- .../browser/parts/editor/editorGroupsControl.ts | 3 +-- .../workbench/browser/parts/editor/editorPart.ts | 3 +-- src/vs/workbench/common/editor.ts | 16 +++++++++------- 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/vs/workbench/browser/parts/editor/editorActions.ts b/src/vs/workbench/browser/parts/editor/editorActions.ts index 4419e710283..f7f5e2e9b83 100644 --- a/src/vs/workbench/browser/parts/editor/editorActions.ts +++ b/src/vs/workbench/browser/parts/editor/editorActions.ts @@ -60,8 +60,7 @@ export class SplitEditorAction extends Action { let options: EditorOptions; const codeEditor = getCodeEditor(editorToSplit); if (codeEditor) { - options = new TextEditorOptions(); - (options).fromEditor(codeEditor); + options = TextEditorOptions.fromEditor(codeEditor); } else { options = new EditorOptions(); } @@ -317,9 +316,7 @@ export abstract class BaseFocusSideGroupAction extends Action { let options: EditorOptions; const codeEditor = getCodeEditor(referenceEditor); if (codeEditor) { - options = new TextEditorOptions(); - options.pinned = true; - (options).fromEditor(codeEditor); + options = TextEditorOptions.fromEditor(codeEditor, { pinned: true }); } else { options = EditorOptions.create({ pinned: true }); } diff --git a/src/vs/workbench/browser/parts/editor/editorGroupsControl.ts b/src/vs/workbench/browser/parts/editor/editorGroupsControl.ts index ea8e7c92f96..dea7059b171 100644 --- a/src/vs/workbench/browser/parts/editor/editorGroupsControl.ts +++ b/src/vs/workbench/browser/parts/editor/editorGroupsControl.ts @@ -1054,8 +1054,7 @@ export class EditorGroupsControl extends Themable implements IEditorGroupsContro const activeEditor = $this.editorService.getActiveEditor(); const editor = getCodeEditor(activeEditor); if (editor && activeEditor.position === stacks.positionOfGroup(identifier.group) && identifier.editor.matches(activeEditor.input)) { - options = TextEditorOptions.create({ pinned: true }); - (options).fromEditor(editor); + options = TextEditorOptions.fromEditor(editor, { pinned: true }); } return options; diff --git a/src/vs/workbench/browser/parts/editor/editorPart.ts b/src/vs/workbench/browser/parts/editor/editorPart.ts index bcddcea6c57..be76d1a4ff6 100644 --- a/src/vs/workbench/browser/parts/editor/editorPart.ts +++ b/src/vs/workbench/browser/parts/editor/editorPart.ts @@ -878,8 +878,7 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService const activeEditor = this.getActiveEditor(); const codeEditor = getCodeEditor(activeEditor); if (codeEditor && activeEditor.position === this.stacks.positionOfGroup(fromGroup) && input.matches(activeEditor.input)) { - options = TextEditorOptions.create({ pinned: true, index, inactive, preserveFocus }); - (options).fromEditor(codeEditor); + options = TextEditorOptions.fromEditor(codeEditor, { pinned: true, index, inactive, preserveFocus }); } // A move to another group is an open first... diff --git a/src/vs/workbench/common/editor.ts b/src/vs/workbench/common/editor.ts index 8636bc66ef0..12cf8f3ea74 100644 --- a/src/vs/workbench/common/editor.ts +++ b/src/vs/workbench/common/editor.ts @@ -685,24 +685,26 @@ export class TextEditorOptions extends EditorOptions { } /** - * Sets the view state to be used when the editor is opening. + * Create a TextEditorOptions inline to be used when the editor is opening. */ - public fromEditor(editor: IEditor): void { + public static fromEditor(editor: IEditor, settings?: IEditorOptions): TextEditorOptions { + const options = TextEditorOptions.create(settings); // View state - this.editorViewState = editor.saveViewState(); + options.editorViewState = editor.saveViewState(); // Selected editor options const codeEditor = editor; if (typeof codeEditor.getConfiguration === 'function') { const config = codeEditor.getConfiguration(); if (config && config.viewInfo && config.wrappingInfo) { - this.editorOptions = Object.create(null); - this.editorOptions.renderWhitespace = config.viewInfo.renderWhitespace; - this.editorOptions.renderControlCharacters = config.viewInfo.renderControlCharacters; - this.editorOptions.wordWrap = config.wrappingInfo.isViewportWrapping ? 'on' : 'off'; + options.editorOptions = Object.create(null); + options.editorOptions.renderWhitespace = config.viewInfo.renderWhitespace; + options.editorOptions.renderControlCharacters = config.viewInfo.renderControlCharacters; + options.editorOptions.wordWrap = config.wrappingInfo.isViewportWrapping ? 'on' : 'off'; } } + return options; } /** -- GitLab