From a2a0848bb18955a00e7b4bc7954bfc825a4f6a82 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 22 May 2023 12:12:47 +0530 Subject: [PATCH] Fix #2018698 [Toolbar button wordwrap glitch](https://bugs.launchpad.net/calibre/+bug/2018698) --- src/calibre/gui2/bars.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/calibre/gui2/bars.py b/src/calibre/gui2/bars.py index c45cb779f7..7108eafedc 100644 --- a/src/calibre/gui2/bars.py +++ b/src/calibre/gui2/bars.py @@ -85,7 +85,13 @@ def wrap_button_text(text, max_len=MAX_TEXT_LENGTH): broken = True else: ans = word - if not broken: + if broken: + prefix, suffix = ans.split('\n', 1) + if len(suffix) > len(prefix) and len(suffix) > MAX_TEXT_LENGTH and len(prefix) < MAX_TEXT_LENGTH and suffix.count(' ') > 1: + word, rest = suffix.split(' ', 1) + if len(word) + len(prefix) <= len(rest): + ans = prefix + ' ' + word + '\n' + rest + else: if ' ' in ans: ans = '\n'.join(ans.split(' ', 1)) elif '/' in ans: