Skip to content

Commit 9843623

Browse files
mjbvzbpasero
authored andcommitted
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
1 parent 4514ddd commit 9843623

File tree

4 files changed

+13
-16
lines changed

4 files changed

+13
-16
lines changed

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ export class SplitEditorAction extends Action {
6060
let options: EditorOptions;
6161
const codeEditor = getCodeEditor(editorToSplit);
6262
if (codeEditor) {
63-
options = new TextEditorOptions();
64-
(<TextEditorOptions>options).fromEditor(codeEditor);
63+
options = TextEditorOptions.fromEditor(codeEditor);
6564
} else {
6665
options = new EditorOptions();
6766
}
@@ -317,9 +316,7 @@ export abstract class BaseFocusSideGroupAction extends Action {
317316
let options: EditorOptions;
318317
const codeEditor = getCodeEditor(referenceEditor);
319318
if (codeEditor) {
320-
options = new TextEditorOptions();
321-
options.pinned = true;
322-
(<TextEditorOptions>options).fromEditor(codeEditor);
319+
options = TextEditorOptions.fromEditor(codeEditor, { pinned: true });
323320
} else {
324321
options = EditorOptions.create({ pinned: true });
325322
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,8 +1054,7 @@ export class EditorGroupsControl extends Themable implements IEditorGroupsContro
10541054
const activeEditor = $this.editorService.getActiveEditor();
10551055
const editor = getCodeEditor(activeEditor);
10561056
if (editor && activeEditor.position === stacks.positionOfGroup(identifier.group) && identifier.editor.matches(activeEditor.input)) {
1057-
options = TextEditorOptions.create({ pinned: true });
1058-
(<TextEditorOptions>options).fromEditor(editor);
1057+
options = TextEditorOptions.fromEditor(editor, { pinned: true });
10591058
}
10601059

10611060
return options;

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -878,8 +878,7 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
878878
const activeEditor = this.getActiveEditor();
879879
const codeEditor = getCodeEditor(activeEditor);
880880
if (codeEditor && activeEditor.position === this.stacks.positionOfGroup(fromGroup) && input.matches(activeEditor.input)) {
881-
options = TextEditorOptions.create({ pinned: true, index, inactive, preserveFocus });
882-
(<TextEditorOptions>options).fromEditor(codeEditor);
881+
options = TextEditorOptions.fromEditor(codeEditor, { pinned: true, index, inactive, preserveFocus });
883882
}
884883

885884
// A move to another group is an open first...

src/vs/workbench/common/editor.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -685,24 +685,26 @@ export class TextEditorOptions extends EditorOptions {
685685
}
686686

687687
/**
688-
* Sets the view state to be used when the editor is opening.
688+
* Create a TextEditorOptions inline to be used when the editor is opening.
689689
*/
690-
public fromEditor(editor: IEditor): void {
690+
public static fromEditor(editor: IEditor, settings?: IEditorOptions): TextEditorOptions {
691+
const options = TextEditorOptions.create(settings);
691692

692693
// View state
693-
this.editorViewState = editor.saveViewState();
694+
options.editorViewState = editor.saveViewState();
694695

695696
// Selected editor options
696697
const codeEditor = <ICommonCodeEditor>editor;
697698
if (typeof codeEditor.getConfiguration === 'function') {
698699
const config = codeEditor.getConfiguration();
699700
if (config && config.viewInfo && config.wrappingInfo) {
700-
this.editorOptions = Object.create(null);
701-
this.editorOptions.renderWhitespace = config.viewInfo.renderWhitespace;
702-
this.editorOptions.renderControlCharacters = config.viewInfo.renderControlCharacters;
703-
this.editorOptions.wordWrap = config.wrappingInfo.isViewportWrapping ? 'on' : 'off';
701+
options.editorOptions = Object.create(null);
702+
options.editorOptions.renderWhitespace = config.viewInfo.renderWhitespace;
703+
options.editorOptions.renderControlCharacters = config.viewInfo.renderControlCharacters;
704+
options.editorOptions.wordWrap = config.wrappingInfo.isViewportWrapping ? 'on' : 'off';
704705
}
705706
}
707+
return options;
706708
}
707709

708710
/**

0 commit comments

Comments
 (0)