mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 11:49:39 +08:00
Remove course pages, APIs and the course_study capability. Add anchored note threads and reviewed learning-block generation, queued and withdrawable chat messages, quote attachments, side chats, and the calendar/favorites/navigation updates. Keep preview's existing backend architecture. Wire the new features through its Python application and existing chat engine, retain legacy selected-text requests, persist mid-turn messages in replay, and restore note context when regenerating. Leave stored user data intact. Validate frontend contracts, dependency boundaries, types, 1290 node tests, 840 rendered tests, lint, localization and the production build. Exercise session/notes/API regressions, 53 chat-engine tests and 20 Python/native integration tests with isolated runtime data.
50 lines
1.8 KiB
TypeScript
50 lines
1.8 KiB
TypeScript
/**
|
|
* Keyboard shortcuts: one description used both to match a key event and to
|
|
* print the keys in a tooltip, so the two can never disagree.
|
|
*/
|
|
|
|
export interface Shortcut {
|
|
/** A letter or digit, e.g. "K" or "1". */
|
|
key: string
|
|
/** ⌘ on macOS, Ctrl elsewhere. */
|
|
mod?: boolean
|
|
alt?: boolean
|
|
shift?: boolean
|
|
}
|
|
|
|
export function isMacPlatform(): boolean {
|
|
if (typeof navigator === 'undefined') return false
|
|
return /Mac|iPhone|iPad|iPod/.test(navigator.platform || navigator.userAgent)
|
|
}
|
|
|
|
/** The keys as printed: ⌘ ⌥ ⇧ K on macOS, Ctrl Alt Shift K elsewhere. */
|
|
export function shortcutKeys(shortcut: Shortcut, mac = isMacPlatform()): string[] {
|
|
const keys: string[] = []
|
|
if (shortcut.mod) keys.push(mac ? '⌘' : 'Ctrl')
|
|
if (shortcut.alt) keys.push(mac ? '⌥' : 'Alt')
|
|
if (shortcut.shift) keys.push(mac ? '⇧' : 'Shift')
|
|
keys.push(shortcut.key.toUpperCase())
|
|
return keys
|
|
}
|
|
|
|
function physicalCode(key: string): string {
|
|
return /^\d$/.test(key) ? `Digit${key}` : `Key${key.toUpperCase()}`
|
|
}
|
|
|
|
export function matchesShortcut(event: KeyboardEvent, shortcut: Shortcut, mac = isMacPlatform()): boolean {
|
|
const mod = mac ? event.metaKey : event.ctrlKey
|
|
if (Boolean(shortcut.mod) !== mod) return false
|
|
if (Boolean(shortcut.alt) !== event.altKey || Boolean(shortcut.shift) !== event.shiftKey) return false
|
|
// ⌥ rewrites event.key on macOS (⌥1 is "¡"), so compare the physical key.
|
|
return event.code === physicalCode(shortcut.key)
|
|
}
|
|
|
|
/** The modern shell's shortcuts, in one place. */
|
|
export const SHORTCUTS = {
|
|
search: { key: 'K', mod: true },
|
|
newChat: { key: 'O', mod: true, shift: true },
|
|
/** A side chat with Dito about the open conversation, in the viewer. */
|
|
sideChat: { key: 'S', mod: true, alt: true },
|
|
category: (index: number): Shortcut => ({ key: String(index + 1), mod: true, alt: true }),
|
|
} as const
|