diff --git a/prompt_toolkit/layout/menus.py b/prompt_toolkit/layout/menus.py index f0d8a0ab1..164df530a 100644 --- a/prompt_toolkit/layout/menus.py +++ b/prompt_toolkit/layout/menus.py @@ -224,7 +224,7 @@ def _trim_formatted_text( result = [] # Text fragments. remaining_width = max_width - 3 - for style_and_ch in explode_text_fragments(formatted_text): + for style_and_ch in explode_text_fragments(formatted_text)[::-1]: ch_width = get_cwidth(style_and_ch[1]) if ch_width <= remaining_width: @@ -235,7 +235,7 @@ def _trim_formatted_text( result.append(('', '...')) - return result, max_width - remaining_width + return result[::-1], max_width - remaining_width else: return formatted_text, width