Hello!
Context
XWIKI-16216 asks to let users rebind the keyboard shortcuts from their user profile. We already decided where the UI goes. A proposed implementation is in PR #2981.
Today, the shortcuts are defined at the wiki level only, as translation keys like core.shortcuts.view.edit=e. An admin can change them for the whole wiki with a translation page (documentation), but a user can’t change them for themselves.
Proposal
Storage
I propose a new class XWiki.UserPreferenceShortcutsClass with two string properties:
translationKey: the shortcut being overridden, for examplecore.shortcuts.view.information.value: the user’s shortcut, for exampleb. An empty value would mean the user unbound this shortcut.
A user profile would hold one object per shortcut the user changed, and nothing else. If there’s no object for a shortcut, the wiki default from the translations would apply. A user who never touches the feature would have no extra data at all.
The value would use the same syntax as the translation it overrides, so it could hold any shortcut the wiki defaults can: a modifier combination like Alt+C, a special key like F2, or a sequence like x+x+x+a. In the user profile of the PR, the shortcut is a plain text field. Its hint recommends a single key to keep it simple, but combinations like Alt+Q work too. A sequence would be stored the same way, but the developer shortcuts of the PR register a customized value as a single-key shortcut.
Using the translation key as the identifier means the storage wouldn’t need to change when a shortcut is added, including one added by an extension. This is the main reason I moved away from the first version of the PR, which added one property per shortcut to XWiki.XWikiUsers.
This proposal wouldn’t block extensibility, but it wouldn’t complete it either. Two things would still be missing for an extension to make its shortcuts customizable:
- The preferences UI of the PR is a fixed list of the core shortcuts, with no extension point to add rows.
#getShortcutValueis a macro of the Flamingo skin, which an extension can’t rely on.
Both could be added later on top of this storage, for example with the Java component of option 3 below.
Resolving a shortcut
A Velocity macro #getShortcutValue($translationKey) in the skin would resolve the shortcut to use:
It would read the user profile from $crtUserDoc, which is already loaded when a page is displayed, so getting all the shortcuts of a page would cost one getObject call per shortcut and no extra document loading.
Where it’s used
In the Flamingo skin, every place that registers a shortcut from a translation would go through this macro:
The editor buttons (Save, Cancel, Preview…) are a special case. Their shortcuts are registered in actionButtons.js. This skin file is evaluated with Velocity, but its URL is the same for every user and it’s served with Cache-Control: public for 30 days. Putting per-user values in it would serve one user’s shortcuts to another through the browser and proxy caches. Instead, the button would carry its shortcut in a data-shortcut attribute and the script would read it from there. Buttons that don’t have this attribute would keep the current default shortcuts.
Saving
In the preferences edit form, each shortcut would be a text input with a Reset button. The shortcuts would be saved with the form, like the other preferences, so Save and Cancel would apply to them too:
This would rely on the standard addedObjects and deletedObjects parameters of the save action. A small script would only decide, for each row, what the form submits:
Data
Since the translation key would identify the shortcut, it would become part of the stored user data:
- An object whose translation key no longer exists, for example after a shortcut is removed, would simply be ignored. It wouldn’t break anything, but it would stay on the profile since the UI no longer shows that shortcut.
- If a profile holds two objects for the same key, the first one would be used. The UI would never create a duplicate, since it updates the existing object.
- Renaming a
core.shortcuts.*key would silently drop the users’ customizations of that shortcut. This has happened before,core.shortcuts.edit.saveandcontinuebecamecore.shortcuts.edit.savein 10.6. From now on, such a rename would need a migration of the objects, or would need to be avoided.
Open question: where the class lives
In the PR, XWiki.UserPreferenceShortcutsClass is a wiki page in the xwiki-platform-user-profile-ui XAR. But the skin (macros.vm, menus_content.vm, docextra.vm, shortcuts.vm) is what reads it, and the skin doesn’t depend on the user profile UI. If the class page is missing, getObject finds nothing and every shortcut falls back to its default, so nothing breaks, but the dependency isn’t explicit.
- Keep the class in
xwiki-platform-user-profile-ui, next to the UI that edits it. - Create the class with a mandatory document initializer in Java, so it exists as soon as the wiki starts, whatever is installed. It would go in
xwiki-platform-user-default, asorg.xwiki.user.internal.shortcut.UserPreferenceShortcutsClassDocumentInitializerextendingAbstractMandatoryClassInitializer. This module is a core extension already bundled in the WAR, it’s about users, and it keeps the class out ofoldcore, where new code shouldn’t go. This is the same pattern asEditorBindingClassDocumentInitializerinxwiki-platform-edit-default. - Option 2, plus a Java component that resolves the shortcuts of the current user and lists the available ones, exposed through a script service in
xwiki-platform-user-script, instead of the Velocity macro. This is also what would let extensions declare their own customizable shortcuts.
Opinion
+1 for the storage design described above because:
- It only stores what the user actually changed.
- Adding a shortcut, including from an extension, would never require changing the class, so it wouldn’t block full extensibility later.
- Resetting to the default would just be deleting an object, and wiki-level defaults would keep working as before.
For the open question, I’m +1 for option 2 because:
- The skin reads the class, so the class should exist independently of an optional UI module.
Conclusion
Do you agree with storing the shortcut preferences as one object per customized shortcut on the user profile? Which option do you prefer for the location of the class?
I’ll close this topic in a week and update the PR with its result if it doesn’t spur a large discussion.
Thank you!
Lucas C.




