Skip to content

Commit fd51a23

Browse files
committed
feat!: enhance keyboard logic for vim users
- Simplified keyboard shortcuts for switching views and showing shortcuts. - Enhanced hotkey registration to include special key mappings. - Updated command hotkeys in various components for consistency. - Adjusted user guide to reflect new shortcut key for showing shortcuts. Signed-off-by: Innei <[email protected]>
1 parent 243cd37 commit fd51a23

File tree

6 files changed

+19
-10
lines changed

6 files changed

+19
-10
lines changed

apps/desktop/layer/renderer/src/constants/shortcuts.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ const shortcutConfigs = {
1919
},
2020
switchNextView: {
2121
name: tShortcuts("keys.subscriptions.switchNextView"),
22-
key: "Tab, ArrowRight",
22+
key: "Tab",
2323
},
2424
switchPreviousView: {
2525
name: tShortcuts("keys.subscriptions.switchPreviousView"),
26-
key: "Shift+Tab, ArrowLeft",
26+
key: "Shift+Tab",
2727
},
2828
nextSubscription: {
2929
name: tShortcuts("keys.subscriptions.nextSubscription"),
@@ -45,7 +45,7 @@ const shortcutConfigs = {
4545
},
4646
showShortcuts: {
4747
name: tShortcuts("keys.layout.showShortcuts"),
48-
key: "H",
48+
key: "?",
4949
},
5050
toggleWideMode: {
5151
name: tShortcuts("keys.layout.toggleWideMode"),

apps/desktop/layer/renderer/src/modules/command/hooks/use-register-hotkey.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ export interface RegisterHotkeyOptions<T extends FollowCommandId> {
1919

2020
const IGNORE_INPUT_ELEMENT = [HTMLInputElement, HTMLTextAreaElement]
2121

22+
const SPECIAL_KEYS_MAPPINGS = [["?", "Shift+Slash"]] as const
23+
2224
export const useCommandHotkey = <T extends FollowCommandId>({
2325
shortcut,
2426
commandId,
@@ -42,7 +44,16 @@ export const useCommandHotkey = <T extends FollowCommandId>({
4244

4345
// Create a handler for each shortcut
4446
shortcuts.forEach((key) => {
45-
keyMap[key] = (event) => {
47+
let nextKey = key
48+
49+
for (const [from, to] of SPECIAL_KEYS_MAPPINGS) {
50+
if (key === from) {
51+
nextKey = to
52+
break
53+
}
54+
}
55+
56+
keyMap[nextKey] = (event) => {
4657
const { target } = event
4758
if (
4859
!options?.forceInputElement &&

apps/desktop/layer/renderer/src/modules/entry-column/EntryColumnShortcutHandler.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ export const EntryColumnShortcutHandler: FC<{
4545

4646
useCommandHotkey({
4747
commandId: COMMAND_ID.layout.focusToEntryRender,
48-
shortcut: "Enter",
48+
shortcut: "Enter, L, ArrowRight",
4949
when,
5050
})
5151

5252
useCommandHotkey({
5353
commandId: COMMAND_ID.layout.focusToSubscription,
54-
shortcut: "Backspace, Escape",
54+
shortcut: "Backspace, Escape, H, ArrowLeft",
5555
when,
5656
})
5757

apps/desktop/layer/renderer/src/modules/new-user-guide/guide-modal-content.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ function Outtro() {
7070
<Trans
7171
i18nKey="new_user_guide.step.shortcuts.description2"
7272
components={{
73-
kbd: <Kbd>H</Kbd>,
73+
kbd: <Kbd>?</Kbd>,
7474
}}
7575
/>
7676
</p>

apps/desktop/layer/renderer/src/modules/timeline-column/FeedList.electron.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ const useRegisterCommand = () => {
319319
useCommandHotkey({
320320
commandId: COMMAND_ID.layout.focusToTimeline,
321321
when: isFocus,
322-
shortcut: "Enter",
322+
shortcut: "Enter, L, ArrowRight",
323323
})
324324

325325
useCommandBinding({

apps/desktop/layer/renderer/src/providers/global-hotkeys-provider.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ export const GlobalHotkeysProvider = () => {
1616

1717
useCommandBinding({
1818
commandId: COMMAND_ID.global.showShortcuts,
19-
when:
20-
activeScopes.includes(HotkeyScope.Home) && !activeScopes.includes(HotkeyScope.EntryRender),
2119
})
2220

2321
useEventListener("keydown", (e) => {

0 commit comments

Comments
 (0)