From c3470a5419cd220b292a8c71d28e2347b8cd2e4f Mon Sep 17 00:00:00 2001 From: Baobhan Sith <80159437+Heavrnl@users.noreply.github.com> Date: Sat, 3 May 2025 19:47:38 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=9C=A8=E7=BB=88=E7=AB=AF=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=A4=8D=E5=88=B6=E7=B2=98=E8=B4=B4=E5=BF=AB=E6=8D=B7?= =?UTF-8?q?=E9=94=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ctrl + Shift + C 复制 Ctrl + Shift + V 粘贴 Related to #6 --- packages/frontend/src/components/Terminal.vue | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/packages/frontend/src/components/Terminal.vue b/packages/frontend/src/components/Terminal.vue index 4fed5a6..4d97e41 100644 --- a/packages/frontend/src/components/Terminal.vue +++ b/packages/frontend/src/components/Terminal.vue @@ -306,6 +306,46 @@ onMounted(() => { if (terminal) { terminal.focus(); } + + // --- 添加 Ctrl+Shift+C/V 复制粘贴 --- + if (terminal && terminal.textarea) { // 确保 terminal 和 textarea 存在 + terminal.textarea.addEventListener('keydown', async (event: KeyboardEvent) => { + // Ctrl+Shift+C for Copy + if (event.ctrlKey && event.shiftKey && event.code === 'KeyC') { + event.preventDefault(); // 阻止默认行为 (例如浏览器开发者工具) + event.stopPropagation(); // 阻止事件冒泡 + const selection = terminal?.getSelection(); + if (selection) { + try { + await navigator.clipboard.writeText(selection); + console.log('[Terminal] Copied via Ctrl+Shift+C:', selection); + } catch (err) { + console.error('[Terminal] Failed to copy via Ctrl+Shift+C:', err); + // 可以考虑添加 UI 提示 + } + } + } + // Ctrl+Shift+V for Paste + else if (event.ctrlKey && event.shiftKey && event.code === 'KeyV') { + event.preventDefault(); + event.stopPropagation(); + try { + const text = await navigator.clipboard.readText(); + if (text) { + // 将粘贴的文本发送到后端,模拟用户输入 + emit('data', text); + console.log('[Terminal] Pasted via Ctrl+Shift+V'); + } + } catch (err) { + console.error('[Terminal] Failed to paste via Ctrl+Shift+V:', err); + // 检查权限问题,例如 navigator.clipboard.readText 需要用户授权或安全上下文 + // 可以考虑添加 UI 提示 + } + } + }); + } + // --- 结束添加复制粘贴 --- + // 重新添加鼠标滚轮缩放功能 if (terminalRef.value) { terminalRef.value.addEventListener('wheel', (event: WheelEvent) => {