mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-10-06 07:29:42 +02:00
fix: COD-157 refine shortcut palette labels
This commit is contained in:
committed by
Aamer Akhter
parent
e8f5ac94f3
commit
596899e19b
@@ -93,12 +93,24 @@ function loadPaletteHarness(overrides: Record<string, any> = {}) {
|
||||
status: 'idle',
|
||||
},
|
||||
],
|
||||
[
|
||||
'sess-gamma',
|
||||
{
|
||||
id: 'sess-gamma',
|
||||
workingDir: '/repo/flux-player',
|
||||
mode: 'codex',
|
||||
status: 'busy',
|
||||
},
|
||||
],
|
||||
]);
|
||||
app.sessionOrder = ['sess-beta', 'sess-alpha'];
|
||||
app.sessionOrder = ['sess-beta', 'sess-alpha', 'sess-gamma'];
|
||||
app.cases = [{ name: 'plex-previews' }, { name: 'flux-player' }, { name: 'api-tools' }];
|
||||
app.selectSession = vi.fn();
|
||||
app.run = vi.fn();
|
||||
app.closeMobileHeaderUtilities = vi.fn();
|
||||
app.getShortId = (id: string) => id.slice(0, 8);
|
||||
app.getSessionName = (session: any) =>
|
||||
session.name || session.workingDir?.split('/').pop() || app.getShortId(session.id);
|
||||
|
||||
return { app, elements, listeners };
|
||||
}
|
||||
@@ -185,6 +197,19 @@ describe('Command-K session palette', () => {
|
||||
expect(results[1]).toMatchObject({ type: 'new-session', title: 'New session' });
|
||||
});
|
||||
|
||||
it('uses the tab name instead of the short session id for unnamed sessions', () => {
|
||||
const { app } = loadPaletteHarness();
|
||||
|
||||
const results = app.buildCommandPaletteItems('flux-player');
|
||||
|
||||
expect(results[0]).toMatchObject({
|
||||
type: 'session',
|
||||
sessionId: 'sess-gamma',
|
||||
title: 'flux-player',
|
||||
});
|
||||
expect(results[0].title).not.toBe('sess-gam');
|
||||
});
|
||||
|
||||
it('uses the best matching case for the new-session action', async () => {
|
||||
const { app, elements } = loadPaletteHarness();
|
||||
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
const INDEX_HTML = readFileSync(join(process.cwd(), 'src/web/public/index.html'), 'utf-8');
|
||||
|
||||
function normalizedHtml(value: string): string {
|
||||
return value.replace(/\s+/g, ' ');
|
||||
}
|
||||
|
||||
function extractElementById(html: string, id: string): string {
|
||||
const idIndex = html.indexOf(`id="${id}"`);
|
||||
expect(idIndex, `expected #${id} to exist`).toBeGreaterThanOrEqual(0);
|
||||
|
||||
const start = html.lastIndexOf('<', idIndex);
|
||||
expect(start, `expected #${id} start tag`).toBeGreaterThanOrEqual(0);
|
||||
|
||||
const nextSection = html.indexOf('<!-- Monitor Panel', idIndex);
|
||||
expect(nextSection, `expected section marker after #${id}`).toBeGreaterThanOrEqual(0);
|
||||
|
||||
const end = nextSection;
|
||||
return html.slice(start, end);
|
||||
}
|
||||
|
||||
function escapeRegExp(value: string): string {
|
||||
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||
}
|
||||
|
||||
function expectShortcut(html: string, keys: string[], label: string): void {
|
||||
const keyPattern = keys.map((key) => `<kbd>${escapeRegExp(key)}</kbd>`).join('\\s*\\+\\s*');
|
||||
expect(html).toMatch(new RegExp(`${keyPattern}.*?${label}`, 'i'));
|
||||
}
|
||||
|
||||
describe('help modal shortcuts', () => {
|
||||
const helpModal = normalizedHtml(extractElementById(INDEX_HTML, 'helpModal'));
|
||||
|
||||
it('documents implemented global and tab shortcuts', () => {
|
||||
expectShortcut(helpModal, ['Ctrl', 'W'], 'Close Session');
|
||||
expectShortcut(helpModal, ['Ctrl', 'Tab'], 'Next Session');
|
||||
expectShortcut(helpModal, ['Alt/Option', '['], 'Previous / Next Session');
|
||||
expectShortcut(helpModal, ['Alt/Option', ']'], 'Previous / Next Session');
|
||||
expectShortcut(helpModal, ['Alt/Option', '1-9'], 'Switch to Tab N');
|
||||
expectShortcut(helpModal, ['Ctrl', '{'], 'Move Active Tab Left');
|
||||
expectShortcut(helpModal, ['Ctrl', '}'], 'Move Active Tab Right');
|
||||
expectShortcut(helpModal, ['Ctrl', '?'], 'Show Shortcuts');
|
||||
expect(helpModal).not.toMatch(/Ctrl<\/kbd>\s*\+\s*<kbd>\/<\/kbd>.*?Show Shortcuts/i);
|
||||
expectShortcut(helpModal, ['Ctrl', 'Shift', 'V'], 'Voice Input');
|
||||
expectShortcut(helpModal, ['Escape'], 'Close Panels');
|
||||
});
|
||||
|
||||
it('documents terminal input shortcuts without advertising stale run shortcuts', () => {
|
||||
expectShortcut(helpModal, ['Ctrl', 'L'], 'Clear Terminal');
|
||||
expectShortcut(helpModal, ['Ctrl', '+'], 'Increase Font');
|
||||
expectShortcut(helpModal, ['Ctrl', '-'], 'Decrease Font');
|
||||
expectShortcut(helpModal, ['Shift', 'Enter'], 'Insert Newline');
|
||||
expectShortcut(helpModal, ['Ctrl', 'Enter'], 'Insert Newline');
|
||||
|
||||
expect(helpModal).not.toMatch(/Ctrl<\/kbd>\s*\+\s*<kbd>K<\/kbd>/i);
|
||||
expect(helpModal).not.toMatch(/Ctrl<\/kbd>\s*\+\s*<kbd>Shift<\/kbd>\s*\+\s*<kbd>R<\/kbd>/i);
|
||||
expect(helpModal).not.toMatch(/Ctrl<\/kbd>\s*\+\s*<kbd>Enter<\/kbd>.*?(Run|Start)/i);
|
||||
});
|
||||
|
||||
it('does not advertise the removed Ctrl+Enter run binding in launch UI hints', () => {
|
||||
expect(INDEX_HTML).not.toContain('Or press <kbd>Ctrl</kbd>+<kbd>Enter</kbd> to start');
|
||||
expect(INDEX_HTML).not.toContain('title="Run (Ctrl+Enter)"');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,53 @@
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
const appSource = readFileSync('src/web/public/app.js', 'utf8');
|
||||
const settingsSource = readFileSync('src/web/public/settings-ui.js', 'utf8');
|
||||
const htmlSource = readFileSync('src/web/public/index.html', 'utf8');
|
||||
|
||||
describe('shortcut registry and overlay', () => {
|
||||
it('defines shortcut metadata that can be overridden from global settings', () => {
|
||||
expect(appSource).toContain('const DEFAULT_SHORTCUTS = [');
|
||||
expect(appSource).toContain('shortcutOverrides');
|
||||
expect(appSource).toContain('getShortcutRegistry()');
|
||||
expect(appSource).toContain('matchesShortcutEvent(e, shortcut)');
|
||||
});
|
||||
|
||||
it('renders a shortcut overlay modal from the registry', () => {
|
||||
expect(htmlSource).toContain('id="shortcutOverlayModal"');
|
||||
expect(htmlSource).toContain('id="shortcutOverlayList"');
|
||||
expect(appSource).toContain('showShortcutOverlay()');
|
||||
expect(appSource).toContain('renderShortcutOverlay()');
|
||||
expect(appSource).toContain('closeShortcutOverlay()');
|
||||
});
|
||||
|
||||
it('adds Ctrl/Option question-mark bindings for the overlay', () => {
|
||||
expect(appSource).toContain("id: 'show-shortcuts'");
|
||||
expect(appSource).toContain("modifiers: ['ctrl']");
|
||||
expect(appSource).toContain("modifiers: ['alt']");
|
||||
expect(appSource).toContain("key: '?'");
|
||||
expect(appSource).toContain("code: 'Slash'");
|
||||
expect(appSource).not.toContain("key: '/'");
|
||||
});
|
||||
|
||||
it('exposes shortcut overrides in a dedicated App Settings shortcuts tab', () => {
|
||||
expect(htmlSource).toContain('data-tab="settings-shortcuts"');
|
||||
expect(htmlSource).toContain('id="settings-shortcuts"');
|
||||
expect(htmlSource).toContain('id="appSettingsShortcutsList"');
|
||||
expect(htmlSource).not.toContain('id="appSettingsShortcutOverrides"');
|
||||
expect(htmlSource).not.toContain('Shortcut Overrides</span>');
|
||||
expect(settingsSource).toContain('renderShortcutSettingsList');
|
||||
expect(settingsSource).toContain('readShortcutOverridesFromSettings');
|
||||
expect(settingsSource).toContain('startShortcutCapture');
|
||||
expect(settingsSource).toContain('onShortcutCaptureKeydown');
|
||||
expect(settingsSource).toContain('settings.shortcutOverrides');
|
||||
});
|
||||
|
||||
it('renders shortcut rows with capture, typed input, reset, and disable controls', () => {
|
||||
expect(settingsSource).toContain('shortcut-setting-row');
|
||||
expect(settingsSource).toContain('shortcut-capture-btn');
|
||||
expect(settingsSource).toContain('shortcut-binding-input');
|
||||
expect(settingsSource).toContain('shortcut-reset-btn');
|
||||
expect(settingsSource).toContain('shortcut-enabled-checkbox');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user