Skip to content

Add option to move editors with workbench.editor.moveToActiveGroupIfOpen #205442

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/vs/workbench/browser/parts/editor/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export const DEFAULT_EDITOR_PART_OPTIONS: IEditorPartOptions = {
restoreViewState: true,
splitInGroupLayout: 'horizontal',
revealIfOpen: false,
revealIfOpenInActiveGroup: false,
// Properties that are Objects have to be defined as getters
// to ensure no consumer modifies the default values
get limit(): IEditorPartLimitOptions { return { enabled: false, value: 10, perEditorGroup: false, excludeDirty: false }; },
Expand Down Expand Up @@ -130,6 +131,7 @@ function validateEditorPartOptions(options: IEditorPartOptions): IEditorPartOpti
'closeOnFileDelete': new BooleanVerifier(DEFAULT_EDITOR_PART_OPTIONS['closeOnFileDelete']),
'closeEmptyGroups': new BooleanVerifier(DEFAULT_EDITOR_PART_OPTIONS['closeEmptyGroups']),
'revealIfOpen': new BooleanVerifier(DEFAULT_EDITOR_PART_OPTIONS['revealIfOpen']),
'revealIfOpenInActiveGroup': new BooleanVerifier(DEFAULT_EDITOR_PART_OPTIONS['revealIfOpenInActiveGroup']),
'mouseBackForwardToNavigate': new BooleanVerifier(DEFAULT_EDITOR_PART_OPTIONS['mouseBackForwardToNavigate']),
'restoreViewState': new BooleanVerifier(DEFAULT_EDITOR_PART_OPTIONS['restoreViewState']),
'splitOnDragAndDrop': new BooleanVerifier(DEFAULT_EDITOR_PART_OPTIONS['splitOnDragAndDrop']),
Expand Down
5 changes: 5 additions & 0 deletions src/vs/workbench/browser/workbench.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,11 @@ const registry = Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Con
'description': localize('revealIfOpen', "Controls whether an editor is revealed in any of the visible groups if opened. If disabled, an editor will prefer to open in the currently active editor group. If enabled, an already opened editor will be revealed instead of opened again in the currently active editor group. Note that there are some cases where this setting is ignored, such as when forcing an editor to open in a specific group or to the side of the currently active group."),
'default': false
},
'workbench.editor.revealIfOpenInActiveGroup': {
'type': 'boolean',
'markdownDescription': localize('revealIfOpenInActiveGroup', "Moves already opened editors to the active editor group when they are revealed. Note that there are some cases where this setting is ignored, such as when the currently active group is locked. Only applies to `#workbench.editor.revealIfOpen#` is set."),
'default': false
},
'workbench.editor.mouseBackForwardToNavigate': {
'type': 'boolean',
'description': localize('mouseBackForwardToNavigate', "Enables the use of mouse buttons four and five for commands 'Go Back' and 'Go Forward'."),
Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/common/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1183,6 +1183,7 @@ interface IEditorPartConfiguration {
closeEmptyGroups?: boolean;
autoLockGroups?: Set<string>;
revealIfOpen?: boolean;
revealIfOpenInActiveGroup?: boolean;
mouseBackForwardToNavigate?: boolean;
labelFormat?: 'default' | 'short' | 'medium' | 'long';
restoreViewState?: boolean;
Expand Down
48 changes: 38 additions & 10 deletions src/vs/workbench/services/editor/common/editorGroupFinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,28 +114,56 @@ function doFindGroup(input: EditorInputWithOptions | IUntypedEditorInput, prefer
// We also try to reveal an editor if it has the `Singleton` capability which
// indicates that the same editor cannot be opened across groups.
if (!group) {
if (options?.revealIfOpened || configurationService.getValue<boolean>('workbench.editor.revealIfOpen') || (isEditorInput(editor) && editor.hasCapability(EditorInputCapabilities.Singleton))) {
let groupWithInputActive: IEditorGroup | undefined = undefined;
let groupWithInputOpened: IEditorGroup | undefined = undefined;
const revealIfOpen = configurationService.getValue<boolean>('workbench.editor.revealIfOpen');

if (options?.revealIfOpened || revealIfOpen || (isEditorInput(editor) && editor.hasCapability(EditorInputCapabilities.Singleton))) {
let groupAndEditorWithInputActive: [IEditorGroup, EditorInput] | undefined = undefined;
let groupAndEditorWithInputOpened: [IEditorGroup, EditorInput] | undefined = undefined;

for (const group of groupsByLastActive) {
if (isOpened(group, editor)) {
if (!groupWithInputOpened) {
groupWithInputOpened = group;
let typedEditor: EditorInput | undefined = undefined;

for (const groupTypedEditor of group.editors) {
if (groupTypedEditor.matches(editor)) {
typedEditor = groupTypedEditor;
break;
}
}

if (typedEditor) {
if (!groupAndEditorWithInputOpened) {
groupAndEditorWithInputOpened = [group, typedEditor];
}

if (!groupWithInputActive && group.isActive(editor)) {
groupWithInputActive = group;
if (!groupAndEditorWithInputActive && group.isActive(editor)) {
groupAndEditorWithInputActive = [group, typedEditor];
}
}

if (groupWithInputOpened && groupWithInputActive) {
if (groupAndEditorWithInputOpened && groupAndEditorWithInputActive) {
break; // we found all groups we wanted
}
}

// Prefer a target group where the input is visible
group = groupWithInputActive || groupWithInputOpened;
const groupAndEditorWithInput = groupAndEditorWithInputActive || groupAndEditorWithInputOpened;

if (groupAndEditorWithInput) {
const [groupWithInput, typedEditor] = groupAndEditorWithInput;

const revealIfOpenInActiveGroup = configurationService.getValue<boolean>('workbench.editor.revealIfOpenInActiveGroup');

// If workbench.editor.revealIfOpenInActiveGroup is set,
// move editor to active group unless it is locked
if (revealIfOpen && revealIfOpenInActiveGroup && !isGroupLockedForEditor(editorGroupService.activeGroup, editor)) {
groupWithInput.moveEditor(typedEditor, editorGroupService.activeGroup);
group = editorGroupService.activeGroup;
}

else {
group = groupWithInput;
}
}
}
}
}
Expand Down