提交 98436234 编写于 作者: M Matt Bierner 提交者: Benjamin Pasero

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
上级 4514ddd1
......@@ -60,8 +60,7 @@ export class SplitEditorAction extends Action {
let options: EditorOptions;
const codeEditor = getCodeEditor(editorToSplit);
if (codeEditor) {
options = new TextEditorOptions();
(<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;
(<TextEditorOptions>options).fromEditor(codeEditor);
options = TextEditorOptions.fromEditor(codeEditor, { pinned: true });
} else {
options = EditorOptions.create({ pinned: true });
}
......
......@@ -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 });
(<TextEditorOptions>options).fromEditor(editor);
options = TextEditorOptions.fromEditor(editor, { pinned: true });
}
return options;
......
......@@ -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 });
(<TextEditorOptions>options).fromEditor(codeEditor);
options = TextEditorOptions.fromEditor(codeEditor, { pinned: true, index, inactive, preserveFocus });
}
// A move to another group is an open first...
......
......@@ -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 = <ICommonCodeEditor>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;
}
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册