From 871c51dfd36fd83c0601b4ac9d9f2e157609a77b Mon Sep 17 00:00:00 2001 From: Karol Kosek Date: Wed, 14 Jul 2021 17:10:05 +0200 Subject: [PATCH] LibGfx: Don't underline escaped ampersand in menus Double ampersands (&&) marking in menus is meant to provide a way to show the ampersand, since using just one would turn it into a modifier that sets the shortcut for the next character. Unfortunately, while the first character had a special case to avoid marking this set, the marking was still calculated for the second character. The fix is rather simple: just skip then the following character! This issue applied only to the visual part of the Menu. The WindowServer calculation for the shortcut character is working properly, i.e. ignores escaped ampersands. --- Userland/Libraries/LibGfx/Painter.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibGfx/Painter.cpp b/Userland/Libraries/LibGfx/Painter.cpp index 8552204678..3e93f9dd50 100644 --- a/Userland/Libraries/LibGfx/Painter.cpp +++ b/Userland/Libraries/LibGfx/Painter.cpp @@ -2221,10 +2221,12 @@ String parse_ampersand_string(const StringView& raw_text, Optional* unde for (size_t i = 0; i < raw_text.length(); ++i) { if (raw_text[i] == '&') { - if (i != (raw_text.length() - 1) && raw_text[i + 1] == '&') + if (i != (raw_text.length() - 1) && raw_text[i + 1] == '&') { builder.append(raw_text[i]); - else if (underline_offset && !(*underline_offset).has_value()) + ++i; + } else if (underline_offset && !(*underline_offset).has_value()) { *underline_offset = i; + } continue; } builder.append(raw_text[i]);