mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-09-30 12:39:42 +02:00
- Session Manager (COD-121/192): align _loadSessionManagerList() with the merged #139 endpoint — map UnifiedSessionItem fields (lastActivityAt epoch-ms → lastModified, optional sizeBytes/firstPrompt/name) to the history-record shape _buildHistoryItem renders; surface non-2xx / error-envelope responses as a visible message instead of a silent "No sessions found"; route clicks by liveness (live row → selectSession, history row → resumeHistorySession by conversation UUID) via a new onActivate option so a live session is never duplicate-resumed - Ctrl+K double-dispatch: gate the palette chord in attachCustomKeyEventHandler (return false on keydown) so xterm never writes 0x0b kill-line into the PTY while the palette opens; gate is registry-aware so a rebound/disabled palette shortcut restores normal terminal Ctrl+K - Shortcut registry (COD-157) finished per maintainer decision: document keydown now dispatches through getShortcutRegistry() + matchesShortcutEvent() (legacy SHORTCUTS table removed), honoring per-shortcut disable and rebinds incl. the palette chord; overrides persist via saveAppSettingsToStorage() (correct device key + cache coherence, was orphaned 'codeman:settings'); Shortcuts tab renders on open via switchSettingsTab hook; capture uses a persistent listener that ignores bare modifier keydowns (combos now capturable) and requires a Ctrl/Cmd/Alt chord; settings rows use delegated listeners instead of inline onclick (JS-string injection sink) and overrides can no longer clobber id/label/action; added the missing row + overlay CSS - matchesShortcutEvent: reject undeclared extra modifiers (Ctrl+Shift+K no longer hijacked from Firefox devtools) while keeping Ctrl/Cmd interchangeable; match physical code OR produced key for layout parity - Registry/dispatch gaps: added restore-terminal-size entry, documented Ctrl+Shift+R again in the help modal (test flipped to assert presence), Ctrl+?/Alt+? now really open the registry-driven shortcut overlay, and Escape closes it - Palette new-session pick routes through selectQuickStartCase() so the searchable combobox, dir display, and lastUsedCase stay in sync - Removed fork cherry-pick debris: dead _onSessionListMaybeChanged(), orphaned .session-row-menu CSS, nonexistent closeMobileHeaderUtilities calls - Tests: functional vm-harness coverage for the unified-list field mapping + error state + liveness routing, palette chord shift/disable/ rebind handling, override persistence round-trip, capture flow, tab render hook, and source guards for the PTY gate + registry dispatch Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
62 lines
3.3 KiB
TypeScript
62 lines
3.3 KiB
TypeScript
import { readFileSync } from 'node:fs';
|
|
import { describe, expect, it } from 'vitest';
|
|
|
|
const appSource = readFileSync('src/web/public/app.js', 'utf8');
|
|
const terminalUiSource = readFileSync('src/web/public/terminal-ui.js', 'utf8');
|
|
const helpHtml = readFileSync('src/web/public/index.html', 'utf8');
|
|
const readme = readFileSync('README.md', 'utf8');
|
|
|
|
describe('keyboard shortcuts', () => {
|
|
it('uses physical Option+number keys so macOS special characters do not break tab switching', () => {
|
|
expect(appSource).toContain('e.code ||');
|
|
expect(appSource).toContain('Digit([1-9])');
|
|
expect(appSource).toContain('parseInt(digitMatch[1], 10) - 1');
|
|
});
|
|
|
|
it('provides Option+bracket shortcuts for previous and next session', () => {
|
|
expect(appSource).toContain("e.code === 'BracketLeft'");
|
|
expect(appSource).toContain("e.code === 'BracketRight'");
|
|
expect(appSource).toContain('this.prevSession()');
|
|
expect(appSource).toContain('this.nextSession()');
|
|
});
|
|
|
|
it('suppresses xterm PTY injection for the same physical Alt nav codes (no ESC leak)', () => {
|
|
// terminal-ui.js must gate its xterm pass-through on the SAME physical e.code set the
|
|
// app.js handler consumes; otherwise Alt+[ / Alt+] (and Option+digit on remapped macOS
|
|
// layouts) switch tabs AND inject ESC<char> into the focused terminal. Keep in sync.
|
|
expect(terminalUiSource).toContain('/^(Digit[1-9]|BracketLeft|BracketRight|KeyK)$/.test(ev.code');
|
|
});
|
|
|
|
it('documents the Alt/Option shortcuts in help and README', () => {
|
|
expect(helpHtml).toContain('<kbd>Alt/Option</kbd>+<kbd>[</kbd>');
|
|
expect(helpHtml).toContain('<kbd>Alt/Option</kbd>+<kbd>]</kbd>');
|
|
expect(helpHtml).toContain('<kbd>Alt/Option</kbd>+<kbd>1-9</kbd>');
|
|
expect(readme).toContain('`Alt/Option+[` / `Alt/Option+]`');
|
|
expect(readme).toContain('`Alt/Option+1`-`Alt/Option+9`');
|
|
});
|
|
|
|
it('documents the Command-K open-session palette in help and README', () => {
|
|
expect(appSource).toContain('this.openCommandPalette()');
|
|
expect(helpHtml).toContain('<kbd>Ctrl/Cmd/Option</kbd>+<kbd>K</kbd>');
|
|
expect(readme).toMatch(/\| `Ctrl\/Cmd\/Option\+K`\s+\| Find open session or start a new one\s+\|/);
|
|
});
|
|
|
|
it('gates the palette chord in the xterm custom key handler (no 0x0b kill-line into the PTY)', () => {
|
|
// The document-level capture handler opens the palette, but preventDefault()
|
|
// does NOT stop xterm from evaluating Ctrl+K into 0x0b and writing it to the
|
|
// live PTY — terminal-ui.js must return false for the palette chord.
|
|
expect(terminalUiSource).toMatch(/ev\.type === 'keydown' && this\.shouldOpenCommandPaletteFromShortcut\?\.\(ev\)/);
|
|
});
|
|
|
|
it('dispatches document shortcuts through the shortcut registry (rebind/disable aware)', () => {
|
|
// The legacy hardcoded SHORTCUTS table must stay gone — dispatch goes through
|
|
// getShortcutRegistry() + matchesShortcutEvent() so overrides and per-shortcut
|
|
// disables (App Settings → Shortcuts) actually take effect.
|
|
expect(appSource).not.toContain('const SHORTCUTS = [');
|
|
expect(appSource).toContain('const SHORTCUT_ACTIONS = {');
|
|
expect(appSource).toContain('for (const shortcut of this.getShortcutRegistry())');
|
|
expect(appSource).toContain('if (this.matchesShortcutEvent(e, shortcut))');
|
|
expect(appSource).toContain('if (shortcut.disabled || !shortcut.action) continue;');
|
|
});
|
|
});
|