mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-14 12:11:43 +01:00
Fix #126805
This commit is contained in:
@@ -36,7 +36,7 @@ import {
|
||||
JoinAllGroupsAction, FocusLeftGroup, FocusAboveGroup, FocusRightGroup, FocusBelowGroup, EditorLayoutSingleAction, EditorLayoutTwoColumnsAction, EditorLayoutThreeColumnsAction, EditorLayoutTwoByTwoGridAction,
|
||||
EditorLayoutTwoRowsAction, EditorLayoutThreeRowsAction, EditorLayoutTwoColumnsBottomAction, EditorLayoutTwoRowsRightAction, NewEditorGroupLeftAction, NewEditorGroupRightAction,
|
||||
NewEditorGroupAboveAction, NewEditorGroupBelowAction, SplitEditorOrthogonalAction, CloseEditorInAllGroupsAction, NavigateToLastEditLocationAction, ToggleGroupSizesAction, ShowAllEditorsByMostRecentlyUsedAction,
|
||||
QuickAccessPreviousRecentlyUsedEditorAction, OpenPreviousRecentlyUsedEditorInGroupAction, OpenNextRecentlyUsedEditorInGroupAction, QuickAccessLeastRecentlyUsedEditorAction, QuickAccessLeastRecentlyUsedEditorInGroupAction, ReopenResourcesAction, ReOpenInTextEditorAction, DuplicateGroupDownAction, DuplicateGroupLeftAction, DuplicateGroupRightAction, DuplicateGroupUpAction
|
||||
QuickAccessPreviousRecentlyUsedEditorAction, OpenPreviousRecentlyUsedEditorInGroupAction, OpenNextRecentlyUsedEditorInGroupAction, QuickAccessLeastRecentlyUsedEditorAction, QuickAccessLeastRecentlyUsedEditorInGroupAction, ReopenResourcesAction, ReOpenInTextEditorAction, DuplicateGroupDownAction, DuplicateGroupLeftAction, DuplicateGroupRightAction, DuplicateGroupUpAction, ToggleEditorTypeAction
|
||||
} from 'vs/workbench/browser/parts/editor/editorActions';
|
||||
import {
|
||||
CLOSE_EDITORS_AND_GROUP_COMMAND_ID, CLOSE_EDITORS_IN_GROUP_COMMAND_ID, CLOSE_EDITORS_TO_THE_RIGHT_COMMAND_ID, CLOSE_EDITOR_COMMAND_ID, CLOSE_EDITOR_GROUP_COMMAND_ID,
|
||||
@@ -244,6 +244,7 @@ registry.registerWorkbenchAction(SyncActionDescriptor.from(EditorLayoutTwoByTwoG
|
||||
registry.registerWorkbenchAction(SyncActionDescriptor.from(EditorLayoutTwoRowsRightAction), 'View: Two Rows Right Editor Layout', CATEGORIES.View.value);
|
||||
registry.registerWorkbenchAction(SyncActionDescriptor.from(EditorLayoutTwoColumnsBottomAction), 'View: Two Columns Bottom Editor Layout', CATEGORIES.View.value);
|
||||
registry.registerWorkbenchAction(SyncActionDescriptor.from(ReopenResourcesAction), 'View: Reopen Editor With...', CATEGORIES.View.value, ActiveEditorAvailableEditorIdsContext);
|
||||
registry.registerWorkbenchAction(SyncActionDescriptor.from(ToggleEditorTypeAction), 'View: Toggle Editor Type', CATEGORIES.View.value, ActiveEditorAvailableEditorIdsContext);
|
||||
registry.registerWorkbenchAction(SyncActionDescriptor.from(ReOpenInTextEditorAction), 'View: Reopen Editor With Text Editor', CATEGORIES.View.value, ActiveEditorAvailableEditorIdsContext);
|
||||
registry.registerWorkbenchAction(SyncActionDescriptor.from(QuickAccessPreviousRecentlyUsedEditorAction), 'View: Quick Open Previous Recently Used Editor', CATEGORIES.View.value);
|
||||
registry.registerWorkbenchAction(SyncActionDescriptor.from(QuickAccessLeastRecentlyUsedEditorAction), 'View: Quick Open Least Recently Used Editor', CATEGORIES.View.value);
|
||||
|
||||
@@ -26,6 +26,7 @@ import { IFilesConfigurationService, AutoSaveMode } from 'vs/workbench/services/
|
||||
import { EditorOverride } from 'vs/platform/editor/common/editor';
|
||||
import { Schemas } from 'vs/base/common/network';
|
||||
import { Registry } from 'vs/platform/registry/common/platform';
|
||||
import { IEditorOverrideService } from 'vs/workbench/services/editor/common/editorOverrideService';
|
||||
|
||||
export class ExecuteCommandAction extends Action {
|
||||
|
||||
@@ -1927,6 +1928,51 @@ export class ReopenResourcesAction extends Action {
|
||||
}
|
||||
}
|
||||
|
||||
export class ToggleEditorTypeAction extends Action {
|
||||
|
||||
static readonly ID = 'workbench.action.toggleEditorType';
|
||||
static readonly LABEL = localize('workbench.action.toggleEditorType', "Toggle Editor Type");
|
||||
|
||||
constructor(
|
||||
id: string,
|
||||
label: string,
|
||||
@IEditorService private readonly editorService: IEditorService,
|
||||
@IEditorOverrideService private readonly editorOverrideService: IEditorOverrideService,
|
||||
) {
|
||||
super(id, label);
|
||||
}
|
||||
|
||||
override async run(): Promise<void> {
|
||||
const activeEditorPane = this.editorService.activeEditorPane;
|
||||
if (!activeEditorPane) {
|
||||
return;
|
||||
}
|
||||
|
||||
const activeEditorResource = activeEditorPane.input.resource;
|
||||
if (!activeEditorResource) {
|
||||
return;
|
||||
}
|
||||
|
||||
const options = activeEditorPane.options;
|
||||
const group = activeEditorPane.group;
|
||||
|
||||
const editorIds = this.editorOverrideService.getEditorIds(activeEditorResource).filter(id => id !== activeEditorPane.input.editorId);
|
||||
|
||||
if (editorIds.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Replace the current editor with the next avaiable editor type
|
||||
await this.editorService.replaceEditors([
|
||||
{
|
||||
editor: activeEditorPane.input,
|
||||
replacement: activeEditorPane.input,
|
||||
options: { ...options, override: editorIds[0] },
|
||||
}
|
||||
], group);
|
||||
}
|
||||
}
|
||||
|
||||
export class ReOpenInTextEditorAction extends Action {
|
||||
|
||||
static readonly ID = 'workbench.action.reopenTextEditor';
|
||||
|
||||
@@ -250,7 +250,13 @@ export class EditorOverrideService extends Disposable implements IEditorOverride
|
||||
}
|
||||
}
|
||||
// Return the editors sorted by their priority
|
||||
return matchingEditors.sort((a, b) => priorityToRank(b.editorInfo.priority) - priorityToRank(a.editorInfo.priority));
|
||||
return matchingEditors.sort((a, b) => {
|
||||
// Very crude if priorities match longer glob wins as longer globs are normally more specific
|
||||
if (priorityToRank(b.editorInfo.priority) === priorityToRank(a.editorInfo.priority) && typeof b.globPattern === 'string' && typeof a.globPattern === 'string') {
|
||||
return b.globPattern.length - a.globPattern.length;
|
||||
}
|
||||
return priorityToRank(b.editorInfo.priority) - priorityToRank(a.editorInfo.priority);
|
||||
});
|
||||
}
|
||||
|
||||
public getEditorIds(resource: URI): string[] {
|
||||
|
||||
Reference in New Issue
Block a user