Skip to content
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

Tabs Multi Select Polish #212930

Merged
merged 29 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from 17 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
10 changes: 5 additions & 5 deletions src/vs/workbench/browser/parts/editor/editor.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
TextCompareEditorActiveContext, ActiveEditorPinnedContext, EditorGroupEditorsCountContext, ActiveEditorStickyContext, ActiveEditorAvailableEditorIdsContext,
EditorPartMultipleEditorGroupsContext, ActiveEditorDirtyContext, ActiveEditorGroupLockedContext, ActiveEditorCanSplitInGroupContext, SideBySideEditorActiveContext,
EditorTabsVisibleContext, ActiveEditorLastInGroupContext, EditorPartMaximizedEditorGroupContext, MultipleEditorGroupsContext, InEditorZenModeContext,
IsAuxiliaryEditorPartContext, ActiveCompareEditorCanSwapContext, MultipleEditorsSelectedContext
IsAuxiliaryEditorPartContext, ActiveCompareEditorCanSwapContext, MultipleEditorsSelectedInGroupContext
} from 'vs/workbench/common/contextkeys';
import { SideBySideEditorInput, SideBySideEditorInputSerializer } from 'vs/workbench/common/editor/sideBySideEditorInput';
import { TextResourceEditor } from 'vs/workbench/browser/parts/editor/textResourceEditor';
Expand Down Expand Up @@ -388,7 +388,7 @@ MenuRegistry.appendMenuItem(MenuId.EditorActionsPositionSubmenu, { command: { id
// Editor Title Context Menu
MenuRegistry.appendMenuItem(MenuId.EditorTitleContext, { command: { id: CLOSE_EDITOR_COMMAND_ID, title: localize('close', "Close") }, group: '1_close', order: 10 });
MenuRegistry.appendMenuItem(MenuId.EditorTitleContext, { command: { id: CLOSE_OTHER_EDITORS_IN_GROUP_COMMAND_ID, title: localize('closeOthers', "Close Others"), precondition: EditorGroupEditorsCountContext.notEqualsTo('1') }, group: '1_close', order: 20 });
MenuRegistry.appendMenuItem(MenuId.EditorTitleContext, { command: { id: CLOSE_EDITORS_TO_THE_RIGHT_COMMAND_ID, title: localize('closeRight', "Close to the Right"), precondition: ContextKeyExpr.and(ActiveEditorLastInGroupContext.toNegated(), MultipleEditorsSelectedContext.negate()) }, group: '1_close', order: 30, when: EditorTabsVisibleContext });
MenuRegistry.appendMenuItem(MenuId.EditorTitleContext, { command: { id: CLOSE_EDITORS_TO_THE_RIGHT_COMMAND_ID, title: localize('closeRight', "Close to the Right"), precondition: ContextKeyExpr.and(ActiveEditorLastInGroupContext.toNegated(), MultipleEditorsSelectedInGroupContext.negate()) }, group: '1_close', order: 30, when: EditorTabsVisibleContext });
MenuRegistry.appendMenuItem(MenuId.EditorTitleContext, { command: { id: CLOSE_SAVED_EDITORS_COMMAND_ID, title: localize('closeAllSaved', "Close Saved") }, group: '1_close', order: 40 });
MenuRegistry.appendMenuItem(MenuId.EditorTitleContext, { command: { id: CLOSE_EDITORS_IN_GROUP_COMMAND_ID, title: localize('closeAll', "Close All") }, group: '1_close', order: 50 });
MenuRegistry.appendMenuItem(MenuId.EditorTitleContext, { command: { id: REOPEN_WITH_COMMAND_ID, title: localize('reopenWith', "Reopen Editor With...") }, group: '1_open', order: 10, when: ActiveEditorAvailableEditorIdsContext });
Expand All @@ -399,11 +399,11 @@ MenuRegistry.appendMenuItem(MenuId.EditorTitleContext, { command: { id: SPLIT_ED
MenuRegistry.appendMenuItem(MenuId.EditorTitleContext, { command: { id: SPLIT_EDITOR_DOWN, title: localize('splitDown', "Split Down") }, group: '5_split', order: 20 });
MenuRegistry.appendMenuItem(MenuId.EditorTitleContext, { command: { id: SPLIT_EDITOR_LEFT, title: localize('splitLeft', "Split Left") }, group: '5_split', order: 30 });
MenuRegistry.appendMenuItem(MenuId.EditorTitleContext, { command: { id: SPLIT_EDITOR_RIGHT, title: localize('splitRight', "Split Right") }, group: '5_split', order: 40 });
MenuRegistry.appendMenuItem(MenuId.EditorTitleContext, { command: { id: SPLIT_EDITOR_IN_GROUP, title: localize('splitInGroup', "Split in Group"), precondition: MultipleEditorsSelectedContext.negate() }, group: '6_split_in_group', order: 10, when: ActiveEditorCanSplitInGroupContext });
MenuRegistry.appendMenuItem(MenuId.EditorTitleContext, { command: { id: JOIN_EDITOR_IN_GROUP, title: localize('joinInGroup', "Join in Group"), precondition: MultipleEditorsSelectedContext.negate() }, group: '6_split_in_group', order: 10, when: SideBySideEditorActiveContext });
MenuRegistry.appendMenuItem(MenuId.EditorTitleContext, { command: { id: SPLIT_EDITOR_IN_GROUP, title: localize('splitInGroup', "Split in Group"), precondition: MultipleEditorsSelectedInGroupContext.negate() }, group: '6_split_in_group', order: 10, when: ActiveEditorCanSplitInGroupContext });
MenuRegistry.appendMenuItem(MenuId.EditorTitleContext, { command: { id: JOIN_EDITOR_IN_GROUP, title: localize('joinInGroup', "Join in Group"), precondition: MultipleEditorsSelectedInGroupContext.negate() }, group: '6_split_in_group', order: 10, when: SideBySideEditorActiveContext });
MenuRegistry.appendMenuItem(MenuId.EditorTitleContext, { command: { id: MOVE_EDITOR_INTO_NEW_WINDOW_COMMAND_ID, title: localize('moveToNewWindow', "Move into New Window") }, group: '7_new_window', order: 10 });
MenuRegistry.appendMenuItem(MenuId.EditorTitleContext, { command: { id: COPY_EDITOR_INTO_NEW_WINDOW_COMMAND_ID, title: localize('copyToNewWindow', "Copy into New Window") }, group: '7_new_window', order: 20 });
MenuRegistry.appendMenuItem(MenuId.EditorTitleContext, { submenu: MenuId.EditorTitleContextShare, title: localize('share', "Share"), group: '11_share', order: -1, when: MultipleEditorsSelectedContext.negate() });
MenuRegistry.appendMenuItem(MenuId.EditorTitleContext, { submenu: MenuId.EditorTitleContextShare, title: localize('share', "Share"), group: '11_share', order: -1, when: MultipleEditorsSelectedInGroupContext.negate() });

// Editor Title Menu
MenuRegistry.appendMenuItem(MenuId.EditorTitle, { command: { id: TOGGLE_DIFF_SIDE_BY_SIDE, title: localize('inlineView', "Inline View"), toggled: ContextKeyExpr.equals('config.diffEditor.renderSideBySide', false) }, group: '1_diff', order: 10, when: ContextKeyExpr.has('isInDiffEditor') });
Expand Down
8 changes: 6 additions & 2 deletions src/vs/workbench/browser/parts/editor/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,13 @@ export interface IInternalEditorOpenOptions extends IInternalEditorTitleControlO
readonly preserveWindowOrder?: boolean;

/**
* Whether to add the editor to the selection or not.
* Whether to add the editor to the current selection or not.
bpasero marked this conversation as resolved.
Show resolved Hide resolved
* Unless the editor opens inactive, by default the current
* selected will be replaced unless `addToSelection` is set
* to `true`. In that case, the editor will be added to the
* selection, irrespective if it opens active or inactive.
*/
readonly selected?: boolean;
readonly addToSelection?: boolean;
}

export interface IInternalEditorCloseOptions extends IInternalEditorTitleControlOptions {
Expand Down
25 changes: 11 additions & 14 deletions src/vs/workbench/browser/parts/editor/editorActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { IWorkbenchLayoutService, Parts } from 'vs/workbench/services/layout/bro
import { GoFilter, IHistoryService } from 'vs/workbench/services/history/common/history';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { CLOSE_EDITOR_COMMAND_ID, MOVE_ACTIVE_EDITOR_COMMAND_ID, ActiveEditorMoveCopyArguments, SPLIT_EDITOR_LEFT, SPLIT_EDITOR_RIGHT, SPLIT_EDITOR_UP, SPLIT_EDITOR_DOWN, splitEditor, LAYOUT_EDITOR_GROUPS_COMMAND_ID, UNPIN_EDITOR_COMMAND_ID, COPY_ACTIVE_EDITOR_COMMAND_ID, SPLIT_EDITOR, resolveCommandsContext, getCommandsContext, TOGGLE_MAXIMIZE_EDITOR_GROUP, MOVE_EDITOR_INTO_NEW_WINDOW_COMMAND_ID, COPY_EDITOR_INTO_NEW_WINDOW_COMMAND_ID, MOVE_EDITOR_GROUP_INTO_NEW_WINDOW_COMMAND_ID, COPY_EDITOR_GROUP_INTO_NEW_WINDOW_COMMAND_ID, NEW_EMPTY_EDITOR_WINDOW_COMMAND_ID as NEW_EMPTY_EDITOR_WINDOW_COMMAND_ID, getEditorsFromContext } from 'vs/workbench/browser/parts/editor/editorCommands';
import { CLOSE_EDITOR_COMMAND_ID, MOVE_ACTIVE_EDITOR_COMMAND_ID, ActiveEditorMoveCopyArguments, SPLIT_EDITOR_LEFT, SPLIT_EDITOR_RIGHT, SPLIT_EDITOR_UP, SPLIT_EDITOR_DOWN, splitEditor, LAYOUT_EDITOR_GROUPS_COMMAND_ID, UNPIN_EDITOR_COMMAND_ID, COPY_ACTIVE_EDITOR_COMMAND_ID, SPLIT_EDITOR, resolveCommandsContext, getCommandsContext, TOGGLE_MAXIMIZE_EDITOR_GROUP, MOVE_EDITOR_INTO_NEW_WINDOW_COMMAND_ID, COPY_EDITOR_INTO_NEW_WINDOW_COMMAND_ID, MOVE_EDITOR_GROUP_INTO_NEW_WINDOW_COMMAND_ID, COPY_EDITOR_GROUP_INTO_NEW_WINDOW_COMMAND_ID, NEW_EMPTY_EDITOR_WINDOW_COMMAND_ID as NEW_EMPTY_EDITOR_WINDOW_COMMAND_ID, resolveEditorsContext, getEditorsContext } from 'vs/workbench/browser/parts/editor/editorCommands';
import { IEditorGroupsService, IEditorGroup, GroupsArrangement, GroupLocation, GroupDirection, preferredSideBySideGroupDirection, IFindGroupScope, GroupOrientation, EditorGroupLayout, GroupsOrder, MergeGroupMode } from 'vs/workbench/services/editor/common/editorGroupsService';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
Expand Down Expand Up @@ -65,7 +65,8 @@ abstract class AbstractSplitEditorAction extends Action2 {
const editorGroupService = accessor.get(IEditorGroupsService);
const configurationService = accessor.get(IConfigurationService);

splitEditor(editorGroupService, this.getDirection(configurationService), [getCommandsContext(accessor, resourceOrContext, context)]);
const commandContext = getCommandsContext(accessor, resourceOrContext, context);
splitEditor(editorGroupService, this.getDirection(configurationService), commandContext ? [commandContext] : undefined);
}
}

Expand Down Expand Up @@ -2514,23 +2515,19 @@ abstract class BaseMoveCopyEditorToNewWindowAction extends Action2 {

override async run(accessor: ServicesAccessor, resourceOrContext?: URI | IEditorCommandsContext, context?: IEditorCommandsContext) {
const editorGroupService = accessor.get(IEditorGroupsService);
const editors = getEditorsFromContext(accessor, resourceOrContext, context);

// If there is no editor, do not create a new window
if (editors.length === 0) {
const editorsContext = resolveEditorsContext(getEditorsContext(accessor, resourceOrContext, context));
if (editorsContext.length === 0) {
return;
}

const auxiliaryEditorPart = await editorGroupService.createAuxiliaryEditorPart();

for (const { editor, group } of editors) {
if (group && editor) {
if (this.move) {
group.moveEditor(editor, auxiliaryEditorPart.activeGroup);
} else {
group.copyEditor(editor, auxiliaryEditorPart.activeGroup);
}
}
const sourceGroup = editorsContext[0].group; // only single group supported for move/copy for now
const sourceEditors = editorsContext.filter(({ group }) => group === sourceGroup);
if (this.move) {
sourceGroup.moveEditors(sourceEditors, auxiliaryEditorPart.activeGroup);
} else {
sourceGroup.copyEditors(sourceEditors, auxiliaryEditorPart.activeGroup);
}

auxiliaryEditorPart.activeGroup.focus();
Expand Down
58 changes: 23 additions & 35 deletions src/vs/workbench/browser/parts/editor/editorCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ function registerFocusEditorGroupAtIndexCommands(): void {
}
}

export function splitEditor(editorGroupService: IEditorGroupsService, direction: GroupDirection, contexts?: (IEditorCommandsContext | URI | undefined)[]): void {
export function splitEditor(editorGroupService: IEditorGroupsService, direction: GroupDirection, contexts?: (IEditorCommandsContext | URI)[]): void {
bpasero marked this conversation as resolved.
Show resolved Hide resolved
let newGroup: IEditorGroup | undefined;

for (const context of contexts ?? [undefined]) {
Expand Down Expand Up @@ -897,7 +897,7 @@ function registerCloseEditorCommands() {
const editorResolverService = accessor.get(IEditorResolverService);
const telemetryService = accessor.get(ITelemetryService);

const editorsAndGroup = getEditorsFromContext(accessor, resourceOrContext, context);
const editorsAndGroup = resolveEditorsContext(getEditorsContext(accessor, resourceOrContext, context));
const editorReplacements = new Map<IEditorGroup, IEditorReplacement[]>();

for (const { editor, group } of editorsAndGroup) {
bpasero marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -912,11 +912,13 @@ function registerCloseEditorCommands() {
return;
}

if (!editorReplacements.has(group)) {
editorReplacements.set(group, []);
let editorReplacementsInGroup = editorReplacements.get(group);
if (!editorReplacementsInGroup) {
editorReplacementsInGroup = [];
editorReplacements.set(group, editorReplacementsInGroup);
}

editorReplacements.get(group)?.push({
editorReplacementsInGroup.push({
editor: editor,
replacement: resolvedEditor.editor,
forceReplaceDirty: editor.resource?.scheme === Schemas.untitled,
Expand Down Expand Up @@ -948,18 +950,11 @@ function registerCloseEditorCommands() {
});
}

// Replace editor with resolved one
let group: IEditorGroup | undefined, replacements: IEditorReplacement[] | undefined;
for ([group, replacements] of editorReplacements) {
// Replace editor with resolved one and make active
for (const [group, replacements] of editorReplacements) {
await group.replaceEditors(replacements);
await group.openEditor(replacements[0].replacement);
}

if (!group || !replacements) {
return;
}

// Make sure it becomes active too
await group?.openEditor(replacements[0].replacement);
}
});

Expand Down Expand Up @@ -1301,7 +1296,7 @@ function registerOtherEditorCommands(): void {
when: ActiveEditorStickyContext.toNegated(),
primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KeyK, KeyMod.Shift | KeyCode.Enter),
handler: async (accessor, resourceOrContext?: URI | IEditorCommandsContext, context?: IEditorCommandsContext) => {
for (const { editor, group } of getEditorsFromContext(accessor, resourceOrContext, context)) {
for (const { editor, group } of resolveEditorsContext(getEditorsContext(accessor, resourceOrContext, context))) {
group.stickEditor(editor);
}
}
Expand Down Expand Up @@ -1340,7 +1335,7 @@ function registerOtherEditorCommands(): void {
when: ActiveEditorStickyContext,
primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KeyK, KeyMod.Shift | KeyCode.Enter),
handler: async (accessor, resourceOrContext?: URI | IEditorCommandsContext, context?: IEditorCommandsContext) => {
for (const { editor, group } of getEditorsFromContext(accessor, resourceOrContext, context)) {
for (const { editor, group } of resolveEditorsContext(getEditorsContext(accessor, resourceOrContext, context))) {
group.unstickEditor(editor);
}
}
Expand Down Expand Up @@ -1368,7 +1363,8 @@ function registerOtherEditorCommands(): void {
});
}

function getEditorsContext(accessor: ServicesAccessor, resourceOrContext?: URI | IEditorCommandsContext, context?: IEditorCommandsContext): { editors: IEditorCommandsContext[]; groups: Array<IEditorGroup | undefined> } {
type EditorsContext = { editors: IEditorCommandsContext[]; groups: Array<IEditorGroup | undefined> };
benibenj marked this conversation as resolved.
Show resolved Hide resolved
export function getEditorsContext(accessor: ServicesAccessor, resourceOrContext?: URI | IEditorCommandsContext, context?: IEditorCommandsContext): EditorsContext {
const editorGroupService = accessor.get(IEditorGroupsService);
const listService = accessor.get(IListService);

Expand All @@ -1389,8 +1385,8 @@ function getEditorsContext(accessor: ServicesAccessor, resourceOrContext?: URI |
};
}

export function getEditorsFromContext(accessor: ServicesAccessor, resourceOrContext?: URI | IEditorCommandsContext, context?: IEditorCommandsContext): { editor: EditorInput; group: IEditorGroup }[] {
const { editors, groups } = getEditorsContext(accessor, resourceOrContext, context);
export function resolveEditorsContext(context: EditorsContext): { editor: EditorInput; group: IEditorGroup }[] {
benibenj marked this conversation as resolved.
Show resolved Hide resolved
const { editors, groups } = context;

const editorsAndGroup = editors.map(e => {
if (e.editorIndex === undefined) {
benibenj marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -1404,14 +1400,14 @@ export function getEditorsFromContext(accessor: ServicesAccessor, resourceOrCont
return { editor, group };
});

return editorsAndGroup.filter(group => !!group);
return coalesce(editorsAndGroup);
}

export function getCommandsContext(accessor: ServicesAccessor, resourceOrContext?: URI | IEditorCommandsContext, context?: IEditorCommandsContext): IEditorCommandsContext | undefined {
benibenj marked this conversation as resolved.
Show resolved Hide resolved
const isUri = URI.isUri(resourceOrContext);

const editorCommandsContext = isUri ? context : resourceOrContext ? resourceOrContext : context;
if (editorCommandsContext && typeof editorCommandsContext.groupId === 'number') {
if (editorCommandsContext) {
return editorCommandsContext;
}

Expand Down Expand Up @@ -1478,19 +1474,11 @@ export function getMultiSelectedEditorContexts(editorContext: IEditorCommandsCon
// Check editors selected in the group (tabs)
else {
const group = editorContext ? editorGroupService.getGroup(editorContext.groupId) : editorGroupService.activeGroup;
if (group) {
const selectedEditors: EditorInput[] = [];
// If context provides an editor index, use it
if (editorContext && editorContext.editorIndex !== undefined) {
const editor = group?.getEditorByIndex(editorContext.editorIndex);
if (editor && group.isSelected(editor)) {
selectedEditors.push(...group.selectedEditors);
}
} else {
selectedEditors.push(...group.selectedEditors);
}
if (selectedEditors.length > 1) {
return selectedEditors.map(se => ({ groupId: group.id, editorIndex: group.getIndexOfEditor(se) }));
const editor = editorContext && editorContext.editorIndex !== undefined ? group?.getEditorByIndex(editorContext.editorIndex) : group?.activeEditor;
benibenj marked this conversation as resolved.
Show resolved Hide resolved
// If the editor is selected, return all selected editors otherwise only use the editors context
if (group && editor) {
if (group.isSelected(editor)) {
return group.selectedEditors.map(se => ({ groupId: group.id, editorIndex: group.getIndexOfEditor(se) }));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/browser/parts/editor/editorDropTarget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,8 @@ class DropOverlay extends Themable {
{
editor: draggedEditor.identifier.editor,
options: fillActiveEditorViewState(sourceGroup, draggedEditor.identifier.editor, {
pinned: true, // always pin dropped editor
sticky: sourceGroup.isSticky(firstDraggedEditor.editor) // preserve sticky state
pinned: true, // always pin dropped editor
sticky: sourceGroup.isSticky(draggedEditor.identifier.editor) // preserve sticky state
})
}
));
Expand Down
Loading
Loading