Merge pull request #53 from XR-stb/patch-1

修复了前端输入中文字符再删除会出现的bug
This commit is contained in:
BLUELOVETH 2023-04-04 21:22:46 +08:00 committed by GitHub
commit 2470a1555c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -143,13 +143,14 @@ function term_init() {
term.write(need_more_lines ? "... " : ">>> ");
break;
case '\u007F': // Backspace (DEL)
// Do not delete the prompt
if (term._core.buffer.x > 4) { // '>>> ' or '... '
term.write('\b \b');
if (command.length > 0) {
command = command.substr(0, command.length - 1);
}
}
var cnt = term._core.buffer.x-4;
if(cnt<=0 || command.length==0) break;
// delete the last unicode char
command = command.replace(/.$/u, "");
// clear the whole line
term.write('\b \b'.repeat(cnt));
// re-write the command
term.write(command);
break;
default: // Print all other characters for demo
if (e >= String.fromCharCode(0x20) && e <= String.fromCharCode(0x7E) || e >= '\u00a0') {
@ -158,4 +159,4 @@ function term_init() {
}
}
});
}
}