Skip to content

Commit 9d2d96c

Browse files
authored
fix: additional logic of optional open item on checkbox (#154)
1 parent 25c4de8 commit 9d2d96c

File tree

5 files changed

+10
-7
lines changed

5 files changed

+10
-7
lines changed

src/pages/home/folder/GridItem.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ export const GridItem = (props: { obj: StoreObj; index: number }) => {
6262
on:click={(e: MouseEvent) => {
6363
if (!checkboxOpen()) return
6464
e.preventDefault()
65-
if (e.altKey) {
66-
// click with alt/option key
65+
if (isShouldOpenItem()) {
6766
to(pushHref(props.obj.name))
6867
return
6968
}

src/pages/home/folder/ImageItem.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ export const ImageItem = (props: { obj: StoreObj; index: number }) => {
8686
cursor={
8787
!checkboxOpen() || isShouldOpenItem() ? "pointer" : "default"
8888
}
89-
on:click={(e: MouseEvent) => {
90-
if (!checkboxOpen() || e.altKey) {
89+
on:click={() => {
90+
if (!checkboxOpen() || isShouldOpenItem()) {
9191
bus.emit("gallery", props.obj.name)
9292
return
9393
}

src/pages/home/folder/ListItem.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ export const ListItem = (props: { obj: StoreObj; index: number }) => {
6565
if (!checkboxOpen()) return
6666
e.preventDefault()
6767
if (isShouldOpenItem()) {
68-
// click with alt/option key
6968
to(pushHref(props.obj.name))
7069
return
7170
}

src/pages/home/folder/helper.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { createKeyHold } from "@solid-primitives/keyboard"
22
import { createEffect, createSignal } from "solid-js"
3+
import { isMac } from "~/utils/compatibility"
34
import { local } from "~/store"
45

56
export function useOpenItemWithCheckbox() {
67
const [shouldOpen, setShouldOpen] = createSignal(
78
local["open_item_on_checkbox"] === "direct",
89
)
910
const isAltKeyPressed = createKeyHold("Alt")
11+
const isMetaKeyPressed = createKeyHold("Meta")
1012
const isControlKeyPressed = createKeyHold("Control")
1113
createEffect(() => {
1214
switch (local["open_item_on_checkbox"]) {
@@ -15,7 +17,10 @@ export function useOpenItemWithCheckbox() {
1517
break
1618
}
1719
case "with_ctrl": {
18-
setShouldOpen(isControlKeyPressed())
20+
// FYI why should use metaKey on a Mac
21+
// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/ctrlKey
22+
// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/metaKey
23+
setShouldOpen(isMac ? isMetaKeyPressed() : isControlKeyPressed())
1924
break
2025
}
2126
case "with_alt": {

src/store/local_settings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export const initialLocalSettings = [
5656
key: "open_item_on_checkbox",
5757
default: "direct",
5858
type: "select",
59-
options: ["direct", "with_alt"], // "with_ctrl",? mac's control key can't be prevented
59+
options: ["direct", "with_alt", "with_ctrl"],
6060
},
6161
]
6262
export type LocalSetting = (typeof initialLocalSettings)[number]

0 commit comments

Comments
 (0)