summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2018-11-01 07:07:30 -0700
committerKaz Kylheku <kaz@kylheku.com>2018-11-01 07:07:30 -0700
commitbf85503bb9d2a52d9d3ddb86ae08fe6de0705e1f (patch)
tree60eba5ec23833cc6e627b521836aecc56301eb4c
parenta268abc3d1b980a4a19a7275108287dc3ce1e492 (diff)
downloadtxr-bf85503bb9d2a52d9d3ddb86ae08fe6de0705e1f.tar.gz
txr-bf85503bb9d2a52d9d3ddb86ae08fe6de0705e1f.tar.bz2
txr-bf85503bb9d2a52d9d3ddb86ae08fe6de0705e1f.zip
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.
-rw-r--r--linenoise/linenoise.c12
1 files changed, 9 insertions, 3 deletions
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;