Skip to content

Clarified DecorateItemsWithHotkeys. - #1121

Merged
alabuzhev merged 5 commits into
FarGroup:masterfrom
MKadaner:mzk/menu_item_data
Aug 16, 2026
Merged

Clarified DecorateItemsWithHotkeys.#1121
alabuzhev merged 5 commits into
FarGroup:masterfrom
MKadaner:mzk/menu_item_data

Conversation

@MKadaner

@MKadaner MKadaner commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Now getting DecorateItemsWithHotkeys right... Hopefully.

The original implementation would misalign accelerator key of the item "&1&2&3".

References

N/A

Checklist

  • I have followed the contributing guidelines.
  • I have discussed this with project maintainers: N/A

    If not checked, I accept that this work might be rejected in favor of a different great big ineffable plan.

Details

Fullwidth-aware DecorateItemsWithHotkeys

DecorateItemsWithHotkeys (former AddHotkeys) tried to compensate the visual string length accounted for by fit_to_left by comparing the results of HiStrlen and visual_string_length. If these functions produce different results, then there is an ampersand in the item name which will be removed during rendering, so we compensated for it adding an extra space before the accelerator string. Unfortunately, escaping ampersand removes all (unescaped) ampersands, so the string may occupy even less screen cells than the algorithm assumed.

The fix is simple: let's assume that HiStrlen returns honest visual length of the properly escaped string. Now, we need to append as many spaces as required to pad the visual length up to the maximum visual length.

Refactoring

  1. Renamed menu_item to menu_item_data and decoupled it from menu_item_ex.
    • The similarity between these classes is incidental: menu_item_data is a struct holding data required to construct menu items, while menu_item_ex is the actual non-trivial class representing menu items internally (well, mostly internally).
    • Having cached VisualLength in menu_item_ex enables future optimizations.
    • Removed GetName / SetName from menu_item_data. It is not needed there. I apologize for code churn.
  2. Regularized SetCheck, SetCustomCheck, SetSelect, SetDisable, and SetGrayed helpers.
    • Now they are free functions, use a common helper, and serve both menu_item_data and menu_item_ex.

@MKadaner
MKadaner force-pushed the mzk/menu_item_data branch from 25ee6da to 02fd62e Compare August 3, 2026 00:36
Comment thread far/vmenu.hpp Outdated
@MKadaner
MKadaner force-pushed the mzk/menu_item_data branch from 02fd62e to cc13a25 Compare August 15, 2026 16:54
@MKadaner
MKadaner force-pushed the mzk/menu_item_data branch from cc13a25 to 4f11bdc Compare August 16, 2026 01:03
1. Do not inherit `menu_item_ex` from `menu_item_data`
2. Unify functions manipulating menu item flags
@MKadaner
MKadaner force-pushed the mzk/menu_item_data branch from 4f11bdc to a926fff Compare August 16, 2026 01:13
@sonarqubecloud

Copy link
Copy Markdown

@alabuzhev
alabuzhev merged commit 1404177 into FarGroup:master Aug 16, 2026
48 checks passed
@alabuzhev

Copy link
Copy Markdown
Contributor

Thank you

@MKadaner
MKadaner deleted the mzk/menu_item_data branch August 16, 2026 19:15
@MKadaner

Copy link
Copy Markdown
Contributor Author

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants