From f9a6e775f3571eb2f9792a9621cc98380a9ec122 Mon Sep 17 00:00:00 2001 From: Xylight <80978739+Xyphyn@users.noreply.github.com> Date: Fri, 15 Aug 2025 06:31:23 -0700 Subject: [PATCH] Revert "feat: add customizable keyboard navigation" --- .../components/lemmy/comment/Comment.svelte | 9 +-- .../lemmy/comment/CommentActions.svelte | 5 +- .../comment/CommentListVirtualizer.svelte | 5 +- .../lemmy/comment/CommentVote.svelte | 33 ++------ src/lib/components/lemmy/post/Post.svelte | 24 ++---- src/lib/components/lemmy/post/PostVote.svelte | 2 +- .../lemmy/post/actions/PostActions.svelte | 5 +- .../lemmy/post/feed/VirtualFeed.svelte | 6 +- src/lib/components/ui/Expandable.svelte | 12 +-- src/lib/components/ui/ExpandableImage.svelte | 12 +-- .../components/ui/layout/CommonList.svelte | 22 +---- .../ui/navbar/commands/CommandsWrapper.svelte | 5 +- src/lib/i18n/en.json | 5 -- src/lib/settings.svelte.ts | 43 +--------- src/lib/ui/keybinds.svelte.ts | 80 ------------------- src/routes/settings/+page.svelte | 71 ---------------- src/routes/settings/Setting.svelte | 6 +- 17 files changed, 39 insertions(+), 306 deletions(-) delete mode 100644 src/lib/ui/keybinds.svelte.ts diff --git a/src/lib/components/lemmy/comment/Comment.svelte b/src/lib/components/lemmy/comment/Comment.svelte index aac0550b..fb56e2bd 100644 --- a/src/lib/components/lemmy/comment/Comment.svelte +++ b/src/lib/components/lemmy/comment/Comment.svelte @@ -25,7 +25,6 @@ import CommentForm from './CommentForm.svelte' import type { CommentNodeI } from './comments.svelte' import { page } from '$app/state' - import { keybindComment } from '$lib/ui/keybinds.svelte' import { settings } from '$lib/settings.svelte' interface Props { @@ -119,15 +118,9 @@ {/if} - -
  • - keybindComment(e, node.comment_view.comment.id, () => (open = !open))} - tabindex="0" > {#if meta} {/snippet} diff --git a/src/lib/components/lemmy/comment/CommentListVirtualizer.svelte b/src/lib/components/lemmy/comment/CommentListVirtualizer.svelte index 6fd0d78b..676951dd 100644 --- a/src/lib/components/lemmy/comment/CommentListVirtualizer.svelte +++ b/src/lib/components/lemmy/comment/CommentListVirtualizer.svelte @@ -4,7 +4,6 @@ import type { CommentNodeI } from './comments.svelte' import Comments from './CommentTree.svelte' import { onMount } from 'svelte' - import { keybindFeed } from '$lib/ui/keybinds.svelte' interface Props { nodes: CommentNodeI[] @@ -14,8 +13,8 @@ onMount(() => { if (scrollTo) { + const element = document?.getElementById(scrollTo) setTimeout(() => { - const element = document?.getElementById(scrollTo) element?.scrollIntoView({ behavior: 'smooth', block: 'start' }) }, 100) } @@ -39,8 +38,6 @@ let initialOffset = $derived(offsetEl?.offsetTop) - -
    {#if offsetEl} { + const castVote = async (newVote: number) => { if (!profile.current?.jwt) { toast({ content: $t('toast.loginVoteGate'), type: 'warning' }) return } - switch (vote ?? 0) { - case 0: - // nothing was removed - if (newVote == 1) upvotes++ - else downvotes++ - break - case 1: - // removed an upvote - upvotes-- - if (newVote == -1) downvotes++ - break - case -1: - // removed a downvote - downvotes-- - if (newVote == 1) upvotes++ - break - } - vote = newVote - client() - .likeComment({ - comment_id: commentId, - score: vote, - }) - .then(res => ({ upvotes, downvotes } = res.comment_view.counts)) + const res = await getClient().likeComment({ + comment_id: commentId, + score: vote, + }) + ;({ upvotes, downvotes } = res.comment_view.counts) } let voteRatio = $derived( diff --git a/src/lib/components/lemmy/post/Post.svelte b/src/lib/components/lemmy/post/Post.svelte index edb0ace3..4d7c249c 100644 --- a/src/lib/components/lemmy/post/Post.svelte +++ b/src/lib/components/lemmy/post/Post.svelte @@ -14,7 +14,6 @@ import type { PostView } from 'lemmy-js-client' import type { ClassValue } from 'svelte/elements' import PostBody from './PostBody.svelte' - import { keybindPost } from '$lib/ui/keybinds.svelte' function getTagRule(tags: Tag[]): 'blur-sm' | 'hide' | undefined { const tagContent = tags.map(t => t.content.toLowerCase()) @@ -29,9 +28,9 @@ return rule } - function onclick(e: Event) { + function onClick(e: Event) { const event = e as Event - const parent = document.getElementById(`item-${post.post.id.toString()}`) + const parent = document.getElementById(post.post.id.toString()) if (event.target == parent) { goto(postLink(post.post)) @@ -80,8 +79,6 @@ admin: post.creator_is_admin, moderator: post.creator_is_moderator, }) - - let voteComponent = $state<{ castVote: (vote: number) => void }>()
    history.back()} + onkeydown={e => { + if (e.key == 'Escape') history.back() + }} + use:focusTrap > -
      +
        {#if items} - {#each items as item, index} + {#each items as item, index (item)}
      • :global(li) { - background-color: var(--color-slate-25); - - &:hover { - background-color: var(--color-slate-50); - } - } - - :global(.dark) ul.secondary > :global(li) { - background-color: var(--color-zinc-925); - - &:hover { - background-color: var(--color-zinc-800); - } - } - @keyframes pop-in { from { transform: translateY(16px); diff --git a/src/lib/components/ui/navbar/commands/CommandsWrapper.svelte b/src/lib/components/ui/navbar/commands/CommandsWrapper.svelte index 19eda457..934fc090 100644 --- a/src/lib/components/ui/navbar/commands/CommandsWrapper.svelte +++ b/src/lib/components/ui/navbar/commands/CommandsWrapper.svelte @@ -1,6 +1,5 @@ @@ -76,7 +74,7 @@ {/if}
    {/if} -
    +
    {#if icon}