修复了前端输入中文字符再删除会出现的bug

具体的bug复现,见:https://github.com/blueloveTH/pocketpy/issues/50
This commit is contained in:
小染 2023-04-03 11:22:01 +08:00 committed by GitHub
parent 06d486d2a2
commit 2fd9879eec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -145,7 +145,12 @@ function term_init() {
case '\u007F': // Backspace (DEL)
// Do not delete the prompt
if (term._core.buffer.x > 4) { // '>>> ' or '... '
term.write('\b \b');
var re=/[^\u4E00-\u9FA5]/;
if (re.test(command.charAt(command.length-1))){//判断前一个字符是否为中文
term.write('\b \b');//false
}else{
term.write('\b\b \b');//中文占两个字节ascii字符占一个字节
}
if (command.length > 0) {
command = command.substr(0, command.length - 1);
}
@ -158,4 +163,4 @@ function term_init() {
}
}
});
}
}