mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-11 23:40:34 -05:00
Fix ctrl+v img file path paste in windows powershell (#308097)
* Fix ctrl+v img file path paste in windows powershell * better * comment
This commit is contained in:
@@ -452,6 +452,7 @@ export const enum TerminalCommandId {
|
||||
FocusNext = 'workbench.action.terminal.focusNext',
|
||||
FocusPrevious = 'workbench.action.terminal.focusPrevious',
|
||||
Paste = 'workbench.action.terminal.paste',
|
||||
PastePwsh = 'workbench.action.terminal.pastePwsh',
|
||||
PasteSelection = 'workbench.action.terminal.pasteSelection',
|
||||
SelectDefaultProfile = 'workbench.action.terminal.selectDefaultShell',
|
||||
RunSelectedText = 'workbench.action.terminal.runSelectedText',
|
||||
@@ -522,6 +523,7 @@ export const DEFAULT_COMMANDS_TO_SKIP_SHELL: string[] = [
|
||||
TerminalCommandId.New,
|
||||
TerminalCommandId.NewInNewWindow,
|
||||
TerminalCommandId.Paste,
|
||||
TerminalCommandId.PastePwsh,
|
||||
TerminalCommandId.PasteSelection,
|
||||
TerminalCommandId.ResizePaneDown,
|
||||
TerminalCommandId.ResizePaneLeft,
|
||||
|
||||
@@ -9,6 +9,8 @@ import { isIOS, isMacintosh, isWindows } from '../../../../../base/common/platfo
|
||||
import { isObject, isString } from '../../../../../base/common/types.js';
|
||||
import { localize, localize2 } from '../../../../../nls.js';
|
||||
import { CONTEXT_ACCESSIBILITY_MODE_ENABLED } from '../../../../../platform/accessibility/common/accessibility.js';
|
||||
import { IClipboardService } from '../../../../../platform/clipboard/common/clipboardService.js';
|
||||
import { ICommandService } from '../../../../../platform/commands/common/commands.js';
|
||||
import { ContextKeyExpr, type ContextKeyExpression } from '../../../../../platform/contextkey/common/contextkey.js';
|
||||
import type { ServicesAccessor } from '../../../../../platform/instantiation/common/instantiation.js';
|
||||
import { KeybindingsRegistry, KeybindingWeight, type IKeybindings } from '../../../../../platform/keybinding/common/keybindingsRegistry.js';
|
||||
@@ -19,6 +21,7 @@ import { IConfigurationResolverService } from '../../../../services/configuratio
|
||||
import { IHistoryService } from '../../../../services/history/common/history.js';
|
||||
import { ITerminalService } from '../../../terminal/browser/terminal.js';
|
||||
import { registerTerminalAction } from '../../../terminal/browser/terminalActions.js';
|
||||
import { TerminalCommandId } from '../../../terminal/common/terminal.js';
|
||||
import { TerminalContextKeys, TerminalContextKeyStrings } from '../../../terminal/common/terminalContextKey.js';
|
||||
|
||||
export const enum TerminalSendSequenceCommandId {
|
||||
@@ -126,10 +129,25 @@ const enum Constants {
|
||||
// shell, this gets handled by PSReadLine which properly handles multi-line pastes. This is
|
||||
// disabled in accessibility mode as PowerShell does not run PSReadLine when it detects a screen
|
||||
// reader. This works even when clipboard.readText is not supported.
|
||||
//
|
||||
// When the clipboard contains a VS Code file resource but no text, PSReadLine
|
||||
// cannot see it (it only reads CF_UNICODETEXT from the Win32 clipboard), so we delegate to the
|
||||
// standard paste command instead.
|
||||
if (isWindows) {
|
||||
registerSendSequenceKeybinding(String.fromCharCode('V'.charCodeAt(0) - Constants.CtrlLetterOffset), { // ctrl+v
|
||||
const ctrlV = String.fromCharCode('V'.charCodeAt(0) - Constants.CtrlLetterOffset);
|
||||
KeybindingsRegistry.registerCommandAndKeybindingRule({
|
||||
id: TerminalCommandId.PastePwsh,
|
||||
weight: KeybindingWeight.WorkbenchContrib,
|
||||
when: ContextKeyExpr.and(TerminalContextKeys.focus, ContextKeyExpr.equals(TerminalContextKeyStrings.ShellType, GeneralShellType.PowerShell), CONTEXT_ACCESSIBILITY_MODE_ENABLED.negate()),
|
||||
primary: KeyMod.CtrlCmd | KeyCode.KeyV
|
||||
primary: KeyMod.CtrlCmd | KeyCode.KeyV,
|
||||
handler: async accessor => {
|
||||
const clipboardService = accessor.get(IClipboardService);
|
||||
const commandService = accessor.get(ICommandService);
|
||||
if (!await clipboardService.readText() && await clipboardService.hasResources()) {
|
||||
return commandService.executeCommand(TerminalCommandId.Paste);
|
||||
}
|
||||
return commandService.executeCommand(TerminalCommandId.SendSequence, { text: ctrlV });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user