Bug 147762 - Automatically assigned mnemonics not always set
Summary: Automatically assigned mnemonics not always set
Status: ASSIGNED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: framework (show other bugs)
Version:
(earliest affected)
Inherited From OOo
Hardware: All All
: high normal
Assignee: Chris Sena
URL:
Whiteboard:
Keywords: accessibility, needsDevEval
: 154389 161011 (view as bug list)
Depends on:
Blocks: Shortcuts-Accelerators
  Show dependency treegraph
 
Reported: 2022-03-04 10:44 UTC by Heiko Tietze
Modified: 2026-04-28 12:33 UTC (History)
11 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Heiko Tietze 2022-03-04 10:44:54 UTC
Spin-off from bug 147667: when mnemonics are not hard-coded it will be assigned automatically. This fails if all letters of a string were used before.

For example the Paste Special dialog uses A for Transpose _All and L for Cance_l making the checkbox "All" not accessible. In this case we cannot prevent double allocation and should use any character.
Comment 1 stragu 2023-07-25 13:15:34 UTC
According to bug 154389 comment 4, labels with no explicitly defined accelerator (in source or translated strings) are assigned one of the initial or final letters of its words if they are not already taken in that menu.

Rafael, do you have a code pointer for that?

Testing in a recent 24.2 master build, here are more example of commands that don't have an accelerator because all letters are taken:
- in French UI, Writer > Fichier > Signatures numériques
- in French UI, Writer > Formulaire > Ouvrir en mode ébauche; Focalisation automatique sur le contrôle; Contrôles de contenu

From bug 154389, an example where "inner" letters are available but not used:
- in English-US UI, Calc > cell with comment > context menu > Delete comment: could use O, M or N as they are not used elsewhere in the menu.

Already seen in OOo 3.3 with Edit > ImageMap missing an accelerator.

For improving the method, I imagine this process:

- If accelerator explicit with ~, use it
- If not:
  - (exclude special characters)
  - use first letter of word if available
  - if not available:
    - use any letter in the string that's not already used
    - if none available:
      - avoid letters already used by a submenu name (see bug 143184)
      - prioritise letters used the least

Hossein, wondering if this could be an easyHack?
Comment 2 Rafael Lima 2023-07-26 11:55:20 UTC
(In reply to Stéphane Guillou (stragu) from comment #1)
> Rafael, do you have a code pointer for that?

This seems to be the method used to generate mnemonics:
MnemonicGenerator::CreateMnemonic()

Located in:
/core/vcl/source/window/mnemonic.cxx
Comment 3 Heiko Tietze 2024-07-05 06:37:26 UTC
*** Bug 161011 has been marked as a duplicate of this bug. ***
Comment 4 Heiko Tietze 2024-07-05 06:37:45 UTC
*** Bug 154389 has been marked as a duplicate of this bug. ***
Comment 5 Heiko Tietze 2024-07-05 07:34:58 UTC
Hossein, how about making this an easyhack? 

MnemonicGenerator::CreateMnemonic() iterates somehow over the string and fails in case of Calc Data > Statistics (and other). The solution is probably a one-liner but to figure out the right place a bit tricky due to CJK.
Comment 6 Chris Sena 2026-03-22 00:51:19 UTC
Taking this bug. Plan is to add a PASS 3 fallback loop in 
MnemonicGenerator::CreateMnemonic() in vcl/source/window/mnemonic.cxx.

After PASS 1 (first letters) and PASS 2 (last letters) both fail to find 
an unclaimed mnemonic, PASS 3 will scan all remaining characters in the 
string and assign the first unclaimed valid letter found.

Reproduced in Calc > Data > Statistics — no menu items have an underlined 
accelerator character. Fix in progress.
Comment 7 Chris Sena 2026-03-22 05:15:54 UTC
Fix submitted to Gerrit for review:
https://gerrit.libreoffice.org/c/core/+/202348

Added PASS 2b fallback loop in MnemonicGenerator::CreateMnemonic() 
in vcl/source/window/mnemonic.cxx.

When PASS 1 (first letters) and PASS 2 (least-used letters) both 
fail, PASS 2b scans all characters and assigns the first unclaimed 
valid letter found.

Verified on:
- Calc > Data > Statistics (all items now have mnemonics)
- Paste Special > All checkbox (now shows underlined letter)
Comment 8 Heiko Tietze 2026-04-28 12:33:29 UTC
*** Bug 171896 has been marked as a duplicate of this bug. ***