Skip to content

Commit

Permalink
fix: sort shortcut
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed Aug 13, 2024
1 parent ba23dcf commit 1f8e4a3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
16 changes: 9 additions & 7 deletions src/renderer/src/hooks/biz/useFeedActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,7 @@ export const useFeedActions = ({
type: "separator" as const,
disabled: isEntryList,
},
{
type: "text" as const,
label: "Copy Feed URL",
disabled: isEntryList,
shortcut: "Meta+C",
click: () => navigator.clipboard.writeText(feed.url),
},

{
type: "separator",
disabled: isEntryList,
Expand Down Expand Up @@ -135,9 +129,17 @@ export const useFeedActions = ({
type: "separator",
disabled: isEntryList,
},
{
type: "text" as const,
label: "Copy Feed URL",
disabled: isEntryList,
shortcut: "Meta+C",
click: () => navigator.clipboard.writeText(feed.url),
},
{
type: "text" as const,
label: "Copy Feed ID",
shortcut: "Meta+Shift+C",
disabled: isEntryList,
click: () => {
navigator.clipboard.writeText(feedId)
Expand Down
21 changes: 20 additions & 1 deletion src/renderer/src/lib/native-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,29 @@ export type NativeMenuItem =
}
| { type: "separator", disabled?: boolean }

function sortShortcutsString(shortcut: string) {
// always order by Shift, Ctrl, Alt, Meta
const arr = shortcut.split("+")
const order = ["Shift", "Ctrl", "Alt", "Meta"]
arr.sort((a, b) => order.indexOf(a) - order.indexOf(b))

return arr.join("+")
}
export const showNativeMenu = async (
items: Array<Nullable<NativeMenuItem | false>>,
e?: MouseEvent | React.MouseEvent,
) => {
const nextItems = items.filter(Boolean) as NativeMenuItem[]
const nextItems = (items.filter(Boolean) as NativeMenuItem[]).map((item) => {
if (item.type === "text") {
return {
...item,
shortcut: item.shortcut ?
sortShortcutsString(item.shortcut) :
undefined,
}
}
return item
}) as NativeMenuItem[]

const el = e && e.currentTarget

Expand Down Expand Up @@ -99,6 +117,7 @@ export const showNativeMenu = async (
enabled: item.enabled ?? (item.click !== undefined || !!item.submenu),
click: undefined,
submenu: item.submenu ? transformMenuItems(item.submenu) : undefined,
shortcut: item.shortcut?.replace("Meta", "CmdOrCtrl"),
}
}
return item
Expand Down

0 comments on commit 1f8e4a3

Please sign in to comment.