From 9f121505d1b72e04efce5be558fc4a68745d2842 Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Tue, 10 Dec 2024 10:24:14 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20telnet=E7=BB=88=E7=AB=AF=E8=BE=93?= =?UTF-8?q?=E5=85=A5=E5=9B=9E=E8=BD=A6=E5=80=BC=E6=97=A0=E6=B3=95=E6=AD=A3?= =?UTF-8?q?=E7=A1=AE=E5=8F=91=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/TerminalTelnet/index.vue | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/components/TerminalTelnet/index.vue b/src/components/TerminalTelnet/index.vue index daba7162..310e9fb1 100644 --- a/src/components/TerminalTelnet/index.vue +++ b/src/components/TerminalTelnet/index.vue @@ -80,16 +80,16 @@ function fnAutoCompleteFilter(input: string, option: any) { } /**自动完成按键触发 */ -function fnAutoCompleteKeydown(evt: any) { +function fnAutoCompleteKeydown(evt: KeyboardEvent) { if (evt.key === 'Enter') { // 阻止默认的换行行为 evt.preventDefault(); // 按下 Shift + Enter 键时换行 - if (evt.shiftKey) { + if (evt.shiftKey && evt.target) { // 插入换行符 - const textarea = evt.target; - const start = textarea.selectionStart; - const end = textarea.selectionEnd; + const textarea = evt.target as HTMLInputElement; + const start = textarea.selectionStart || 0; + const end = textarea.selectionEnd || 0; const text = textarea.value; textarea.value = text.substring(0, start) + '\n' + text.substring(end); terminalState.text = textarea.value; @@ -121,7 +121,7 @@ function fnAutoCompleteKeydown(evt: any) { type: 'telnet', data: `${cmdStr}\r\n`, }); - terminalState.text = ' '; + terminalState.text = ''; // 退出登录 if (['q', 'quit', 'exit'].includes(cmdStr)) { @@ -296,11 +296,12 @@ defineExpose({ style="width: 100%" :options="terminalState.history" :filter-option="fnAutoCompleteFilter" - @keydown="fnAutoCompleteKeydown" + :defaultActiveFirstOption="false" >