Skip to content

Commit

Permalink
fix(ui-tars): resolve page down and page up event error
Browse files Browse the repository at this point in the history
  • Loading branch information
zhoushaw committed Feb 10, 2025
1 parent a5f92b8 commit 38d55fb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
15 changes: 6 additions & 9 deletions packages/shared/src/us-keyboard-layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -712,15 +712,12 @@ const keyMap: Record<string, KeyInput> = {
};

export function transformHotkeyInput(keyInput: string): string[] {
// page down
if (keyMap[keyInput.toLowerCase()]) {
return [getKeyDefinition(keyMap[keyInput.toLowerCase()])];
}

return keyInput.split(' ').map((key) => {
let newKey = key;
if (keyMap[key.toLowerCase()]) {
newKey = keyMap[key.toLowerCase()];
}
const keyDefinition = getKeyDefinition(newKey);
if (keyDefinition) {
return keyDefinition;
}
return newKey;
return getKeyDefinition(keyMap[key.toLowerCase()] || key);
});
}
5 changes: 5 additions & 0 deletions packages/shared/tests/unit-test/keyboard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,9 @@ describe('transformHotkeyInput', () => {
it('should handle empty input', () => {
expect(transformHotkeyInput('')).toEqual(['']);
});

it('should handle page down', () => {
expect(transformHotkeyInput('page down')).toEqual(['PageDown']);
expect(transformHotkeyInput('page up')).toEqual(['PageUp']);
});
});

0 comments on commit 38d55fb

Please sign in to comment.