fix: telnet终端输入回车值无法正确发出

This commit is contained in:
TsMask
2024-12-10 10:24:14 +08:00
parent 6add41254d
commit 9f121505d1

View File

@@ -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"
>
<a-textarea
:auto-size="{ minRows: 1, maxRows: 6 }"
placeholder="Execute command. Shift+Enter to line feed, Enter to send"
@keypress="fnAutoCompleteKeydown"
/>
</a-auto-complete>
</div>