Skip to content

Commit

Permalink
fix: additional logic of optional open item on checkbox (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
liuycy authored Mar 1, 2024
1 parent 25c4de8 commit 9d2d96c
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
3 changes: 1 addition & 2 deletions src/pages/home/folder/GridItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ export const GridItem = (props: { obj: StoreObj; index: number }) => {
on:click={(e: MouseEvent) => {
if (!checkboxOpen()) return
e.preventDefault()
if (e.altKey) {
// click with alt/option key
if (isShouldOpenItem()) {
to(pushHref(props.obj.name))
return
}
Expand Down
4 changes: 2 additions & 2 deletions src/pages/home/folder/ImageItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ export const ImageItem = (props: { obj: StoreObj; index: number }) => {
cursor={
!checkboxOpen() || isShouldOpenItem() ? "pointer" : "default"
}
on:click={(e: MouseEvent) => {
if (!checkboxOpen() || e.altKey) {
on:click={() => {
if (!checkboxOpen() || isShouldOpenItem()) {
bus.emit("gallery", props.obj.name)
return
}
Expand Down
1 change: 0 additions & 1 deletion src/pages/home/folder/ListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ export const ListItem = (props: { obj: StoreObj; index: number }) => {
if (!checkboxOpen()) return
e.preventDefault()
if (isShouldOpenItem()) {
// click with alt/option key
to(pushHref(props.obj.name))
return
}
Expand Down
7 changes: 6 additions & 1 deletion src/pages/home/folder/helper.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { createKeyHold } from "@solid-primitives/keyboard"
import { createEffect, createSignal } from "solid-js"
import { isMac } from "~/utils/compatibility"
import { local } from "~/store"

export function useOpenItemWithCheckbox() {
const [shouldOpen, setShouldOpen] = createSignal(
local["open_item_on_checkbox"] === "direct",
)
const isAltKeyPressed = createKeyHold("Alt")
const isMetaKeyPressed = createKeyHold("Meta")
const isControlKeyPressed = createKeyHold("Control")
createEffect(() => {
switch (local["open_item_on_checkbox"]) {
Expand All @@ -15,7 +17,10 @@ export function useOpenItemWithCheckbox() {
break
}
case "with_ctrl": {
setShouldOpen(isControlKeyPressed())
// FYI why should use metaKey on a Mac
// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/ctrlKey
// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/metaKey
setShouldOpen(isMac ? isMetaKeyPressed() : isControlKeyPressed())
break
}
case "with_alt": {
Expand Down
2 changes: 1 addition & 1 deletion src/store/local_settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const initialLocalSettings = [
key: "open_item_on_checkbox",
default: "direct",
type: "select",
options: ["direct", "with_alt"], // "with_ctrl",? mac's control key can't be prevented
options: ["direct", "with_alt", "with_ctrl"],
},
]
export type LocalSetting = (typeof initialLocalSettings)[number]
Expand Down

0 comments on commit 9d2d96c

Please sign in to comment.