diff --git a/apps/studio-host/src/command/shortcut-map.test.ts b/apps/studio-host/src/command/shortcut-map.test.ts index 6b3c0ce..2d28294 100644 --- a/apps/studio-host/src/command/shortcut-map.test.ts +++ b/apps/studio-host/src/command/shortcut-map.test.ts @@ -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' }); diff --git a/apps/studio-host/src/command/shortcut-map.ts b/apps/studio-host/src/command/shortcut-map.ts index d49c22d..c7f78a8 100644 --- a/apps/studio-host/src/command/shortcut-map.ts +++ b/apps/studio-host/src/command/shortcut-map.ts @@ -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, shortcuts: [ShortcutDef, string][],