From a34be50ca2903afa67f5c35d2a0b514696249164 Mon Sep 17 00:00:00 2001 From: Arno Gourdol Date: Wed, 12 Jun 2024 14:29:20 -0700 Subject: [PATCH] fix: fixed #2396 --- CHANGELOG.md | 6 +++-- src/editor/commands.ts | 4 ++-- src/public/virtual-keyboard.ts | 1 + src/virtual-keyboard/utils.ts | 30 ++++++++++++------------ src/virtual-keyboard/virtual-keyboard.ts | 5 ++-- 5 files changed, 25 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3825ee36b..0c6116a21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,10 +2,12 @@ ### Bug Fixes - - **#2392** Pressing the backspace key after typing several digits would - delete all the digits. +- **#2396** Pressing the arrow keys in the virtual keyboard would not move the + selection in the mathfield and display a runtime error in the console. - **#2395** Added a `dispatchEvent` command which can be attached to a custom keycap. +- **#2392** Pressing the backspace key after typing several digits would + delete all the digits. Its first argument is the name of the dispatched event, and the second argument is an object with the `detail` property, which is the data diff --git a/src/editor/commands.ts b/src/editor/commands.ts index eb6cff020..274e941ea 100644 --- a/src/editor/commands.ts +++ b/src/editor/commands.ts @@ -238,7 +238,7 @@ register( */ export function parseCommand( command: undefined | string | [string, ...any[]] -): [SelectorPrivate, ...any[]] | undefined { +): [SelectorPrivate, ...any[]] | SelectorPrivate | undefined { if (!command) return undefined; if (isArray(command) && command.length > 0) { let selector = command[0]; @@ -283,5 +283,5 @@ export function parseCommand( let selector = command; selector.replace(/-\w/g, (m) => m[1].toUpperCase()); - return [selector as SelectorPrivate]; + return selector as SelectorPrivate; } diff --git a/src/public/virtual-keyboard.ts b/src/public/virtual-keyboard.ts index 65a727fb8..3127a8914 100644 --- a/src/public/virtual-keyboard.ts +++ b/src/public/virtual-keyboard.ts @@ -29,6 +29,7 @@ export interface VirtualKeyboardKeycap { * Command to perform when the keycap is pressed */ command: + | string | Selector | string[] | [string, any] diff --git a/src/virtual-keyboard/utils.ts b/src/virtual-keyboard/utils.ts index ef0bd7925..1bfc55ffe 100644 --- a/src/virtual-keyboard/utils.ts +++ b/src/virtual-keyboard/utils.ts @@ -718,54 +718,54 @@ const KEYCAP_SHORTCUTS: Record> = { '[left]': { class: 'action hide-shift', label: '', - command: ['performWithFeedback', 'moveToPreviousChar'], + command: 'performWithFeedback(moveToPreviousChar)', shift: { label: '', - command: ['performWithFeedback', 'extendSelectionBackward'], + command: 'performWithFeedback(extendSelectionBackward)', }, }, '[right]': { class: 'action hide-shift', label: '', - command: ['performWithFeedback', 'moveToNextChar'], + command: 'performWithFeedback(moveToNextChar)', shift: { label: '', - command: ['performWithFeedback', 'extendSelectionForward'], + command: 'performWithFeedback(extendSelectionForward)', }, }, '[up]': { class: 'action hide-shift', label: '↑', - command: ['performWithFeedback', 'moveUp'], + command: 'performWithFeedback(moveUp)', shift: { label: '↟', - command: ['performWithFeedback', 'extendSelectionUpward'], + command: 'performWithFeedback(extendSelectionUpward)', }, }, '[down]': { class: 'action hide-shift', label: '↓', - command: ['performWithFeedback', 'moveDown'], + command: 'performWithFeedback(moveDown)', shift: { label: '↡', - command: ['performWithFeedback', 'extendSelectionDownward'], + command: 'performWithFeedback(extendSelectionDownward)', }, }, '[return]': { class: 'action hide-shift', - command: ['performWithFeedback', 'commit'], - shift: { command: ['performWithFeedback', 'addRowAfter'] }, + command: 'performWithFeedback(commit)', + shift: { command: 'performWithFeedback(addRowAfter)' }, width: 1.5, label: '', }, '[action]': { class: 'action hide-shift', - command: ['performWithFeedback', 'commit'], + command: 'performWithFeedback(commit)', shift: { label: '', - command: ['performWithFeedback', 'addRowAfter'], + command: 'performWithFeedback(addRowAfter)', }, width: 1.5, label: '', @@ -782,14 +782,14 @@ const KEYCAP_SHORTCUTS: Record> = { }, '[.]': { variants: '.', - command: ['performWithFeedback', 'insertDecimalSeparator'], + command: 'performWithFeedback(insertDecimalSeparator)', shift: ',', class: 'big-op hide-shift', label: '.', }, '[,]': { variants: ',', - command: ['performWithFeedback', 'insertDecimalSeparator'], + command: 'performWithFeedback(insertDecimalSeparator)', shift: '.', class: 'big-op hide-shift', label: ',', @@ -849,7 +849,7 @@ const KEYCAP_SHORTCUTS: Record> = { '[backspace]': { class: 'action bottom right hide-shift', width: 1.5, - command: ['performWithFeedback', 'deleteBackward'], + command: 'performWithFeedback(deleteBackward)', label: '', shift: { class: 'action warning', diff --git a/src/virtual-keyboard/virtual-keyboard.ts b/src/virtual-keyboard/virtual-keyboard.ts index 2d0822ebd..f9b8a0ee6 100644 --- a/src/virtual-keyboard/virtual-keyboard.ts +++ b/src/virtual-keyboard/virtual-keyboard.ts @@ -854,8 +854,9 @@ export class VirtualKeyboard implements VirtualKeyboardInterface, EventTarget { if (isArray(command)) { selector = command[0]; if (selector === 'performWithFeedback') { - command = command.slice(1) as [SelectorPrivate, ...any[]]; - target = getCommandTarget(command); + target = getCommandTarget( + command.slice(1) as [SelectorPrivate, ...any[]] + ); } args = command.slice(1); } else selector = command;