feat: add toggleable hotkey hints to sidebar buttons and refac ShortcutsModal
- Add src/lib/shortcuts.ts as the single source of truth for every shortcut - Create HotkeyHint.svelte to show OS-aware key combos (⌘ on Mac, Ctrl elsewhere) - Make sidebar “New Chat” and “Search” buttons display their shortcuts on hover - Add user setting to toggle these sidebar hints - Refactor ShortcutsModal into categorized (Global, Chat, Message, Input), data-driven sections - Introduce ShortcutItem.svelte to render each row, dividers, and multi-line text - Fix “Focus text area” action and include “Close modal” shortcut - Wire everything through +layout.svelte and the shortcuts registry
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
<script lang="ts">
|
||||
import { getContext } from 'svelte';
|
||||
import Tooltip from '../common/Tooltip.svelte';
|
||||
import type { Shortcut } from '$lib/shortcuts';
|
||||
|
||||
export let shortcut: Shortcut;
|
||||
export let isMac: boolean;
|
||||
|
||||
const i18n = getContext('i18n');
|
||||
|
||||
function formatKey(key: string): string {
|
||||
const lowerKey = key.toLowerCase();
|
||||
|
||||
if (lowerKey === 'mod') return isMac ? '⌘' : 'Ctrl/⌘';
|
||||
if (lowerKey === 'shift') return isMac ? '⇧' : 'Shift';
|
||||
if (lowerKey === 'backspace') return '⌫/Delete';
|
||||
if (lowerKey === 'escape') return 'Esc';
|
||||
if (lowerKey === 'enter') return 'Enter';
|
||||
if (lowerKey === 'tab') return 'Tab';
|
||||
if (lowerKey === 'arrowup') return '↑';
|
||||
if (lowerKey === 'arrowdown') return '↓';
|
||||
|
||||
// For keys like 'KeyK', 'KeyO', etc., we just want the last character.
|
||||
if (lowerKey.startsWith('key')) return key.slice(-1);
|
||||
// For keys like 'Digit2', 'Digit3', etc.
|
||||
if (lowerKey.startsWith('digit')) return key.slice(-1);
|
||||
// For other special keys
|
||||
if (lowerKey === 'quote') return "'";
|
||||
if (lowerKey === 'period') return '.';
|
||||
if (lowerKey === 'slash') return '/';
|
||||
if (lowerKey === 'semicolon') return ';';
|
||||
|
||||
return key.toUpperCase();
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="w-full flex justify-between items-center">
|
||||
<div class="text-sm whitespace-pre-line">
|
||||
{#if shortcut.tooltip}
|
||||
<Tooltip content={$i18n.t(shortcut.tooltip)}>
|
||||
<span class="whitespace-nowrap">
|
||||
{$i18n.t(shortcut.name)}<span class="text-xs"> *</span>
|
||||
</span>
|
||||
</Tooltip>
|
||||
{:else}
|
||||
{$i18n.t(shortcut.name)}
|
||||
{/if}
|
||||
</div>
|
||||
<div class="flex-shrink-0 flex items-center self-center space-x-1 text-xs">
|
||||
{#each shortcut.keys as key}
|
||||
<div
|
||||
class="h-fit py-1 px-2 flex items-center justify-center rounded-sm border border-black/10 capitalize text-gray-600 dark:border-white/10 dark:text-gray-300"
|
||||
>
|
||||
{formatKey(key)}
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
Reference in New Issue
Block a user