🐛 终端无法粘贴.
This commit is contained in:
@@ -29,7 +29,7 @@ export const readText = () => {
|
||||
try {
|
||||
const success = document.execCommand('paste');
|
||||
if (!success) {
|
||||
Message.error('当前浏览器无法读取剪切板内容');
|
||||
Message.error('当前环境无法读取剪切板内容');
|
||||
}
|
||||
resolve(textarea.value);
|
||||
} catch (error) {
|
||||
@@ -53,7 +53,10 @@ export const copyToClipboard = async (value: string) => {
|
||||
document.body.appendChild(textarea);
|
||||
textarea.select();
|
||||
try {
|
||||
document.execCommand('copy');
|
||||
const success = document.execCommand('copy');
|
||||
if (!success) {
|
||||
Message.error('当前环境无法复制到剪切板');
|
||||
}
|
||||
} catch (error) {
|
||||
throw error;
|
||||
} finally {
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
v-model="formModel.copyAutoTrim" />
|
||||
</block-setting-item>
|
||||
<!-- 粘贴去除空格 -->
|
||||
<block-setting-item label="粘贴去除空格" desc="粘贴文本前自动删除尾部空格 如: 命令输入框, 命令编辑器, 右键粘贴, 粘贴按钮, 右键菜单粘贴, 自定义粘贴快捷键">
|
||||
<block-setting-item label="粘贴去除空格" desc="粘贴文本前自动删除尾部空格 如: 命令输入框, 命令编辑器, 右键粘贴, 粘贴按钮, 右键菜单粘贴, 自定义粘贴快捷键 (内置粘贴快捷键因浏览器限制不会去除)">
|
||||
<a-switch type="round"
|
||||
v-model="formModel.pasteAutoTrim" />
|
||||
</block-setting-item>
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
<!-- 启用-未修改 -->
|
||||
<span v-else-if="item.enabled">{{ item.shortcutKey }}</span>
|
||||
<!-- 禁用 -->
|
||||
<span v-else />
|
||||
<span v-else class="disabled-key">已禁用</span>
|
||||
</div>
|
||||
<!-- 操作 -->
|
||||
<a-space class="shortcut-actions-container">
|
||||
@@ -52,6 +52,13 @@
|
||||
<icon-settings />
|
||||
</div>
|
||||
</a-space>
|
||||
<!-- 描述 -->
|
||||
<div class="shortcut-desc">
|
||||
<!-- 粘贴描述 -->
|
||||
<template v-if="item.item === TerminalShortcutKeys.PASTE">
|
||||
Ctrl + Shift + V, Shift + Insert 为浏览器内置快捷键, 不受环境影响
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
@@ -68,6 +75,7 @@
|
||||
import type { TerminalShortcutKeyEditable } from '@/store/modules/terminal/types';
|
||||
import type { VNodeRef } from 'vue';
|
||||
import { setAutoFocus } from '@/utils/dom';
|
||||
import { TerminalShortcutKeys } from '../../../types/terminal.const';
|
||||
|
||||
defineProps<{
|
||||
title: string;
|
||||
@@ -116,6 +124,10 @@
|
||||
.shortcut-actions-container {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.shortcut-desc {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
.shortcut-name {
|
||||
@@ -132,6 +144,11 @@
|
||||
}
|
||||
}
|
||||
|
||||
.shortcut-desc {
|
||||
display: flex;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.shortcut-actions-container {
|
||||
display: none;
|
||||
|
||||
@@ -144,6 +161,10 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.disabled-key {
|
||||
color: var(--color-neutral-6);
|
||||
}
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
@@ -16,18 +16,22 @@ const preventKeys: Array<ShortcutKey> = [
|
||||
altKey: false,
|
||||
shiftKey: true,
|
||||
code: 'KeyC'
|
||||
}
|
||||
// , {
|
||||
// ctrlKey: true,
|
||||
// altKey: false,
|
||||
// shiftKey: true,
|
||||
// code: 'KeyV'
|
||||
// }, {
|
||||
// ctrlKey: false,
|
||||
// altKey: false,
|
||||
// shiftKey: true,
|
||||
// code: 'Insert'
|
||||
// },
|
||||
},
|
||||
];
|
||||
|
||||
// 内置快捷键
|
||||
const builtinKeys: Array<ShortcutKey> = [
|
||||
{
|
||||
ctrlKey: true,
|
||||
altKey: false,
|
||||
shiftKey: true,
|
||||
code: 'KeyV'
|
||||
}, {
|
||||
ctrlKey: false,
|
||||
altKey: false,
|
||||
shiftKey: true,
|
||||
code: 'Insert'
|
||||
},
|
||||
];
|
||||
|
||||
const { copy: copyValue, readText } = useCopy();
|
||||
@@ -50,16 +54,13 @@ export default class SshSessionHandler implements ISshSessionHandler {
|
||||
this.session = session;
|
||||
this.inst = session.inst;
|
||||
this.domRef = domRef;
|
||||
const { preference, tabManager } = useTerminalStore();
|
||||
const { preference } = useTerminalStore();
|
||||
this.interactSetting = preference.interactSetting;
|
||||
this.shortcutKeys = preference.shortcutSetting.keys;
|
||||
}
|
||||
|
||||
// 检测是否忽略默认行为
|
||||
checkPreventDefault(e: KeyboardEvent): boolean {
|
||||
if (e.type !== 'keydown') {
|
||||
return false;
|
||||
}
|
||||
return !!preventKeys.find(key => {
|
||||
return key.code === e.code
|
||||
&& key.altKey === e.altKey
|
||||
@@ -68,6 +69,16 @@ export default class SshSessionHandler implements ISshSessionHandler {
|
||||
});
|
||||
}
|
||||
|
||||
// 检测是否为内置快捷键
|
||||
checkIsBuiltin(e: KeyboardEvent): boolean {
|
||||
return !!builtinKeys.find(key => {
|
||||
return key.code === e.code
|
||||
&& key.altKey === e.altKey
|
||||
&& key.shiftKey === e.shiftKey
|
||||
&& key.ctrlKey === e.ctrlKey;
|
||||
});
|
||||
}
|
||||
|
||||
// 启用状态
|
||||
enabledStatus(option: string): boolean {
|
||||
switch (option) {
|
||||
|
||||
@@ -85,6 +85,10 @@ export default class SshSession implements ISshSession {
|
||||
if (e.type !== 'keydown') {
|
||||
return true;
|
||||
}
|
||||
// 检测是否为内置快捷键
|
||||
if (this.handler.checkIsBuiltin(e)) {
|
||||
return true;
|
||||
}
|
||||
// 检测是否阻止默认行为
|
||||
if (this.handler.checkPreventDefault(e)) {
|
||||
e.preventDefault();
|
||||
|
||||
@@ -212,6 +212,8 @@ export const TerminalShortcutKeys = {
|
||||
CHANGE_TO_PREV_SESSION: 'changeToPrevSession',
|
||||
// 切换至后一个会话
|
||||
CHANGE_TO_NEXT_SESSION: 'changeToNextSession',
|
||||
// 粘贴
|
||||
PASTE: 'paste',
|
||||
};
|
||||
|
||||
// 终端操作快捷键
|
||||
@@ -257,7 +259,7 @@ export const TerminalShortcutItems: Array<ShortcutKeyItem> = [
|
||||
content: '复制',
|
||||
type: TerminalShortcutType.TERMINAL
|
||||
}, {
|
||||
item: 'paste',
|
||||
item: TerminalShortcutKeys.PASTE,
|
||||
content: '粘贴',
|
||||
type: TerminalShortcutType.TERMINAL
|
||||
}, {
|
||||
|
||||
@@ -267,6 +267,8 @@ export interface ISshSession extends ITerminalSession {
|
||||
export interface ISshSessionHandler {
|
||||
// 检测是否忽略默认行为
|
||||
checkPreventDefault: (e: KeyboardEvent) => boolean;
|
||||
// 检测是否为内置快捷键
|
||||
checkIsBuiltin: (e: KeyboardEvent) => boolean;
|
||||
// 启用状态
|
||||
enabledStatus: (option: string) => boolean;
|
||||
// 调用处理方法
|
||||
|
||||
Reference in New Issue
Block a user