diff --git a/visidata/cliptext.py b/visidata/cliptext.py index e4ec13ec9..52354d233 100644 --- a/visidata/cliptext.py +++ b/visidata/cliptext.py @@ -162,8 +162,12 @@ def _clipstr(s, dispw, trunch='', oddspacech='', combch='', modch=''): if dispw and w+chlen > dispw: if trunchlen and dispw > trunchlen: - ret = ret[:-1] + trunch # replace final char with ellipsis - w += trunchlen-1 + lastchlen = _dispch(ret[-1])[1] + if w+trunchlen > dispw: + ret = ret[:-1] + w -= lastchlen + ret += trunch # replace final char with ellipsis + w += trunchlen break w += chlen diff --git a/visidata/tests/test_cliptext.py b/visidata/tests/test_cliptext.py index badda69cd..868d27249 100644 --- a/visidata/tests/test_cliptext.py +++ b/visidata/tests/test_cliptext.py @@ -17,7 +17,8 @@ def test_dispwidth(self, s, dispw): ('b to', 4, 'b to', 4), ('abcde', 8, 'abcde', 5), (' jsonl', 5, ' jso…', 5), - (' で', 6, ' で', 6), + ('abcdで', 6, 'abcdで', 6), + ('abcdで', 5, 'abcd…', 5), ]) def test_clipstr(self, s, w, clippeds, clippedw): clips, clipw = visidata.clipstr(s, w)