about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorThomas E. Dickey <dickey@invisible-island.net>2017-04-29 00:35:28 +0000
committerThomas E. Dickey <dickey@invisible-island.net>2017-04-29 00:35:28 +0000
commit2d65308da82f7c091df6abfc7488e2bb33702073 (patch)
tree579593a6a3589477bce783534825c98e60c5a5b3
parent5ae317fdbe6eed531e4eba65faaa6e33050e19c2 (diff)
downloadlynx-snapshots-2d65308da82f7c091df6abfc7488e2bb33702073.tar.gz
snapshot of project "lynx", label v2-8-9dev_11r
-rw-r--r--CHANGES5
-rw-r--r--src/LYStrings.c10
2 files changed, 11 insertions, 4 deletions
diff --git a/CHANGES b/CHANGES
index 713a0717..2dd2a488 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,9 +1,12 @@
--- $LynxId: CHANGES,v 1.886 2017/04/28 20:10:44 tom Exp $
+-- $LynxId: CHANGES,v 1.887 2017/04/29 00:35:28 tom Exp $
 ===============================================================================
 Changes since Lynx 2.8 release
 ===============================================================================
 
 2017-04-28 (2.8.9dev.12)
+* correct logic in cell2char(), which gave up too early in determining the
+  number of cells needed for a multibyte string in the editable text-fields
+  (Debian #841155) -TD
 * improve manual page discussion of environment variables, prompted by
   comments in Debian #791452, which overlooked the fact that details of proxy
   behavior are found in the user guide -TD
diff --git a/src/LYStrings.c b/src/LYStrings.c
index 02b1286d..622add8b 100644
--- a/src/LYStrings.c
+++ b/src/LYStrings.c
@@ -1,4 +1,4 @@
-/* $LynxId: LYStrings.c,v 1.265 2017/03/18 21:42:48 tom Exp $ */
+/* $LynxId: LYStrings.c,v 1.266 2017/04/29 00:32:21 tom Exp $ */
 #include <HTUtils.h>
 #include <HTCJK.h>
 #include <UCAux.h>
@@ -3105,15 +3105,19 @@ static int cell2char(char *s, int cells)
     int have;
 
     CTRACE_EDIT((tfp, "cell2char(%d) %d:%s\n", cells, len, s));
-    /* FIXME - make this a binary search */
     if (len != 0) {
+	int best = -1;
+
 	for (pos = 0; pos <= len; ++pos) {
 	    have = LYstrExtent2(s, pos);
 	    CTRACE_EDIT((tfp, "  %2d:%2d:%.*s\n", pos, have, pos, s));
 	    if (have >= cells) {
-		break;
+		/* the best solution is the one with the most bytes */
+		best = pos;
 	    }
 	}
+	if (best >= 0)
+	    pos = best;
 	if (pos > len)
 	    pos = len;
     } else {