Repository navigation
forward hotkeys - #186
forward hotkeys#186Kitenite wants to merge 1 commit into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughThis PR refactors terminal tab management and lifecycle handling in the desktop renderer's Terminal component. It centralizes exit handling, adds keyboard shortcuts (Meta+K and Meta+W), coordinates tab closure with the tabs store, implements a deferred event-processing mechanism, and ensures the PTY remains available for reattachment after detach. Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx (2)
202-224: Cross-platform keyboard shortcut support may be missing.The shortcut handler only responds to the
metaKey(Cmd on macOS). On Windows and Linux, users typically expectCtrl+KandCtrl+Wfor these operations. If this is a cross-platform Electron app, consider supporting both modifier keys.const shortcutHandler = (event: KeyboardEvent) => { - const isMetaOnly = event.metaKey && !event.ctrlKey && !event.altKey; - if (!isMetaOnly || event.shiftKey) return true; + const isMeta = event.metaKey && !event.ctrlKey && !event.altKey; + const isCtrl = event.ctrlKey && !event.metaKey && !event.altKey; + const isShortcutModifier = isMeta || isCtrl; + if (!isShortcutModifier || event.shiftKey) return true; if (event.code === "KeyK") {
85-103: MemoizehandleStreamDatawithuseCallbackto prevent unnecessary subscription rebinds and potential stale closure issues.The
handleStreamDatafunction references thesubscriptionEnabledstate directly and is passed as theonDatacallback totrpc.useSubscription. Without memoization, the function is recreated on every render, which can cause:
- Unnecessary resubscribe/unsubscribe cycles in the tRPC subscription
- Potential stale closure if the subscription handler is not rebound on each render
Wrap it with
useCallbackand includesubscriptionEnabledas a dependency (already done forhandleTerminalExit):const handleStreamData = useCallback((event: TerminalStreamEvent) => { if (!xtermRef.current) { pendingEventsRef.current.push(event); return; } if (!subscriptionEnabled) { pendingEventsRef.current.push(event); return; } if (event.type === "data") { xtermRef.current.write(event.data); } else if (event.type === "exit") { handleTerminalExit(event.exitCode); } }, [subscriptionEnabled, handleTerminalExit]);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx(7 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
apps/desktop/**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (apps/desktop/AGENTS.md)
For Electron interprocess communication, ALWAYS use tRPC as defined in
src/lib/trpc
Files:
apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx
apps/desktop/**/*.{ts,tsx}
📄 CodeRabbit inference engine (apps/desktop/AGENTS.md)
apps/desktop/**/*.{ts,tsx}: Please use alias as defined intsconfig.jsonwhen possible
Prefer zustand for state management if it makes sense. Do not use effect unless absolutely necessary
Files:
apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx
**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
**/*.{ts,tsx}: Avoid usinganytype - use explicit types instead for type safety
Use camelCase for variable and function names following existing codebase patterns
Keep diffs minimal with targeted edits only - avoid unnecessary changes when making modifications
Follow existing patterns and match the codebase style when writing new code
Files:
apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx
**/components/**/*.tsx
📄 CodeRabbit inference engine (AGENTS.md)
**/components/**/*.tsx: Create one folder per component with structure:ComponentName/ComponentName.tsx+index.tsfor barrel export
Co-locate tests next to the component file they test (e.g.,ComponentName.test.tsx)
Co-locate dependencies (utils, hooks, constants, config, stories) next to the file using them
Use nestedcomponents/subdirectory within a parent component only if a sub-component is used 2+ times within that parent; otherwise keep it in the parent'scomponents/folder
One component per file - avoid multi-component files
Files:
apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx
apps/desktop/src/renderer/**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Never import Node.js modules (fs, path, os, net, etc.) in renderer process code - browser environment only
Files:
apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx
apps/desktop/src/renderer/**/*.tsx
📄 CodeRabbit inference engine (AGENTS.md)
Call IPC methods using
window.ipcRenderer.invoke()with object parameters - TypeScript will infer the exact response type automatically
Files:
apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx
🧠 Learnings (1)
📚 Learning: 2025-11-28T01:03:47.951Z
Learnt from: CR
Repo: superset-sh/superset PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-28T01:03:47.951Z
Learning: Applies to **/*.{ts,tsx} : Keep diffs minimal with targeted edits only - avoid unnecessary changes when making modifications
Applied to files:
apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx
🧬 Code graph analysis (1)
apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx (3)
apps/desktop/src/renderer/stores/tabs/hooks.ts (1)
useSetActiveTab(10-11)apps/desktop/src/renderer/stores/theme/store.ts (1)
useTerminalTheme(184-185)apps/desktop/src/renderer/stores/tabs/store.ts (1)
useTabsStore(36-167)
🔇 Additional comments (10)
apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx (10)
4-11: LGTM!Imports are well-organized, use alias paths as defined in tsconfig.json, and correctly add the necessary hooks for the new tab lifecycle management functionality. No Node.js modules are imported in this renderer process code.
29-37: LGTM!Good use of refs for mutable closure state (
closeTabRef,hasClosedRef) to prevent stale closure issues and double-close race conditions. The zustand selectors forremoveTabandremoveChildTabFromGroupfollow the recommended pattern.
59-61: LGTM!Correctly resets the close guard when the
tabIdchanges, ensuring the new tab instance can be closed. This handles the edge case of prop changes without component remount.
63-74: LGTM!The close tab logic correctly distinguishes between grouped child tabs and standalone tabs. The
hasClosedRefguard prevents multiple close attempts, which is important sincecloseTabRef.current()is called from multiple code paths (exit handler, keyboard shortcut).
76-83: LGTM!Good centralization of exit handling logic. The underscore prefix on
_exitCodecorrectly indicates an intentionally unused parameter. Note thatsetSubscriptionEnabledis a stable React setState function, so it doesn't strictly need to be in the dependency array, but including it is harmless and explicit.
252-259: VerifyterminalThemeis intentionally excluded from dependencies.The
terminalThemeis used increateTerminalInstance(line 117) but is not in the dependency array. A separate effect handles theme updates (lines 262-269), which suggests this is intentional to avoid recreating the terminal on theme changes.However, if
terminalThemeisundefinedinitially and loads asynchronously, the terminal may start with the default theme even if a custom theme is available shortly after. The separate theme effect should correct this, so this is likely acceptable behavior.
242-251: LGTM!Cleanup sequence is correct: dispose input listener, cleanup event handlers, detach PTY (keeping it alive for reattachment), disable subscription, then dispose xterm. The comment at line 246 clarifies the intentional PTY preservation.
261-269: LGTM!Clean separation of theme update logic from terminal initialization. Using the options setter is the correct approach for xterm.js v5 to trigger a repaint without recreating the instance.
274-281: LGTM!Simple and clean JSX structure with proper background color fallback handling.
214-219: Review comment is incorrect—no PTY lifecycle error exists.When
Meta+WtriggerscloseTabRef.current(), the actual flow is:
removeTab→killTerminalForTab(id)callstrpcClient.terminal.kill({ tabId, deleteHistory: true })(async, fire-and-forget)- Component unmounts
- Cleanup runs:
detachRef.current({ tabId })Both
killanddetachinapps/desktop/src/main/lib/terminal-manager.tsgracefully handle race conditions:
kill()(lines 230-252): If session not found, logs warning and returns safelydetach()(lines 254-264): If session not found, logs warning and returns safely; otherwise updateslastActiveThere is no error condition.
detachdoes not require the PTY to exist—it checks for the session and warns if missing. The operations are idempotent and safe regardless of execution order.
Summary by CodeRabbit
Release Notes
New Features
Improvements
✏️ Tip: You can customize this high-level summary in your review settings.