mirror of
https://github.com/Microsoft/vscode
synced 2024-10-04 02:14:06 +00:00
Fix split editor inactive group action (#212837)
* Fix split editor inactive group action * fix getCommandsContext
This commit is contained in:
parent
652c948b85
commit
c72bcdaa99
|
@ -61,11 +61,11 @@ abstract class AbstractSplitEditorAction extends Action2 {
|
||||||
return preferredSideBySideGroupDirection(configurationService);
|
return preferredSideBySideGroupDirection(configurationService);
|
||||||
}
|
}
|
||||||
|
|
||||||
override async run(accessor: ServicesAccessor, context?: IEditorIdentifier): Promise<void> {
|
override async run(accessor: ServicesAccessor, resourceOrContext?: URI | IEditorCommandsContext, context?: IEditorCommandsContext): Promise<void> {
|
||||||
const editorGroupService = accessor.get(IEditorGroupsService);
|
const editorGroupService = accessor.get(IEditorGroupsService);
|
||||||
const configurationService = accessor.get(IConfigurationService);
|
const configurationService = accessor.get(IConfigurationService);
|
||||||
|
|
||||||
splitEditor(editorGroupService, this.getDirection(configurationService), [context]);
|
splitEditor(editorGroupService, this.getDirection(configurationService), [getCommandsContext(accessor, resourceOrContext, context)]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1146,7 +1146,7 @@ export class ToggleMaximizeEditorGroupAction extends Action2 {
|
||||||
override async run(accessor: ServicesAccessor, resourceOrContext?: URI | IEditorCommandsContext, context?: IEditorCommandsContext): Promise<void> {
|
override async run(accessor: ServicesAccessor, resourceOrContext?: URI | IEditorCommandsContext, context?: IEditorCommandsContext): Promise<void> {
|
||||||
const editorGroupsService = accessor.get(IEditorGroupsService);
|
const editorGroupsService = accessor.get(IEditorGroupsService);
|
||||||
|
|
||||||
const { group } = resolveCommandsContext(editorGroupsService, getCommandsContext(resourceOrContext, context));
|
const { group } = resolveCommandsContext(editorGroupsService, getCommandsContext(accessor, resourceOrContext, context));
|
||||||
editorGroupsService.toggleMaximizeGroup(group);
|
editorGroupsService.toggleMaximizeGroup(group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ import { coalesce, distinct } from 'vs/base/common/arrays';
|
||||||
import { IJSONSchema } from 'vs/base/common/jsonSchema';
|
import { IJSONSchema } from 'vs/base/common/jsonSchema';
|
||||||
import { KeyChord, KeyCode, KeyMod } from 'vs/base/common/keyCodes';
|
import { KeyChord, KeyCode, KeyMod } from 'vs/base/common/keyCodes';
|
||||||
import { Schemas, matchesScheme } from 'vs/base/common/network';
|
import { Schemas, matchesScheme } from 'vs/base/common/network';
|
||||||
import { extname } from 'vs/base/common/resources';
|
import { extname, isEqual } from 'vs/base/common/resources';
|
||||||
import { isNumber, isObject, isString, isUndefined } from 'vs/base/common/types';
|
import { isNumber, isObject, isString, isUndefined } from 'vs/base/common/types';
|
||||||
import { URI, UriComponents } from 'vs/base/common/uri';
|
import { URI, UriComponents } from 'vs/base/common/uri';
|
||||||
import { isDiffEditor } from 'vs/editor/browser/editorBrowser';
|
import { isDiffEditor } from 'vs/editor/browser/editorBrowser';
|
||||||
|
@ -31,7 +31,7 @@ import { ActiveGroupEditorsByMostRecentlyUsedQuickAccess } from 'vs/workbench/br
|
||||||
import { SideBySideEditor } from 'vs/workbench/browser/parts/editor/sideBySideEditor';
|
import { SideBySideEditor } from 'vs/workbench/browser/parts/editor/sideBySideEditor';
|
||||||
import { TextDiffEditor } from 'vs/workbench/browser/parts/editor/textDiffEditor';
|
import { TextDiffEditor } from 'vs/workbench/browser/parts/editor/textDiffEditor';
|
||||||
import { ActiveEditorCanSplitInGroupContext, ActiveEditorGroupEmptyContext, ActiveEditorGroupLockedContext, ActiveEditorStickyContext, MultipleEditorGroupsContext, SideBySideEditorActiveContext, TextCompareEditorActiveContext } from 'vs/workbench/common/contextkeys';
|
import { ActiveEditorCanSplitInGroupContext, ActiveEditorGroupEmptyContext, ActiveEditorGroupLockedContext, ActiveEditorStickyContext, MultipleEditorGroupsContext, SideBySideEditorActiveContext, TextCompareEditorActiveContext } from 'vs/workbench/common/contextkeys';
|
||||||
import { CloseDirection, EditorInputCapabilities, EditorsOrder, IEditorCommandsContext, IEditorIdentifier, IResourceDiffEditorInput, IUntitledTextResourceEditorInput, IVisibleEditorPane, isEditorIdentifier, isEditorInputWithOptionsAndGroup } from 'vs/workbench/common/editor';
|
import { CloseDirection, EditorInputCapabilities, EditorsOrder, IEditorCommandsContext, IEditorIdentifier, IResourceDiffEditorInput, IUntitledTextResourceEditorInput, IVisibleEditorPane, isEditorCommandsContext, isEditorIdentifier, isEditorInputWithOptionsAndGroup } from 'vs/workbench/common/editor';
|
||||||
import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput';
|
import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput';
|
||||||
import { EditorInput } from 'vs/workbench/common/editor/editorInput';
|
import { EditorInput } from 'vs/workbench/common/editor/editorInput';
|
||||||
import { SideBySideEditorInput } from 'vs/workbench/common/editor/sideBySideEditorInput';
|
import { SideBySideEditorInput } from 'vs/workbench/common/editor/sideBySideEditorInput';
|
||||||
|
@ -656,13 +656,24 @@ function registerFocusEditorGroupAtIndexCommands(): void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function splitEditor(editorGroupService: IEditorGroupsService, direction: GroupDirection, contexts?: (IEditorCommandsContext | undefined)[]): void {
|
export function splitEditor(editorGroupService: IEditorGroupsService, direction: GroupDirection, contexts?: (IEditorCommandsContext | URI | undefined)[]): void {
|
||||||
let newGroup: IEditorGroup | undefined;
|
let newGroup: IEditorGroup | undefined;
|
||||||
|
|
||||||
for (const context of contexts ?? [undefined]) {
|
for (const context of contexts ?? [undefined]) {
|
||||||
let sourceGroup: IEditorGroup | undefined;
|
let sourceGroup: IEditorGroup | undefined;
|
||||||
if (context && typeof context.groupId === 'number') {
|
|
||||||
|
const isEditorCommand = context && isEditorCommandsContext(context);
|
||||||
|
const isURI = context && URI.isUri(context);
|
||||||
|
|
||||||
|
if (isEditorCommand) {
|
||||||
sourceGroup = editorGroupService.getGroup(context.groupId);
|
sourceGroup = editorGroupService.getGroup(context.groupId);
|
||||||
|
} else if (isURI) {
|
||||||
|
for (const group of editorGroupService.getGroups(GroupsOrder.MOST_RECENTLY_ACTIVE)) {
|
||||||
|
if (isEqual(group.activeEditor?.resource, context)) {
|
||||||
|
sourceGroup = group;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
sourceGroup = editorGroupService.activeGroup;
|
sourceGroup = editorGroupService.activeGroup;
|
||||||
}
|
}
|
||||||
|
@ -678,7 +689,7 @@ export function splitEditor(editorGroupService: IEditorGroupsService, direction:
|
||||||
|
|
||||||
// Split editor (if it can be split)
|
// Split editor (if it can be split)
|
||||||
let editorToCopy: EditorInput | undefined;
|
let editorToCopy: EditorInput | undefined;
|
||||||
if (context && typeof context.editorIndex === 'number') {
|
if (isEditorCommand && typeof context.editorIndex === 'number') {
|
||||||
editorToCopy = sourceGroup.getEditorByIndex(context.editorIndex);
|
editorToCopy = sourceGroup.getEditorByIndex(context.editorIndex);
|
||||||
} else {
|
} else {
|
||||||
editorToCopy = sourceGroup.activeEditor ?? undefined;
|
editorToCopy = sourceGroup.activeEditor ?? undefined;
|
||||||
|
@ -686,7 +697,7 @@ export function splitEditor(editorGroupService: IEditorGroupsService, direction:
|
||||||
|
|
||||||
// Copy the editor to the new group, else create an empty group
|
// Copy the editor to the new group, else create an empty group
|
||||||
if (editorToCopy && !editorToCopy.hasCapability(EditorInputCapabilities.Singleton)) {
|
if (editorToCopy && !editorToCopy.hasCapability(EditorInputCapabilities.Singleton)) {
|
||||||
sourceGroup.copyEditor(editorToCopy, newGroup, { preserveFocus: context?.preserveFocus });
|
sourceGroup.copyEditor(editorToCopy, newGroup, { preserveFocus: isEditorCommand && context?.preserveFocus });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -800,7 +811,7 @@ function registerCloseEditorCommands() {
|
||||||
win: { primary: KeyMod.CtrlCmd | KeyCode.F4, secondary: [KeyMod.CtrlCmd | KeyCode.KeyW] },
|
win: { primary: KeyMod.CtrlCmd | KeyCode.F4, secondary: [KeyMod.CtrlCmd | KeyCode.KeyW] },
|
||||||
handler: (accessor, resourceOrContext?: URI | IEditorCommandsContext, context?: IEditorCommandsContext) => {
|
handler: (accessor, resourceOrContext?: URI | IEditorCommandsContext, context?: IEditorCommandsContext) => {
|
||||||
const editorGroupService = accessor.get(IEditorGroupsService);
|
const editorGroupService = accessor.get(IEditorGroupsService);
|
||||||
const commandsContext = getCommandsContext(resourceOrContext, context);
|
const commandsContext = getCommandsContext(accessor, resourceOrContext, context);
|
||||||
|
|
||||||
let group: IEditorGroup | undefined;
|
let group: IEditorGroup | undefined;
|
||||||
if (commandsContext && typeof commandsContext.groupId === 'number') {
|
if (commandsContext && typeof commandsContext.groupId === 'number') {
|
||||||
|
@ -865,7 +876,7 @@ function registerCloseEditorCommands() {
|
||||||
handler: async (accessor, resourceOrContext?: URI | IEditorCommandsContext, context?: IEditorCommandsContext) => {
|
handler: async (accessor, resourceOrContext?: URI | IEditorCommandsContext, context?: IEditorCommandsContext) => {
|
||||||
const editorGroupService = accessor.get(IEditorGroupsService);
|
const editorGroupService = accessor.get(IEditorGroupsService);
|
||||||
|
|
||||||
const { group, editor } = resolveCommandsContext(editorGroupService, getCommandsContext(resourceOrContext, context));
|
const { group, editor } = resolveCommandsContext(editorGroupService, getCommandsContext(accessor, resourceOrContext, context));
|
||||||
if (group && editor) {
|
if (group && editor) {
|
||||||
if (group.activeEditor) {
|
if (group.activeEditor) {
|
||||||
group.pinEditor(group.activeEditor);
|
group.pinEditor(group.activeEditor);
|
||||||
|
@ -957,7 +968,7 @@ function registerCloseEditorCommands() {
|
||||||
CommandsRegistry.registerCommand(CLOSE_EDITORS_AND_GROUP_COMMAND_ID, async (accessor: ServicesAccessor, resourceOrContext?: URI | IEditorCommandsContext, context?: IEditorCommandsContext) => {
|
CommandsRegistry.registerCommand(CLOSE_EDITORS_AND_GROUP_COMMAND_ID, async (accessor: ServicesAccessor, resourceOrContext?: URI | IEditorCommandsContext, context?: IEditorCommandsContext) => {
|
||||||
const editorGroupService = accessor.get(IEditorGroupsService);
|
const editorGroupService = accessor.get(IEditorGroupsService);
|
||||||
|
|
||||||
const { group } = resolveCommandsContext(editorGroupService, getCommandsContext(resourceOrContext, context));
|
const { group } = resolveCommandsContext(editorGroupService, getCommandsContext(accessor, resourceOrContext, context));
|
||||||
if (group) {
|
if (group) {
|
||||||
await group.closeAllEditors();
|
await group.closeAllEditors();
|
||||||
|
|
||||||
|
@ -1005,7 +1016,7 @@ function registerSplitEditorInGroupCommands(): void {
|
||||||
const editorGroupService = accessor.get(IEditorGroupsService);
|
const editorGroupService = accessor.get(IEditorGroupsService);
|
||||||
const instantiationService = accessor.get(IInstantiationService);
|
const instantiationService = accessor.get(IInstantiationService);
|
||||||
|
|
||||||
const { group, editor } = resolveCommandsContext(editorGroupService, getCommandsContext(resourceOrContext, context));
|
const { group, editor } = resolveCommandsContext(editorGroupService, getCommandsContext(accessor, resourceOrContext, context));
|
||||||
if (!editor) {
|
if (!editor) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1040,7 +1051,7 @@ function registerSplitEditorInGroupCommands(): void {
|
||||||
async function joinEditorInGroup(accessor: ServicesAccessor, resourceOrContext?: URI | IEditorCommandsContext, context?: IEditorCommandsContext): Promise<void> {
|
async function joinEditorInGroup(accessor: ServicesAccessor, resourceOrContext?: URI | IEditorCommandsContext, context?: IEditorCommandsContext): Promise<void> {
|
||||||
const editorGroupService = accessor.get(IEditorGroupsService);
|
const editorGroupService = accessor.get(IEditorGroupsService);
|
||||||
|
|
||||||
const { group, editor } = resolveCommandsContext(editorGroupService, getCommandsContext(resourceOrContext, context));
|
const { group, editor } = resolveCommandsContext(editorGroupService, getCommandsContext(accessor, resourceOrContext, context));
|
||||||
if (!(editor instanceof SideBySideEditorInput)) {
|
if (!(editor instanceof SideBySideEditorInput)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1096,7 +1107,7 @@ function registerSplitEditorInGroupCommands(): void {
|
||||||
async run(accessor: ServicesAccessor, resourceOrContext?: URI | IEditorCommandsContext, context?: IEditorCommandsContext): Promise<void> {
|
async run(accessor: ServicesAccessor, resourceOrContext?: URI | IEditorCommandsContext, context?: IEditorCommandsContext): Promise<void> {
|
||||||
const editorGroupService = accessor.get(IEditorGroupsService);
|
const editorGroupService = accessor.get(IEditorGroupsService);
|
||||||
|
|
||||||
const { editor } = resolveCommandsContext(editorGroupService, getCommandsContext(resourceOrContext, context));
|
const { editor } = resolveCommandsContext(editorGroupService, getCommandsContext(accessor, resourceOrContext, context));
|
||||||
if (editor instanceof SideBySideEditorInput) {
|
if (editor instanceof SideBySideEditorInput) {
|
||||||
await joinEditorInGroup(accessor, resourceOrContext, context);
|
await joinEditorInGroup(accessor, resourceOrContext, context);
|
||||||
} else if (editor) {
|
} else if (editor) {
|
||||||
|
@ -1217,7 +1228,7 @@ function registerOtherEditorCommands(): void {
|
||||||
handler: async (accessor, resourceOrContext?: URI | IEditorCommandsContext, context?: IEditorCommandsContext) => {
|
handler: async (accessor, resourceOrContext?: URI | IEditorCommandsContext, context?: IEditorCommandsContext) => {
|
||||||
const editorGroupService = accessor.get(IEditorGroupsService);
|
const editorGroupService = accessor.get(IEditorGroupsService);
|
||||||
|
|
||||||
const { group, editor } = resolveCommandsContext(editorGroupService, getCommandsContext(resourceOrContext, context));
|
const { group, editor } = resolveCommandsContext(editorGroupService, getCommandsContext(accessor, resourceOrContext, context));
|
||||||
if (group && editor) {
|
if (group && editor) {
|
||||||
return group.pinEditor(editor);
|
return group.pinEditor(editor);
|
||||||
}
|
}
|
||||||
|
@ -1238,7 +1249,7 @@ function registerOtherEditorCommands(): void {
|
||||||
function setEditorGroupLock(accessor: ServicesAccessor, resourceOrContext?: URI | IEditorCommandsContext, context?: IEditorCommandsContext, locked?: boolean): void {
|
function setEditorGroupLock(accessor: ServicesAccessor, resourceOrContext?: URI | IEditorCommandsContext, context?: IEditorCommandsContext, locked?: boolean): void {
|
||||||
const editorGroupService = accessor.get(IEditorGroupsService);
|
const editorGroupService = accessor.get(IEditorGroupsService);
|
||||||
|
|
||||||
const { group } = resolveCommandsContext(editorGroupService, getCommandsContext(resourceOrContext, context));
|
const { group } = resolveCommandsContext(editorGroupService, getCommandsContext(accessor, resourceOrContext, context));
|
||||||
group?.lock(locked ?? !group.isLocked);
|
group?.lock(locked ?? !group.isLocked);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1346,7 +1357,7 @@ function registerOtherEditorCommands(): void {
|
||||||
const editorGroupService = accessor.get(IEditorGroupsService);
|
const editorGroupService = accessor.get(IEditorGroupsService);
|
||||||
const quickInputService = accessor.get(IQuickInputService);
|
const quickInputService = accessor.get(IQuickInputService);
|
||||||
|
|
||||||
const commandsContext = getCommandsContext(resourceOrContext, context);
|
const commandsContext = getCommandsContext(accessor, resourceOrContext, context);
|
||||||
if (commandsContext && typeof commandsContext.groupId === 'number') {
|
if (commandsContext && typeof commandsContext.groupId === 'number') {
|
||||||
const group = editorGroupService.getGroup(commandsContext.groupId);
|
const group = editorGroupService.getGroup(commandsContext.groupId);
|
||||||
if (group) {
|
if (group) {
|
||||||
|
@ -1363,7 +1374,7 @@ function getEditorsContext(accessor: ServicesAccessor, resourceOrContext?: URI |
|
||||||
const editorGroupService = accessor.get(IEditorGroupsService);
|
const editorGroupService = accessor.get(IEditorGroupsService);
|
||||||
const listService = accessor.get(IListService);
|
const listService = accessor.get(IListService);
|
||||||
|
|
||||||
const editorContext = getMultiSelectedEditorContexts(getCommandsContext(resourceOrContext, context), listService, editorGroupService);
|
const editorContext = getMultiSelectedEditorContexts(getCommandsContext(accessor, resourceOrContext, context), listService, editorGroupService);
|
||||||
|
|
||||||
const activeGroup = editorGroupService.activeGroup;
|
const activeGroup = editorGroupService.activeGroup;
|
||||||
if (editorContext.length === 0 && activeGroup.activeEditor) {
|
if (editorContext.length === 0 && activeGroup.activeEditor) {
|
||||||
|
@ -1398,17 +1409,20 @@ export function getEditorsFromContext(accessor: ServicesAccessor, resourceOrCont
|
||||||
return editorsAndGroup.filter(group => !!group);
|
return editorsAndGroup.filter(group => !!group);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getCommandsContext(resourceOrContext?: URI | IEditorCommandsContext, context?: IEditorCommandsContext): IEditorCommandsContext | undefined {
|
export function getCommandsContext(accessor: ServicesAccessor, resourceOrContext?: URI | IEditorCommandsContext, context?: IEditorCommandsContext): IEditorCommandsContext | undefined {
|
||||||
if (URI.isUri(resourceOrContext)) {
|
const isUri = URI.isUri(resourceOrContext);
|
||||||
return context;
|
|
||||||
|
const editorCommandsContext = isUri ? context : resourceOrContext;
|
||||||
|
if (editorCommandsContext && typeof editorCommandsContext.groupId === 'number') {
|
||||||
|
return editorCommandsContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resourceOrContext && typeof resourceOrContext.groupId === 'number') {
|
if (isUri) {
|
||||||
return resourceOrContext;
|
const editorGroupService = accessor.get(IEditorGroupsService);
|
||||||
}
|
const editorGroup = editorGroupService.getGroups(GroupsOrder.MOST_RECENTLY_ACTIVE).find(group => isEqual(group.activeEditor?.resource, resourceOrContext));
|
||||||
|
if (editorGroup) {
|
||||||
if (context && typeof context.groupId === 'number') {
|
return { groupId: editorGroup.index, editorIndex: editorGroup.getIndexOfEditor(editorGroup.activeEditor!) };
|
||||||
return context;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return undefined;
|
return undefined;
|
||||||
|
|
|
@ -1079,6 +1079,12 @@ export interface IEditorCommandsContext {
|
||||||
preserveFocus?: boolean;
|
preserveFocus?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isEditorCommandsContext(context: unknown): context is IEditorCommandsContext {
|
||||||
|
const candidate = context as IEditorCommandsContext | undefined;
|
||||||
|
|
||||||
|
return typeof candidate?.groupId === 'number';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* More information around why an editor was closed in the model.
|
* More information around why an editor was closed in the model.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue