From 8c7a38596defa40624796141f4fbddfdea9240ae Mon Sep 17 00:00:00 2001
From: Benno Schulenberg <bensberg@justemail.net>
Date: Tue, 12 Jul 2016 21:05:09 +0200
Subject: [PATCH] screen: include a workaround only when compiling against
 older ncurses

The bug with a leading wide character has been fixed since ncurses-5.9.

See https://savannah.gnu.org/bugs/?31743 for reference.
---
 src/nano.h  | 4 ++++
 src/winio.c | 9 +++++++--
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/nano.h b/src/nano.h
index 36c7e9b1..b2e154a1 100644
--- a/src/nano.h
+++ b/src/nano.h
@@ -92,6 +92,10 @@
 #include <curses.h>
 #endif /* CURSES_H */
 
+#if defined(NCURSES_VERSION_MAJOR) && (NCURSES_VERSION_MAJOR < 6)
+#define USING_OLD_NCURSES yes
+#endif
+
 #ifdef ENABLE_NLS
 /* Native language support. */
 #ifdef HAVE_LIBINTL_H
diff --git a/src/winio.c b/src/winio.c
index 2bb7244a..c9786679 100644
--- a/src/winio.c
+++ b/src/winio.c
@@ -46,8 +46,10 @@ static int statusblank = 0;
 	/* The number of keystrokes left before we blank the statusbar. */
 static bool suppress_cursorpos = FALSE;
 	/* Should we skip constant position display for one keystroke? */
+#ifdef USING_OLD_NCURSES
 static bool seen_wide = FALSE;
 	/* Whether we've seen a multicolumn character in the current line. */
+#endif
 
 #ifndef NANO_TINY
 static sig_atomic_t last_sigwinch_counter = 0;
@@ -1761,7 +1763,9 @@ char *display_string(const char *buf, size_t start_col, size_t span,
     converted = charalloc(strlen(buf) * (mb_cur_max() + tabsize) + 1);
 
     index = 0;
+#ifdef USING_OLD_NCURSES
     seen_wide = FALSE;
+#endif
     buf += start_index;
 
     if (*buf != '\0' && *buf != '\t' &&
@@ -1845,9 +1849,10 @@ char *display_string(const char *buf, size_t start_col, size_t span,
 		converted[index++] = *(buf++);
 
 	    start_col += charwidth;
+#ifdef USING_OLD_NCURSES
 	    if (charwidth > 1)
 		seen_wide = TRUE;
-
+#endif
 	    continue;
 	}
 
@@ -2229,7 +2234,7 @@ void edit_draw(filestruct *fileptr, const char *converted, int
      * marking highlight on just the pieces that need it. */
     mvwaddstr(edit, line, 0, converted);
 
-#ifndef USE_SLANG
+#ifdef USING_OLD_NCURSES
     /* Tell ncurses to really redraw the line without trying to optimize
      * for what it thinks is already there, because it gets it wrong in
      * the case of a wide character in column zero.  See bug #31743. */
-- 
GitLab