From 2fd9879eecfa799dec599cad53da14cee7d26b1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E6=9F=93?= <56108982+XR-stb@users.noreply.github.com> Date: Mon, 3 Apr 2023 11:22:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E5=89=8D=E7=AB=AF?= =?UTF-8?q?=E8=BE=93=E5=85=A5=E4=B8=AD=E6=96=87=E5=AD=97=E7=AC=A6=E5=86=8D?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E4=BC=9A=E5=87=BA=E7=8E=B0=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 具体的bug复现,见:https://github.com/blueloveTH/pocketpy/issues/50 --- web/index.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/web/index.js b/web/index.js index 8755b9a6..1a723488 100644 --- a/web/index.js +++ b/web/index.js @@ -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() { } } }); -} \ No newline at end of file +}