提交 273159c1 编写于 作者: B Benjamin Pasero

introduce option to reveal an editor (for #8714)

上级 e72019a5
......@@ -151,6 +151,12 @@ export interface IEditorOptions {
*/
forceOpen?: boolean;
/**
* Will reveal the editor if it is already opened in any editor group.
* This prevents duplicates of the same editor input showing up.
*/
revealIfOpened?: boolean;
/**
* An editor that is pinned remains in the editor stack even when another editor is being opened.
* An editor that is not pinned will always get replaced by another editor that is not pinned.
......
......@@ -192,7 +192,7 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
if (!options) { options = null; }
// Determine position to open editor in (left, center, right)
const position = this.validatePosition(arg3, widthRatios);
const position = this.findPosition(input, options, arg3, widthRatios);
// Some conditions under which we prevent the request
if (
......@@ -1151,9 +1151,9 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
super.dispose();
}
private validatePosition(sideBySide?: boolean, widthRatios?: number[]): Position;
private validatePosition(desiredPosition?: Position, widthRatios?: number[]): Position;
private validatePosition(arg1?: any, widthRatios?: number[]): Position {
private findPosition(input: EditorInput, options?: EditorOptions, sideBySide?: boolean, widthRatios?: number[]): Position;
private findPosition(input: EditorInput, options?: EditorOptions, desiredPosition?: Position, widthRatios?: number[]): Position;
private findPosition(input: EditorInput, options?: EditorOptions, arg1?: any, widthRatios?: number[]): Position {
// With defined width ratios, always trust the provided position
if (widthRatios && types.isNumber(arg1)) {
......@@ -1167,6 +1167,24 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
return Position.LEFT; // can only be LEFT
}
// Respect option to reveal an editor if it is already opened
if (options && options.revealIfOpened) {
if (typeof arg1 === 'number') {
const desiredGroup = this.stacks.groupAt(arg1);
if (desiredGroup && desiredGroup.contains(input)) {
return arg1;
}
}
const groups = this.stacks.groups;
for (let i = 0; i < groups.length; i++) {
const group = groups[i];
if (group.contains(input)) {
return this.stacks.positionOfGroup(group);
}
}
}
// Position is unknown: pick last active or LEFT
if (types.isUndefinedOrNull(arg1) || arg1 === false) {
let lastActivePosition = this.sideBySideControl.getActivePosition();
......
......@@ -430,6 +430,7 @@ export class EditorOptions implements IEditorOptions {
let options = new EditorOptions();
options.preserveFocus = settings.preserveFocus;
options.forceOpen = settings.forceOpen;
options.revealIfOpened = settings.revealIfOpened;
options.pinned = settings.pinned;
options.index = settings.index;
options.inactive = settings.inactive;
......@@ -443,6 +444,7 @@ export class EditorOptions implements IEditorOptions {
public mixin(other: EditorOptions): void {
this.preserveFocus = other.preserveFocus;
this.forceOpen = other.forceOpen;
this.revealIfOpened = other.revealIfOpened;
this.pinned = other.pinned;
this.index = other.index;
}
......@@ -460,6 +462,12 @@ export class EditorOptions implements IEditorOptions {
*/
public forceOpen: boolean;
/**
* Will reveal the editor if it is already opened in any editor group.
* This prevents duplicates of the same editor input showing up.
*/
public revealIfOpened: boolean;
/**
* An editor that is pinned remains in the editor stack even when another editor is being opened.
* An editor that is not pinned will always get replaced by another editor that is not pinned.
......@@ -482,16 +490,16 @@ export class EditorOptions implements IEditorOptions {
* Base Text Editor Options.
*/
export class TextEditorOptions extends EditorOptions {
private startLineNumber: number;
private startColumn: number;
private endLineNumber: number;
private endColumn: number;
protected startLineNumber: number;
protected startColumn: number;
protected endLineNumber: number;
protected endColumn: number;
private editorViewState: IEditorViewState;
public static from(input: IResourceInput): TextEditorOptions {
let options: TextEditorOptions = null;
if (input && input.options) {
if (input.options.selection || input.options.forceOpen || input.options.preserveFocus || input.options.pinned || input.options.inactive || typeof input.options.index === 'number') {
if (input.options.selection || input.options.forceOpen || input.options.revealIfOpened || input.options.preserveFocus || input.options.pinned || input.options.inactive || typeof input.options.index === 'number') {
options = new TextEditorOptions();
}
......@@ -504,6 +512,10 @@ export class TextEditorOptions extends EditorOptions {
options.forceOpen = true;
}
if (input.options.revealIfOpened) {
options.revealIfOpened = true;
}
if (input.options.preserveFocus) {
options.preserveFocus = true;
}
......@@ -531,6 +543,7 @@ export class TextEditorOptions extends EditorOptions {
let options = new TextEditorOptions();
options.preserveFocus = settings.preserveFocus;
options.forceOpen = settings.forceOpen;
options.revealIfOpened = settings.revealIfOpened;
options.pinned = settings.pinned;
options.index = settings.index;
......@@ -616,6 +629,15 @@ export class TextEditorOptions extends EditorOptions {
}
}
export interface ITextDiffEditorOptions extends ITextEditorOptions {
/**
* Whether to auto reveal the first change when the text editor is opened or not. By default
* the first change will not be revealed.
*/
autoRevealFirstChange: boolean;
}
/**
* Base Text Diff Editor Options.
*/
......@@ -624,11 +646,23 @@ export class TextDiffEditorOptions extends TextEditorOptions {
/**
* Helper to create TextDiffEditorOptions inline.
*/
public static create(settings: { autoRevealFirstChange?: boolean; preserveFocus?: boolean; forceOpen?: boolean; }): TextDiffEditorOptions {
public static create(settings: ITextDiffEditorOptions): TextDiffEditorOptions {
let options = new TextDiffEditorOptions();
options.autoRevealFirstChange = settings.autoRevealFirstChange;
options.preserveFocus = settings.preserveFocus;
options.forceOpen = settings.forceOpen;
options.revealIfOpened = settings.revealIfOpened;
options.pinned = settings.pinned;
options.index = settings.index;
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;
}
return options;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册