From: Simon Tatham Date: Fri, 8 Dec 2023 12:33:24 +0000 (+0000) Subject: Fix a wrapping glitch I spotted this morning. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=2b9696f92ef8ff6cd04237e96c965a28070f421b;p=mastodonochrome.git Fix a wrapping glitch I spotted this morning. --- diff --git a/cursesclient.py b/cursesclient.py index 4c442fc..e238f65 100644 --- a/cursesclient.py +++ b/cursesclient.py @@ -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)])) +