Skip to content

Commit ff8d0d6

Browse files
authored
Copy Path and Copy Relative Path commands are only available when editor is not focused. (fix microsoft#137216) (microsoft#158556)
1 parent aca0074 commit ff8d0d6

File tree

2 files changed

+41
-11
lines changed

2 files changed

+41
-11
lines changed

src/vs/workbench/browser/parts/editor/titleControl.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ export abstract class TitleControl extends Themable {
260260
// Editor actions require the editor control to be there, so we retrieve it via service
261261
const activeEditorPane = this.group.activeEditorPane;
262262
if (activeEditorPane instanceof EditorPane) {
263-
const scopedContextKeyService = activeEditorPane.scopedContextKeyService ?? this.contextKeyService;
263+
const scopedContextKeyService = this.getEditorPaneAwareContextKeyService();
264264
const titleBarMenu = this.menuService.createMenu(MenuId.EditorTitle, scopedContextKeyService, { emitEventsForSubmenuChanges: true, eventDebounceDelay: 0 });
265265
this.editorToolBarMenuDisposables.add(titleBarMenu);
266266
this.editorToolBarMenuDisposables.add(titleBarMenu.onDidChange(() => {
@@ -282,6 +282,10 @@ export abstract class TitleControl extends Themable {
282282
return { primary, secondary };
283283
}
284284

285+
private getEditorPaneAwareContextKeyService(): IContextKeyService {
286+
return this.group.activeEditorPane?.scopedContextKeyService ?? this.contextKeyService;
287+
}
288+
285289
protected clearEditorActionsToolbar(): void {
286290
this.editorActionsToolbar?.setActions([], []);
287291
}
@@ -401,7 +405,7 @@ export abstract class TitleControl extends Themable {
401405
}
402406

403407
private getKeybinding(action: IAction): ResolvedKeybinding | undefined {
404-
return this.keybindingService.lookupKeybinding(action.id);
408+
return this.keybindingService.lookupKeybinding(action.id, this.getEditorPaneAwareContextKeyService());
405409
}
406410

407411
protected getKeybindingLabel(action: IAction): string | undefined {

src/vs/workbench/contrib/files/browser/fileCommands.ts

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { ExplorerViewPaneContainer } from 'vs/workbench/contrib/files/browser/ex
1616
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
1717
import { toErrorMessage } from 'vs/base/common/errorMessage';
1818
import { IListService } from 'vs/platform/list/browser/listService';
19-
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
19+
import { CommandsRegistry, ICommandHandler } from 'vs/platform/commands/common/commands';
2020
import { IContextKey, IContextKeyService, ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
2121
import { IFileService } from 'vs/platform/files/common/files';
2222
import { KeybindingsRegistry, KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
@@ -248,6 +248,11 @@ async function resourcesToClipboard(resources: URI[], relative: boolean, clipboa
248248
}
249249
}
250250

251+
const copyPathCommandHandler: ICommandHandler = async (accessor, resource: URI | object) => {
252+
const resources = getMultiSelectedResources(resource, accessor.get(IListService), accessor.get(IEditorService), accessor.get(IExplorerService));
253+
await resourcesToClipboard(resources, false, accessor.get(IClipboardService), accessor.get(ILabelService), accessor.get(IConfigurationService));
254+
};
255+
251256
KeybindingsRegistry.registerCommandAndKeybindingRule({
252257
weight: KeybindingWeight.WorkbenchContrib,
253258
when: EditorContextKeys.focus.toNegated(),
@@ -256,12 +261,25 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
256261
primary: KeyMod.Shift | KeyMod.Alt | KeyCode.KeyC
257262
},
258263
id: COPY_PATH_COMMAND_ID,
259-
handler: async (accessor, resource: URI | object) => {
260-
const resources = getMultiSelectedResources(resource, accessor.get(IListService), accessor.get(IEditorService), accessor.get(IExplorerService));
261-
await resourcesToClipboard(resources, false, accessor.get(IClipboardService), accessor.get(ILabelService), accessor.get(IConfigurationService));
262-
}
264+
handler: copyPathCommandHandler
263265
});
264266

267+
KeybindingsRegistry.registerCommandAndKeybindingRule({
268+
weight: KeybindingWeight.WorkbenchContrib,
269+
when: EditorContextKeys.focus,
270+
primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KeyK, KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.KeyC),
271+
win: {
272+
primary: KeyMod.Shift | KeyMod.Alt | KeyCode.KeyC
273+
},
274+
id: COPY_PATH_COMMAND_ID,
275+
handler: copyPathCommandHandler
276+
});
277+
278+
const copyRelativePathCommandHandler: ICommandHandler = async (accessor, resource: URI | object) => {
279+
const resources = getMultiSelectedResources(resource, accessor.get(IListService), accessor.get(IEditorService), accessor.get(IExplorerService));
280+
await resourcesToClipboard(resources, true, accessor.get(IClipboardService), accessor.get(ILabelService), accessor.get(IConfigurationService));
281+
};
282+
265283
KeybindingsRegistry.registerCommandAndKeybindingRule({
266284
weight: KeybindingWeight.WorkbenchContrib,
267285
when: EditorContextKeys.focus.toNegated(),
@@ -270,10 +288,18 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
270288
primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KeyK, KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KeyC)
271289
},
272290
id: COPY_RELATIVE_PATH_COMMAND_ID,
273-
handler: async (accessor, resource: URI | object) => {
274-
const resources = getMultiSelectedResources(resource, accessor.get(IListService), accessor.get(IEditorService), accessor.get(IExplorerService));
275-
await resourcesToClipboard(resources, true, accessor.get(IClipboardService), accessor.get(ILabelService), accessor.get(IConfigurationService));
276-
}
291+
handler: copyRelativePathCommandHandler
292+
});
293+
294+
KeybindingsRegistry.registerCommandAndKeybindingRule({
295+
weight: KeybindingWeight.WorkbenchContrib,
296+
when: EditorContextKeys.focus,
297+
primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KeyK, KeyMod.CtrlCmd | KeyMod.Shift | KeyMod.Alt | KeyCode.KeyC),
298+
win: {
299+
primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KeyK, KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KeyC)
300+
},
301+
id: COPY_RELATIVE_PATH_COMMAND_ID,
302+
handler: copyRelativePathCommandHandler
277303
});
278304

279305
KeybindingsRegistry.registerCommandAndKeybindingRule({

0 commit comments

Comments
 (0)