Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions apps/studio-host/src/command/shortcut-map.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ describe('shortcut-map', () => {
)).toBe('edit:goto');
});

it('lets unmodified letters reach the document instead of the object properties shortcut', () => {
installNavigator({ platform: 'MacIntel', userAgent: 'Mac OS X' });

expect(matchShortcut(keyEvent({ key: 'p', code: 'KeyP' }), defaultShortcuts)).toBeNull();
expect(matchShortcut(keyEvent({ key: 'ㅔ', code: 'KeyP' }), defaultShortcuts)).toBeNull();
expect(matchShortcut(keyEvent({ key: 'p', metaKey: true }), defaultShortcuts)).toBe('file:print');
expect(matchShortcut(keyEvent({ key: 'f6' }), defaultShortcuts)).toBe('format:style-dialog');
});

it('does not run unmodified shortcuts while a non-primary system modifier is held', () => {
installNavigator({ platform: 'Win32', userAgent: 'Windows NT 10.0' });

Expand Down
11 changes: 10 additions & 1 deletion apps/studio-host/src/command/shortcut-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,18 @@ const hopShortcutKeys = new Set(hopShortcuts.map(([shortcut]) => shortcutKey(sho

export const defaultShortcuts: [ShortcutDef, string][] = [
...hopShortcuts,
...upstreamDefaultShortcuts.filter(([shortcut]) => !hopShortcutKeys.has(shortcutKey(shortcut))),
...upstreamDefaultShortcuts.filter(
([shortcut]) => !hopShortcutKeys.has(shortcutKey(shortcut)) && !isUnmodifiedCharacterShortcut(shortcut),
),
];

// rhwp 0.8.4의 일반 키 경로는 매칭된 단축키를 canExecute 결과와 무관하게 preventDefault 한다.
// 그래서 modifier 없는 'P'(개체 속성) 단축키가 본문 타이핑의 p/ㅔ를 삼킨다. upstream이 실행된
// 키만 삼키도록 바뀔 때까지 modifier 없는 단일 글자 단축키는 등록하지 않는다.
function isUnmodifiedCharacterShortcut(shortcut: ShortcutDef): boolean {
return !shortcut.ctrl && !shortcut.alt && !shortcut.shift && shortcut.key.length === 1;
}

export function matchShortcut(
event: Pick<KeyboardEvent, 'key' | 'code' | 'ctrlKey' | 'metaKey' | 'shiftKey' | 'altKey'>,
shortcuts: [ShortcutDef, string][],
Expand Down