Skip to content

Commit 08f21f0

Browse files
committed
Make also locale dependant shortcuts work in browser
Signed-off-by: Samuel Mehrbrodt <samuel.mehrbrodt@collabora.com> Change-Id: I3268ae0ace30d62878d29fafb3c401a8e5fbb0df
1 parent 5f39a8c commit 08f21f0

4 files changed

Lines changed: 519 additions & 44 deletions

File tree

browser/src/control/jsdialog/Util.Shortcuts.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@ class ShortcutsUtil {
4343
this.shortcutMap.set(command, shortcut as string);
4444
}
4545

46+
// Apply per-language shortcut overrides from Accelerators.xcu.
47+
// Core defines different key combos per language
48+
for (const [lang, overrides] of Object.entries(unoShortcutsL10N)) {
49+
if ((String as any).locale.startsWith(lang)) {
50+
const o = overrides as Record<string, string>;
51+
for (const [command, shortcut] of Object.entries(o)) {
52+
this.shortcutMap.set(command, shortcut);
53+
}
54+
break;
55+
}
56+
}
57+
4658
// Aliases: non-UNO IDs that resolve to a UNO command's shortcut.
4759
for (const [alias, unoCmd] of Object.entries(UNO_ALIASES)) {
4860
const shortcut = this.shortcutMap.get(unoCmd);

browser/src/map/handler/Map.KeyboardShortcuts.ts

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -391,35 +391,50 @@ keyboardShortcuts.definitions.set('default', new Array<ShortcutDescriptor>(
391391
new ShortcutDescriptor({ eventType: 'keydown', modifier: Mod.CTRL, key: '`', preventDefault: false, platform: Platform.MAC }), // Cycle through windows
392392
));
393393

394-
// German shortcuts.
394+
// German shortcuts: only online-specific dispatchAction entries and
395+
// passthrough shortcuts. UNO command bindings are generated from
396+
// Accelerators.xcu (see below).
395397
keyboardShortcuts.definitions.set('de', new Array<ShortcutDescriptor>(
396398
new ShortcutDescriptor({ eventType: 'keydown', key: 'F12', dispatchAction: 'saveas' }),
397-
398-
new ShortcutDescriptor({ docType: 'presentation', eventType: 'keydown', modifier: Mod.SHIFT, key: 'F9', unoAction: '.uno:GridVisible' }),
399-
new ShortcutDescriptor({ docType: 'presentation', eventType: 'keydown', modifier: Mod.SHIFT, key: 'F3', unoAction: '.uno:ChangeCaseRotateCase' }),
400-
new ShortcutDescriptor({ docType: 'presentation', eventType: 'keydown', modifier: Mod.SHIFT, key: 'F5', dispatchAction: 'presentation' }), // Already available without this shortcut.
401-
new ShortcutDescriptor({ eventType: 'keydown', modifier: Mod.SHIFT | Mod.CTRL, key: 'F', unoAction: '.uno:Bold' }),
402-
new ShortcutDescriptor({ eventType: 'keydown', modifier: Mod.SHIFT | Mod.CTRL, key: 'K', unoAction: '.uno:Italic' }),
403-
new ShortcutDescriptor({ eventType: 'keydown', modifier: Mod.SHIFT | Mod.CTRL, key: 'U', unoAction: '.uno:Underline' }),
404-
405-
new ShortcutDescriptor({ docType: 'text', eventType: 'keydown', modifier: Mod.SHIFT, key: 'F3', unoAction: '.uno:ChangeCaseRotateCase' }),
406-
new ShortcutDescriptor({ docType: 'text', eventType: 'keydown', key: 'F5', unoAction: '.uno:GoToPage' }),
407-
new ShortcutDescriptor({ docType: 'text', eventType: 'keydown', modifier: Mod.ALT | Mod.CTRL, key: 's', dispatchAction: 'home-search' }),
408-
409-
new ShortcutDescriptor({ docType: 'spreadsheet', eventType: 'keydown', modifier: Mod.SHIFT, key: 'F3', unoAction: '.uno:FunctionDialog' }),
399+
new ShortcutDescriptor({ docType: 'presentation', eventType: 'keydown', modifier: Mod.SHIFT, key: 'F5', dispatchAction: 'presentation' }),
400+
new ShortcutDescriptor({ docType: 'text', eventType: 'keydown', modifier: Mod.ALT | Mod.CTRL, key: 's', dispatchAction: 'home-search' }),
410401
new ShortcutDescriptor({ docType: 'spreadsheet', eventType: 'keydown', modifier: Mod.SHIFT, key: 'F2', dispatchAction: 'insertcomment' }),
411402
new ShortcutDescriptor({ docType: 'spreadsheet', eventType: 'keydown', key: 'F4', dispatchAction: 'togglerelative' }),
412-
new ShortcutDescriptor({ docType: 'spreadsheet', eventType: 'keydown', key: 'F9', unoAction: '.uno:Calculate' }),
413403
new ShortcutDescriptor({ docType: 'spreadsheet', eventType: 'keydown', key: 'F5', dispatchAction: 'focusonaddressinput' }),
414-
new ShortcutDescriptor({ docType: 'spreadsheet', eventType: 'keydown', modifier: Mod.ALT, key: '0', unoAction: '.uno:FormatCellDialog' }),
415-
416404
// Passthrough some system shortcuts
417405
new ShortcutDescriptor({ eventType: 'keydown', modifier: Mod.CTRL | Mod.SHIFT, key: '`', preventDefault: false, platform: Platform.MAC }), // Cycle through windows
418406
));
419407

420-
// French shortcuts.
421-
keyboardShortcuts.definitions.set('fr', new Array<ShortcutDescriptor>(
422-
new ShortcutDescriptor({ eventType: 'keydown', modifier: Mod.CTRL, key: 'g', unoAction: '.uno:Bold' }),
423-
));
408+
// Register per-language keyboard shortcuts generated from core's
409+
// Accelerators.xcu by scripts/unoshortcuts.py.
410+
if (typeof unoShortcutsL10NKeyBindings !== 'undefined') {
411+
for (const [lang, bindings] of Object.entries(unoShortcutsL10NKeyBindings)) {
412+
let existing = keyboardShortcuts.definitions.get(lang);
413+
if (!existing) {
414+
existing = new Array<ShortcutDescriptor>();
415+
keyboardShortcuts.definitions.set(lang, existing);
416+
}
417+
418+
// Track key+modifier combos already defined manually so we
419+
// don't create duplicates (which would throw in findShortcut).
420+
const existingKeys = new Set<string>();
421+
for (const d of existing) {
422+
existingKeys.add(d.key + '|' + d.modifier);
423+
}
424+
425+
for (const b of bindings as any[]) {
426+
const k = b.key + '|' + b.modifier;
427+
if (!existingKeys.has(k)) {
428+
existing.push(new ShortcutDescriptor({
429+
eventType: 'keydown',
430+
key: b.key,
431+
modifier: b.modifier,
432+
unoAction: b.unoAction,
433+
}));
434+
existingKeys.add(k);
435+
}
436+
}
437+
}
438+
}
424439

425440
window.KeyboardShortcuts = keyboardShortcuts;

browser/src/unoshortcuts.js

Lines changed: 176 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ var unoShortcutsMap = {
1818
'.uno:Copy': 'Ctrl+C',
1919
'.uno:Cut': 'Ctrl+X',
2020
'.uno:DataFilterAutoFilter': 'Ctrl+Shift+L',
21-
'.uno:DefaultBullet': 'Shift+F12',
22-
'.uno:DefaultNumbering': 'F12',
21+
'.uno:DefaultBullet': 'Ctrl+Shift+L',
2322
'.uno:DefineName': 'Ctrl+F3',
2423
'.uno:Delete': 'Delete',
2524
'.uno:DeleteCell': 'Ctrl+-',
@@ -32,7 +31,7 @@ var unoShortcutsMap = {
3231
'.uno:FunctionDialog': 'Ctrl+F2',
3332
'.uno:GotoPage': 'Ctrl+Shift+F5',
3433
'.uno:GraphicDialog': 'F4',
35-
'.uno:Group': 'F12',
34+
'.uno:Group': 'Shift+Alt+Right',
3635
'.uno:Grow': 'Ctrl+]',
3736
'.uno:HyperlinkDialog': 'Ctrl+K',
3837
'.uno:InsertAnnotation': 'Ctrl+Alt+C',
@@ -109,6 +108,180 @@ var unoShortcutsMap = {
109108
'.uno:ZoomPlus': 'Ctrl+Shift+PageUp',
110109
};
111110

111+
var unoShortcutsL10N = {
112+
bs: {
113+
'.uno:InsertCurrentDate': 'Ctrl+,',
114+
'.uno:InsertCurrentTime': 'Ctrl+Shift+,',
115+
},
116+
da: {
117+
'.uno:InsertCurrentDate': 'Ctrl+,',
118+
'.uno:InsertCurrentTime': 'Ctrl+Shift+,',
119+
},
120+
de: {
121+
'.uno:AlignBlock': 'Ctrl+B',
122+
'.uno:Bold': 'Ctrl+Shift+F',
123+
'.uno:ChangeCaseRotateCase': 'Ctrl+Shift+F3',
124+
'.uno:FormatCellDialog': 'Alt+0',
125+
'.uno:FormatUngroup': 'Ctrl+Shift+H',
126+
'.uno:FunctionDialog': 'Shift+F3',
127+
'.uno:Group': 'Ctrl+F12',
128+
'.uno:InsertAnnotation': 'Shift+F2',
129+
'.uno:InsertCurrentDate': 'Ctrl+.',
130+
'.uno:InsertCurrentTime': 'Ctrl+Shift+.',
131+
'.uno:Italic': 'Ctrl+Shift+K',
132+
'.uno:Navigator': 'Ctrl+F',
133+
'.uno:PasteSpecial': 'Ctrl+Alt+V',
134+
'.uno:SearchDialog': 'Ctrl+Alt+F',
135+
'.uno:Shrink': 'Ctrl+Shift+;',
136+
'.uno:SmallCaps': 'Ctrl+Shift+Q',
137+
'.uno:Strikeout': 'Ctrl+5',
138+
'.uno:SubScript': 'Ctrl+T',
139+
'.uno:SuperScript': 'Ctrl+H',
140+
'.uno:Underline': 'Ctrl+Shift+U',
141+
'.uno:UnderlineDouble': 'Ctrl+Shift+D',
142+
'.uno:Ungroup': 'Ctrl+Shift+F12',
143+
},
144+
es: {
145+
'.uno:AlignHorizontalCenter': 'Ctrl+T',
146+
'.uno:Bold': 'Ctrl+N',
147+
'.uno:HyperlinkDialog': 'Ctrl+Alt+K',
148+
'.uno:InsertCurrentDate': 'Ctrl+,',
149+
'.uno:InsertCurrentTime': 'Ctrl+Shift+,',
150+
'.uno:Italic': 'Ctrl+K',
151+
'.uno:Save': 'Ctrl+G',
152+
'.uno:SearchDialog': 'Ctrl+Alt+B',
153+
'.uno:SelectAll': 'Ctrl+E',
154+
'.uno:Underline': 'Ctrl+S',
155+
},
156+
et: {
157+
'.uno:InsertCurrentDate': 'Ctrl+,',
158+
'.uno:InsertCurrentTime': 'Ctrl+Shift+,',
159+
},
160+
fi: {
161+
'.uno:InsertCurrentDate': 'Ctrl+,',
162+
'.uno:InsertCurrentTime': 'Ctrl+Shift+,',
163+
},
164+
fo: {
165+
'.uno:InsertCurrentDate': 'Ctrl+,',
166+
'.uno:InsertCurrentTime': 'Ctrl+Shift+,',
167+
},
168+
fr: {
169+
'.uno:Bold': 'Ctrl+G',
170+
'.uno:InsertCurrentTime': 'Ctrl+:',
171+
},
172+
hr: {
173+
'.uno:InsertCurrentDate': 'Ctrl+,',
174+
'.uno:InsertCurrentTime': 'Ctrl+Shift+,',
175+
},
176+
hu: {
177+
'.uno:InsertAnnotation': 'Ctrl+Shift+H',
178+
'.uno:InsertCurrentDate': 'Ctrl+.',
179+
'.uno:InsertCurrentTime': 'Ctrl+Shift+.',
180+
'.uno:Shrink': 'Ctrl+Shift+,',
181+
},
182+
is: {
183+
'.uno:InsertCurrentDate': 'Ctrl+,',
184+
'.uno:InsertCurrentTime': 'Ctrl+Shift+,',
185+
},
186+
it: {
187+
'.uno:InsertCurrentDate': 'Ctrl+,',
188+
'.uno:InsertCurrentTime': 'Ctrl+Shift+,',
189+
},
190+
nb: {
191+
'.uno:InsertCurrentDate': 'Ctrl+,',
192+
'.uno:InsertCurrentTime': 'Ctrl+Shift+,',
193+
},
194+
nn: {
195+
'.uno:InsertCurrentDate': 'Ctrl+,',
196+
'.uno:InsertCurrentTime': 'Ctrl+Shift+,',
197+
},
198+
pt: {
199+
'.uno:InsertCurrentDate': 'Ctrl+,',
200+
'.uno:InsertCurrentTime': 'Ctrl+Shift+,',
201+
},
202+
'pt-BR': {
203+
'.uno:InsertCurrentDate': 'Ctrl+,',
204+
'.uno:InsertCurrentTime': 'Ctrl+Shift+,',
205+
},
206+
ro: {
207+
'.uno:InsertCurrentDate': 'Ctrl+,',
208+
'.uno:InsertCurrentTime': 'Ctrl+Shift+,',
209+
},
210+
ru: {
211+
'.uno:InsertCurrentDate': 'Ctrl+,',
212+
'.uno:InsertCurrentTime': 'Ctrl+Shift+,',
213+
},
214+
sl: {
215+
'.uno:InsertCurrentDate': 'Ctrl+,',
216+
'.uno:InsertCurrentTime': 'Ctrl+Shift+,',
217+
},
218+
sq: {
219+
'.uno:InsertCurrentDate': 'Ctrl+,',
220+
'.uno:InsertCurrentTime': 'Ctrl+Shift+,',
221+
},
222+
sr: {
223+
'.uno:InsertCurrentDate': 'Ctrl+,',
224+
'.uno:InsertCurrentTime': 'Ctrl+Shift+,',
225+
},
226+
sv: {
227+
'.uno:Grow': 'Ctrl+9',
228+
'.uno:InsertCurrentDate': 'Ctrl+,',
229+
'.uno:InsertCurrentTime': 'Ctrl+Shift+,',
230+
'.uno:Shrink': 'Ctrl+8',
231+
},
232+
tr: {
233+
'.uno:InsertCurrentDate': 'Ctrl+,',
234+
'.uno:InsertCurrentTime': 'Ctrl+Shift+,',
235+
},
236+
};
237+
238+
var unoShortcutsL10NKeyBindings = {
239+
de: [
240+
{ key: 'b', modifier: 1, unoAction: '.uno:AlignBlock' },
241+
{ key: 'F', modifier: 5, unoAction: '.uno:Bold' },
242+
{ key: '+', modifier: 5, unoAction: '.uno:CalculateSel' },
243+
{ key: 'd', modifier: 1, unoAction: '.uno:CopyObjects' },
244+
{ key: 'M', modifier: 5, unoAction: '.uno:DecrementIndent' },
245+
{ key: '/', modifier: 1, unoAction: '.uno:DefaultNumbering' },
246+
{ key: 'F5', modifier: 0, unoAction: '.uno:FocusCellAddress' },
247+
{ key: 'F3', modifier: 4, unoAction: '.uno:FunctionDialog' },
248+
{ key: 'F9', modifier: 4, unoAction: '.uno:GridVisible' },
249+
{ key: 'F12', modifier: 1, unoAction: '.uno:Group' },
250+
{ key: 'm', modifier: 1, unoAction: '.uno:IncrementIndent' },
251+
{ key: 'K', modifier: 5, unoAction: '.uno:Italic' },
252+
{ key: 'f', modifier: 1, unoAction: '.uno:Navigator' },
253+
{ key: 'g', modifier: 1, unoAction: '.uno:RecSearch' },
254+
{ key: ' ', modifier: 1, unoAction: '.uno:RemoveDirectCharFormats' },
255+
{ key: 'F9', modifier: 1, unoAction: '.uno:ShowRuler' },
256+
{ key: ';', modifier: 5, unoAction: '.uno:Shrink' },
257+
{ key: 'Q', modifier: 5, unoAction: '.uno:SmallCaps' },
258+
{ key: '1', modifier: 1, unoAction: '.uno:SpacePara1' },
259+
{ key: '5', modifier: 1, unoAction: '.uno:Strikeout' },
260+
{ key: '+', modifier: 1, unoAction: '.uno:SubScript' },
261+
{ key: '*', modifier: 1, unoAction: '.uno:SuperScript' },
262+
{ key: 'h', modifier: 1, unoAction: '.uno:SuperScript' },
263+
{ key: 'D', modifier: 5, unoAction: '.uno:UnderlineDouble' },
264+
{ key: 'F12', modifier: 5, unoAction: '.uno:Ungroup' },
265+
{ key: 'c', modifier: 2, unoAction: '.uno:UnicodeNotationToggle' },
266+
],
267+
es: [
268+
{ key: 'u', modifier: 1, unoAction: '.uno:AddDirect' },
269+
{ key: 'n', modifier: 1, unoAction: '.uno:Bold' },
270+
{ key: 'k', modifier: 1, unoAction: '.uno:Italic' },
271+
{ key: 'a', modifier: 1, unoAction: '.uno:Open' },
272+
{ key: 'g', modifier: 1, unoAction: '.uno:Save' },
273+
{ key: 'e', modifier: 1, unoAction: '.uno:SelectAll' },
274+
{ key: 's', modifier: 1, unoAction: '.uno:Underline' },
275+
],
276+
eu: [{ key: 'c', modifier: 2, unoAction: '.uno:UnicodeNotationToggle' }],
277+
fr: [{ key: 'g', modifier: 1, unoAction: '.uno:Bold' }],
278+
gl: [{ key: 'c', modifier: 2, unoAction: '.uno:UnicodeNotationToggle' }],
279+
nl: [{ key: 'c', modifier: 2, unoAction: '.uno:UnicodeNotationToggle' }],
280+
'pt-BR': [{ key: 'c', modifier: 2, unoAction: '.uno:UnicodeNotationToggle' }],
281+
'zh-CN': [{ key: ' ', modifier: 5, unoAction: '.uno:SelectColumn' }],
282+
'zh-TW': [{ key: ' ', modifier: 5, unoAction: '.uno:SelectColumn' }],
283+
};
284+
112285
var unoShortcutsModifierL10N = {
113286
ca: { Shift: 'Maj' },
114287
de: { Ctrl: 'Strg', Shift: 'Umschalt' },

0 commit comments

Comments
 (0)