From bf85503bb9d2a52d9d3ddb86ae08fe6de0705e1f Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 1 Nov 2018 07:07:30 -0700 Subject: linenoise: avoid refresh for new text in multi-line mode. * linenoise/linenoise.c (edit_insert): This function is missing an important optimization for multi-line mode. Let's add it. Since multi-line mode doesn't scroll horizontally, it is very simple: if a character is added at the end, there is no need for refresh. --- linenoise/linenoise.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'linenoise') diff --git a/linenoise/linenoise.c b/linenoise/linenoise.c index 93ead695..4d89591e 100644 --- a/linenoise/linenoise.c +++ b/linenoise/linenoise.c @@ -1506,9 +1506,15 @@ static int edit_insert(lino_t *l, wchar_t c) { l->dpos++; l->dlen++; l->data[l->dlen] = '\0'; - if ((!l->mlmode && l->len == l->dlen && l->plen+l->len < l->cols)) { - /* Avoid a full update of the line in the - * trivial case. */ + if ((!l->mlmode && l->len == l->dlen && l->plen+l->len < l->cols) || + (l->mlmode && l->dpos == l->dlen)) + { + /* Avoid full line update in trivial situations. + * single-line mode: line is shorter than cols (so no + * horizontal scrolling) and no funny characters that + * make the display length different from the buffer length. + * multi-line-mode: we are just adding to the end. + */ wchar_t str[2] = { c }; if (!lino_os.puts_fn(l->tty_ofs, str)) return -1; -- cgit v1.2.3