chiark / gitweb /
Fix a wrapping glitch I spotted this morning.
authorSimon Tatham <anakin@pobox.com>
Fri, 8 Dec 2023 12:33:24 +0000 (12:33 +0000)
committerSimon Tatham <anakin@pobox.com>
Fri, 8 Dec 2023 12:33:24 +0000 (12:33 +0000)
cursesclient.py

index 4c442fc64f44b14fbf55316d733a28762e87a132..e238f653faa8bbf194b2fa7ac32852f70b218a8a 100644 (file)
@@ -788,9 +788,8 @@ class Composer(Activity):
 
                     i += 1
                     hard_wrap_point = i
-                    if (i+1 < len(para) and
-                        str(para[i-1]) == ' ' and
-                        str(para[i]) != ' '):
+                    if (str(para[i-1]) == ' ' and
+                        (i+1 >= len(para) or str(para[i]) != ' ')):
                         soft_wrap_point = i
 
                 assert hard_wrap_point is not None
@@ -1064,3 +1063,23 @@ class testComposerLayout(unittest.TestCase):
         t.layout(10, 500, 23)
         self.assertEqual(t.lines, [text.ColouredString("")])
         self.assertEqual(t.yx, [(0,0),(1,0)])
+
+        t = Composer.DisplayText("abc def ")
+        t.layout(8, 500, 23)
+        self.assertEqual(t.lines, [text.ColouredString("abc def ")])
+        self.assertEqual(t.yx, ([(0,i) for i in range(9)]))
+
+        t = Composer.DisplayText("abc def gh")
+        t.layout(8, 500, 23)
+        self.assertEqual(t.lines, [text.ColouredString("abc def "),
+                                   text.ColouredString("gh")])
+        self.assertEqual(t.yx, ([(0,i) for i in range(8)] +
+                                [(1,i) for i in range(3)]))
+
+        t = Composer.DisplayText("abc def g")
+        t.layout(8, 500, 23)
+        self.assertEqual(t.lines, [text.ColouredString("abc def "),
+                                   text.ColouredString("g")])
+        self.assertEqual(t.yx, ([(0,i) for i in range(8)] +
+                                [(1,i) for i in range(2)]))
+