Skip to content

Commit

Permalink
fix: Fix #522: slash key on Spanish ISO keyboards
Browse files Browse the repository at this point in the history
  • Loading branch information
arnog committed Jun 28, 2020
1 parent 377f72c commit ecbd4a2
Show file tree
Hide file tree
Showing 4 changed files with 240 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/editor/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export function update(
hu: 'qwertz',
sk: 'qwertz',
ch: 'qwertz',
}[l10n.locale.substring(0, 2)] || 'qwerty';
}[l10n.locale.substring(0, 2)] ?? 'qwerty';
} else {
result.virtualKeyboardLayout =
updates.virtualKeyboardLayout;
Expand Down Expand Up @@ -278,7 +278,7 @@ export function getDefault(): Required<MathfieldConfigPrivate> {
removeExtraneousParentheses: true,
ignoreSpacebarInMathMode: true,

locale: 'auto',
locale: l10n.locale,
strings: {},

keybindings: DEFAULT_KEYBINDINGS,
Expand Down
23 changes: 9 additions & 14 deletions src/editor/keybindings-definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,14 +264,14 @@ export const DEFAULT_KEYBINDINGS: Keybinding[] = [
command: ['insert', '$$\\backslash$$'],
}, // "|" key} override command mode
{
key: '[Slash]',
key: '/',
ifMode: 'math',
command: ['insert', '$$\\frac{#@}{#?}$$'],
},
{
key: 'alt+[Slash]',
key: 'alt+/',
ifMode: 'math',
command: ['insert', '$$\\frac{#?}{#@}$$'],
command: ['insert', '$$\\/$$'],
},
{
key: '[NumpadDivide]',
Expand All @@ -288,11 +288,6 @@ export const DEFAULT_KEYBINDINGS: Keybinding[] = [
ifMode: 'math',
command: ['insert', '$$\\~$$'],
}, // ??
{
key: 'alt+shift+[Slash]',
ifMode: 'math',
command: ['insert', '$$\\/$$'],
}, // ??

// Accessibility
{ key: 'alt+shift+k', command: 'toggleKeystrokeCaption' },
Expand All @@ -303,12 +298,12 @@ export const DEFAULT_KEYBINDINGS: Keybinding[] = [
// The workaround is to create a default binding file to silence them.
// In ~/Library/KeyBindings/DefaultKeyBinding.dict add these entries:
/*
{
"^@\UF701" = "noop:";
"^@\UF702" = "noop:";
"^@\UF703" = "noop:";
}
*/
{
"^@\UF701" = "noop:";
"^@\UF702" = "noop:";
"^@\UF703" = "noop:";
}
*/
{
key: 'ctrl+alt+[ArrowUp]',
command: ['speak', 'parent', { withHighlighting: false }],
Expand Down
9 changes: 5 additions & 4 deletions src/editor/keybindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,15 @@ export function getCommandForKeybinding(
keystroke: string
): Selector | any[] | '' {
if (keybindings.length === 0) return '';
for (let i = keybindings.length - 1; i--; i >= 0) {

// Try to match using a virtual keystroke
for (let i = keybindings.length - 1; i >= 0; i--) {
if (keybindings[i].key === keystroke) {
if (!keybindings[i].ifMode || keybindings[i].ifMode === mode) {
return keybindings[i].command;
}
}
}

return '';
}

Expand Down Expand Up @@ -199,7 +200,7 @@ export function getKeybindingMarkup(keystroke: string): string {
'[digit7]': '7',
'[digit8]': '8',
'[digit9]': '9',
}[segment.toLowerCase()] || segment.toUpperCase();
}[segment.toLowerCase()] ?? segment.toUpperCase();
}
}
return result;
Expand Down Expand Up @@ -254,7 +255,7 @@ function normalizeKeybinding(keybinding: Keybinding): Keybinding {
if (!code) {
throw new Error('Invalid keybinding key "' + keybinding.key + '"');
}
segments.push(code);
segments = segments.concat(code.split('+'));
} else {
segments.push(key);
}
Expand Down
225 changes: 224 additions & 1 deletion src/editor/keyboard-layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,10 +511,13 @@ export function register(layout: KeyboardLayout): void {
// }

export function getCodeForKey(k: string): string {
const layout = gKeyboardLayouts[0] ?? DEFAULT_KEYBOARD_LAYOUT;
const layout = getActiveKeyboardLayout() ?? DEFAULT_KEYBOARD_LAYOUT;

for (const [key, value] of Object.entries(layout.mapping)) {
if (value[0] === k) return '[' + key + ']';
if (value[1] === k) return 'shift+[' + key + ']';
if (value[2] === k) return 'alt+[' + key + ']';
if (value[3] === k) return 'shift+alt+[' + key + ']';
}

return BASE_LAYOUT_MAPPING[k] ?? '';
Expand Down Expand Up @@ -665,6 +668,226 @@ register({
},
});

register({
id: 'apple.spanish',
locale: 'es',
displayName: 'Spanish ISO',
platform: 'apple',
score: 0,
mapping: {
KeyA: ['a', 'A', 'å', 'Å'],
KeyB: ['b', 'B', 'ß', ''],
KeyC: ['c', 'C', '©', ' '],
KeyD: ['d', 'D', '∂', '∆'],
KeyE: ['e', 'E', '€', '€'],
KeyF: ['f', 'F', 'ƒ', 'fi'],
KeyG: ['g', 'G', '', 'fl'],
KeyH: ['h', 'H', '™', ' '],
KeyI: ['i', 'I', ' ', ' '],
KeyJ: ['j', 'J', '¶', '¯'],
KeyK: ['k', 'K', '§', 'ˇ'],
KeyL: ['l', 'L', ' ', '˘'],
KeyM: ['m', 'M', 'µ', '˚'],
KeyN: ['n', 'N', ' ', '˙'],
KeyO: ['o', 'O', 'ø', 'Ø'],
KeyP: ['p', 'P', 'π', '∏'],
KeyQ: ['q', 'Q', 'œ', 'Œ'],
KeyR: ['r', 'R', '®', ' '],
KeyS: ['s', 'S', '∫', ' '],
KeyT: ['t', 'T', '†', '‡'],
KeyU: ['u', 'U', ' ', ' '],
KeyV: ['v', 'V', '√', '◊'],
KeyW: ['w', 'W', 'æ', 'Æ'],
KeyX: ['x', 'X', '∑', '›'],
KeyY: ['y', 'Y', '¥', ' '],
KeyZ: ['z', 'Z', 'Ω', '‹'],
Digit1: ['1', '!', '|', 'ı'],
Digit2: ['2', '"', '@', '˝'],
Digit3: ['3', '·', '#', '•'],
Digit4: ['4', '$', '¢', '£'],
Digit5: ['5', '%', '∞', '‰'],
Digit6: ['6', '&', '¬', ' '],
Digit7: ['7', '/', '÷', '⁄'],
Digit8: ['8', '(', '“', '‘'],
Digit9: ['9', ')', '”', '’'],
Digit0: ['0', '=', '≠', '≈'],
Space: [' ', ' ', ' ', ' '],
Minus: ["'", '?', '´', '¸'],
Equal: ['¡', '¿', '‚', '˛'],
BracketLeft: ['`', '^', '[', 'ˆ'],
BracketRight: ['+', '*', ']', '±'],
Backslash: ['ç', 'Ç', '}', '»'],
Semicolon: ['ñ', 'Ñ', '~', '˜'],
Quote: ['´', '¨', '{', '«'],
Backquote: ['<', '>', '≤', '≥'],
Comma: [',', ';', '„', ''],
Period: ['.', ':', '…', '…'],
Slash: ['-', '_', '–', '—'],
NumpadDivide: ['/', '/', '/', '/'],
NumpadMultiply: ['*', '*', '*', '*'],
NumpadSubtract: ['-', '-', '-', '-'],
NumpadAdd: ['+', '+', '+', '+'],
Numpad1: ['1', '1', '1', '1'],
Numpad2: ['2', '2', '2', '2'],
Numpad3: ['3', '3', '3', '3'],
Numpad4: ['4', '4', '4', '4'],
Numpad5: ['5', '5', '5', '5'],
Numpad6: ['6', '6', '6', '6'],
Numpad7: ['7', '7', '7', '7'],
Numpad8: ['8', '8', '8', '8'],
Numpad9: ['9', '9', '9', '9'],
Numpad0: ['0', '0', '0', '0'],
NumpadDecimal: [',', ',', ',', ','],
IntlBackslash: ['º', 'ª', '\\', '°'],
},
});

register({
id: 'windows.spanish',
locale: 'es',
displayName: 'Spanish',
platform: 'windows',
score: 0,
mapping: {
KeyA: ['a', 'A', '', ''],
KeyB: ['b', 'B', '', ''],
KeyC: ['c', 'C', '', ''],
KeyD: ['d', 'D', '', ''],
KeyE: ['e', 'E', '€', ''],
KeyF: ['f', 'F', '', ''],
KeyG: ['g', 'G', '', ''],
KeyH: ['h', 'H', '', ''],
KeyI: ['i', 'I', '', ''],
KeyJ: ['j', 'J', '', ''],
KeyK: ['k', 'K', '', ''],
KeyL: ['l', 'L', '', ''],
KeyM: ['m', 'M', '', ''],
KeyN: ['n', 'N', '', ''],
KeyO: ['o', 'O', '', ''],
KeyP: ['p', 'P', '', ''],
KeyQ: ['q', 'Q', '', ''],
KeyR: ['r', 'R', '', ''],
KeyS: ['s', 'S', '', ''],
KeyT: ['t', 'T', '', ''],
KeyU: ['u', 'U', '', ''],
KeyV: ['v', 'V', '', ''],
KeyW: ['w', 'W', '', ''],
KeyX: ['x', 'X', '', ''],
KeyY: ['y', 'Y', '', ''],
KeyZ: ['z', 'Z', '', ''],
Digit1: ['1', '!', '|', ''],
Digit2: ['2', '"', '@', ''],
Digit3: ['3', '·', '#', ''],
Digit4: ['4', '$', '~', ''],
Digit5: ['5', '%', '€', ''],
Digit6: ['6', '&', '¬', ''],
Digit7: ['7', '/', '', ''],
Digit8: ['8', '(', '', ''],
Digit9: ['9', ')', '', ''],
Digit0: ['0', '=', '', ''],
Space: [' ', ' ', '', ''],
Minus: ["'", '?', '', ''],
Equal: ['¡', '¿', '', ''],
BracketLeft: ['`', '^', '[', ''],
BracketRight: ['+', '*', ']', ''],
Backslash: ['ç', 'Ç', '}', ''],
Semicolon: ['ñ', 'Ñ', '', ''],
Quote: ['´', '¨', '{', ''],
Backquote: ['º', 'ª', '\\', ''],
Comma: [',', ';', '', ''],
Period: ['.', ':', '', ''],
Slash: ['-', '_', '', ''],
NumpadDivide: ['/', '/', '', ''],
NumpadMultiply: ['*', '*', '', ''],
NumpadSubtract: ['-', '-', '', ''],
NumpadAdd: ['+', '+', '', ''],
IntlBackslash: ['<', '>', '', ''],
},
});

register({
id: 'linux.spanish',
locale: 'es',
displayName: 'Spanish',
platform: 'linux',
score: 0,
mapping: {
KeyA: ['a', 'A', 'æ', 'Æ'],
KeyB: ['b', 'B', '”', '’'],
KeyC: ['c', 'C', '¢', '©'],
KeyD: ['d', 'D', 'ð', 'Ð'],
KeyE: ['e', 'E', '€', '¢'],
KeyF: ['f', 'F', 'đ', 'ª'],
KeyG: ['g', 'G', 'ŋ', 'Ŋ'],
KeyH: ['h', 'H', 'ħ', 'Ħ'],
KeyI: ['i', 'I', '→', 'ı'],
KeyJ: ['j', 'J', '̉', '̛'],
KeyK: ['k', 'K', 'ĸ', '&'],
KeyL: ['l', 'L', 'ł', 'Ł'],
KeyM: ['m', 'M', 'µ', 'º'],
KeyN: ['n', 'N', 'n', 'N'],
KeyO: ['o', 'O', 'ø', 'Ø'],
KeyP: ['p', 'P', 'þ', 'Þ'],
KeyQ: ['q', 'Q', '@', 'Ω'],
KeyR: ['r', 'R', '¶', '®'],
KeyS: ['s', 'S', 'ß', '§'],
KeyT: ['t', 'T', 'ŧ', 'Ŧ'],
KeyU: ['u', 'U', '↓', '↑'],
KeyV: ['v', 'V', '“', '‘'],
KeyW: ['w', 'W', 'ł', 'Ł'],
KeyX: ['x', 'X', '»', '>'],
KeyY: ['y', 'Y', '←', '¥'],
KeyZ: ['z', 'Z', '«', '<'],
Digit1: ['1', '!', '|', '¡'],
Digit2: ['2', '"', '@', '⅛'],
Digit3: ['3', '·', '#', '£'],
Digit4: ['4', '$', '~', '$'],
Digit5: ['5', '%', '½', '⅜'],
Digit6: ['6', '&', '¬', '⅝'],
Digit7: ['7', '/', '{', '⅞'],
Digit8: ['8', '(', '[', '™'],
Digit9: ['9', ')', ']', '±'],
Digit0: ['0', '=', '}', '°'],
Enter: ['\r', '\r', '\r', '\r'],
Escape: ['\u001b', '\u001b', '\u001b', '\u001b'],
Backspace: ['\b', '\b', '\b', '\b'],
Tab: ['\t', '', '\t', ''],
Space: [' ', ' ', ' ', ' '],
Minus: ["'", '?', '\\', '¿'],
Equal: ['¡', '¿', '̃', '~'],
BracketLeft: ['̀', '̂', '[', '̊'],
BracketRight: ['+', '*', ']', '̄'],
Backslash: ['ç', 'Ç', '}', '̆'],
Semicolon: ['ñ', 'Ñ', '~', '̋'],
Quote: ['́', '̈', '{', '{'],
Backquote: ['º', 'ª', '\\', '\\'],
Comma: [',', ';', '─', '×'],
Period: ['.', ':', '·', '÷'],
Slash: ['-', '_', '̣', '̇'],
NumpadDivide: ['/', '/', '/', '/'],
NumpadMultiply: ['*', '*', '*', '*'],
NumpadSubtract: ['-', '-', '-', '-'],
NumpadAdd: ['+', '+', '+', '+'],
NumpadEnter: ['\r', '\r', '\r', '\r'],
Numpad1: ['', '1', '', '1'],
Numpad2: ['', '2', '', '2'],
Numpad3: ['', '3', '', '3'],
Numpad4: ['', '4', '', '4'],
Numpad5: ['', '5', '', '5'],
Numpad6: ['', '6', '', '6'],
Numpad7: ['', '7', '', '7'],
Numpad8: ['', '8', '', '8'],
Numpad9: ['', '9', '', '9'],
Numpad0: ['', '0', '', '0'],
NumpadDecimal: ['', '.', '', '.'],
IntlBackslash: ['<', '>', '|', '¦'],
NumpadEqual: ['=', '=', '=', '='],
NumpadComma: ['.', '.', '.', '.'],
NumpadParenLeft: ['(', '(', '(', '('],
NumpadParenRight: [')', ')', ')', ')'],
},
});

register({
id: 'linux.french',
locale: 'fr',
Expand Down

0 comments on commit ecbd4a2

Please sign in to comment.