Skip to content

Commit 89af5cb

Browse files
fix: only show TOC shortcut key when TOC is enabled
Hide the 't' keyboard shortcut from the shortcuts overlay when table of contents is not available (git mode, multi-file, or no headings). Also make pressing 't' a no-op in those cases instead of toggling a hidden element. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent b56baad commit 89af5cb

File tree

3 files changed

+15
-17
lines changed

3 files changed

+15
-17
lines changed

e2e/tests/keyboard.spec.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -413,24 +413,13 @@ test.describe('Keyboard UI Toggles', () => {
413413
await expect(waitingOverlay).toHaveClass(/active/);
414414
});
415415

416-
test('t toggles table of contents (hidden in git mode, but toggles)', async ({ page }) => {
417-
// In git mode, the tocToggle button is hidden (display: none), so pressing t clicks a hidden button.
418-
// The toc starts with toc-hidden. Pressing t clicks the toggle button.
419-
// Since the button is display:none in git mode, the click via keyboard shortcut
420-
// still fires the click handler. Let's verify toc state changes.
416+
test('t does nothing in git mode (TOC is disabled)', async ({ page }) => {
421417
const toc = page.locator('#toc');
422418

423419
// Initially has toc-hidden
424420
await expect(toc).toHaveClass(/toc-hidden/);
425421

426-
// Press t
427-
await page.keyboard.press('t');
428-
429-
// In git mode, the toggle button is hidden, but the 't' shortcut calls .click() on it,
430-
// which should still toggle the class
431-
await expect(toc).not.toHaveClass(/toc-hidden/);
432-
433-
// Press t again to close
422+
// Press t — should be a no-op since TOC is hidden in git mode
434423
await page.keyboard.press('t');
435424
await expect(toc).toHaveClass(/toc-hidden/);
436425
});

frontend/app.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3445,11 +3445,17 @@
34453445
const tocEl = document.getElementById('toc');
34463446
const listEl = tocEl.querySelector('.toc-list');
34473447
const toggleBtn = document.getElementById('tocToggle');
3448+
const tocShortcut = document.querySelector('.shortcut-toc-only');
34483449
listEl.innerHTML = '';
34493450

3451+
function hideToc() {
3452+
toggleBtn.style.display = 'none';
3453+
if (tocShortcut) tocShortcut.style.display = 'none';
3454+
}
3455+
34503456
// TOC only for single-file markdown reviews
34513457
if (session.mode === 'git' || files.length > 1) {
3452-
toggleBtn.style.display = 'none';
3458+
hideToc();
34533459
return;
34543460
}
34553461

@@ -3464,10 +3470,11 @@
34643470
}
34653471

34663472
if (allItems.length === 0) {
3467-
toggleBtn.style.display = 'none';
3473+
hideToc();
34683474
return;
34693475
}
34703476
toggleBtn.style.display = '';
3477+
if (tocShortcut) tocShortcut.style.display = '';
34713478

34723479
// Restore TOC open/closed state from cookie
34733480
if (getCookie('crit-toc') === 'open') {
@@ -3802,8 +3809,10 @@
38023809
break;
38033810
}
38043811
case 't': {
3812+
var tocBtn = document.getElementById('tocToggle');
3813+
if (tocBtn.style.display === 'none') return;
38053814
e.preventDefault();
3806-
document.getElementById('tocToggle').click();
3815+
tocBtn.click();
38073816
break;
38083817
}
38093818
case 'n': {

frontend/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ <h3>Keyboard Shortcuts</h3>
110110
<tr class="shortcut-filemode-only"><td><kbd>n</kbd></td><td>Next change</td></tr>
111111
<tr class="shortcut-filemode-only"><td><kbd>N</kbd></td><td>Previous change</td></tr>
112112
<tr><td><kbd>Shift</kbd>+<kbd>F</kbd></td><td>Finish review</td></tr>
113-
<tr><td><kbd>t</kbd></td><td>Toggle table of contents</td></tr>
113+
<tr class="shortcut-toc-only"><td><kbd>t</kbd></td><td>Toggle table of contents</td></tr>
114114
<tr><td><kbd>Esc</kbd></td><td>Cancel / clear focus</td></tr>
115115
<tr><td><kbd>Ctrl</kbd>+<kbd>Enter</kbd></td><td>Submit comment</td></tr>
116116
<tr><td><kbd>?</kbd></td><td>Toggle this help</td></tr>

0 commit comments

Comments
 (0)