From 36e3cb3b98b5686ae8a96b92a45277f8977e71d7 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Fri, 3 Apr 2020 16:32:43 +0800 Subject: fix moonp repl editing issue. --- src/linenoise.hpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/linenoise.hpp b/src/linenoise.hpp index b680141..06add16 100644 --- a/src/linenoise.hpp +++ b/src/linenoise.hpp @@ -1867,11 +1867,14 @@ inline void refreshSingleLine(struct linenoiseState *l) { /* Erase to right */ snprintf(seq,64,"\x1b[0K"); ab += seq; - if (!l->prompt.empty() || len != 0) { - /* Move cursor to original position. */ - snprintf(seq,64,"\r\x1b[%dC", (int)(unicodeColumnPos(buf, pos)+pcolwid)); - ab += seq; + int newPos = unicodeColumnPos(buf, pos) + pcolwid; + /* Move cursor to original position. */ + if (newPos != 0) { + snprintf(seq,64,"\r\x1b[%dC", newPos); + } else { + snprintf(seq,64,"\r"); } + ab += seq; if (write(fd,ab.c_str(), static_cast(ab.length())) == -1) {} /* Can't recover from write error. */ } -- cgit v1.2.3-55-g6feb