Repository navigation
feat(desktop): add Copy Path:Line to Monaco editor context menu - #415
Conversation
Add right-click context menu action and keyboard shortcut (Cmd+Shift+C) to copy file path with line number in format `path:line` or `path:startLine-endLine` for multi-line selections. Useful for feeding file references to agents. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
Warning Rate limit exceeded@Kitenite has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 17 minutes and 13 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (2)
WalkthroughThe pull request adds a Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
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 |
- Move registerCopyPathLineAction and registerSaveCommand to editor-actions.ts - Simplify editor ref type annotation - Clean up DiffViewer component 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/ChangesContent/components/DiffViewer/DiffViewer.tsx (1)
61-78: LGTM with optional refactor suggestion.The
handleMountcallback correctly:
- Retrieves both editors to add the copy-path-line action
- Stores the modified editor reference for save operations
- Updates dependencies to include
filePathThe implementation properly enables the copy-path-line feature on both editor panels.
The
modifiedEditorcheck on line 70 is defensive but redundant sincemodifiedEditoris assigned on line 65 fromeditor.getModifiedEditor()and will always be defined. You can simplify to:🔎 Optional refactor to remove redundant check:
- if (editable && modifiedEditor) { + if (editable) { modifiedEditor.addCommand( monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS, handleSave, ); }
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/ChangesContent/ChangesContent.tsx(1 hunks)apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/ChangesContent/components/DiffViewer/DiffViewer.tsx(2 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/ChangesContent/ChangesContent.tsxapps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/ChangesContent/components/DiffViewer/DiffViewer.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/ChangesContent/ChangesContent.tsxapps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/ChangesContent/components/DiffViewer/DiffViewer.tsx
**/*.{ts,tsx,js,jsx,json}
📄 CodeRabbit inference engine (AGENTS.md)
Use Biome for code formatting and linting, running at root level for speed
Files:
apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/ChangesContent/ChangesContent.tsxapps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/ChangesContent/components/DiffViewer/DiffViewer.tsx
**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Avoid
anytype and prioritize type safety in TypeScript code
Files:
apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/ChangesContent/ChangesContent.tsxapps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/ChangesContent/components/DiffViewer/DiffViewer.tsx
**/components/**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
**/components/**/*.{ts,tsx}: Structure project folders as one folder per component with PascalCase naming (ComponentName/ComponentName.tsx + index.ts barrel export)
Co-locate component dependencies (utils, hooks, constants, config, tests, stories) next to the file using them
Use one component per file (no multi-component files)
Files:
apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/ChangesContent/ChangesContent.tsxapps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/ChangesContent/components/DiffViewer/DiffViewer.tsx
apps/desktop/src/renderer/**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Call IPC methods from renderer process using window.ipcRenderer.invoke with type-safe object parameters
Files:
apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/ChangesContent/ChangesContent.tsxapps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/ChangesContent/components/DiffViewer/DiffViewer.tsx
🧬 Code graph analysis (1)
apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/ChangesContent/components/DiffViewer/DiffViewer.tsx (1)
apps/desktop/src/shared/changes-types.ts (2)
FileContents(69-73)DiffViewMode(58-58)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Build
🔇 Additional comments (4)
apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/ChangesContent/ChangesContent.tsx (1)
153-153: LGTM!The addition of the
filePathprop toDiffVieweris clean and correctly passesselectedFile.path. Null safety is already handled upstream (lines 106-113), so this change is safe.apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/ChangesContent/components/DiffViewer/DiffViewer.tsx (3)
2-2: LGTM!The type-only import of Monaco types is correct and follows TypeScript best practices for importing types without including runtime code.
39-39: LGTM!The
filePath: stringprop addition is correctly typed and appropriately required for the copy-path-line functionality.
47-47: LGTM!The
filePathprop is correctly destructured and used in the component logic.
| function addCopyPathLineAction( | ||
| editor: Monaco.editor.IStandaloneCodeEditor, | ||
| filePath: string, | ||
| ) { | ||
| editor.addAction({ | ||
| id: COPY_PATH_LINE_ACTION_ID, | ||
| label: "Copy Path:Line", | ||
| keybindings: [ | ||
| monaco.KeyMod.CtrlCmd | monaco.KeyMod.Shift | monaco.KeyCode.KeyC, | ||
| ], | ||
| contextMenuGroupId: "9_cutcopypaste", | ||
| contextMenuOrder: 4, | ||
| run: (ed) => { | ||
| const selection = ed.getSelection(); | ||
| if (selection) { | ||
| const startLine = selection.startLineNumber; | ||
| const endLine = selection.endLineNumber; | ||
| const pathWithLine = | ||
| startLine === endLine | ||
| ? `${filePath}:${startLine}` | ||
| : `${filePath}:${startLine}-${endLine}`; | ||
| navigator.clipboard.writeText(pathWithLine); | ||
| } | ||
| }, | ||
| }); | ||
| } |
There was a problem hiding this comment.
Add error handling for clipboard write operation.
The navigator.clipboard.writeText() call on line 30 is an asynchronous operation that can fail (e.g., due to permission issues or browser security restrictions). Currently, failures would be silent, providing no feedback to the user.
🔎 Apply this diff to add error handling:
run: (ed) => {
const selection = ed.getSelection();
if (selection) {
const startLine = selection.startLineNumber;
const endLine = selection.endLineNumber;
const pathWithLine =
startLine === endLine
? `${filePath}:${startLine}`
: `${filePath}:${startLine}-${endLine}`;
- navigator.clipboard.writeText(pathWithLine);
+ navigator.clipboard.writeText(pathWithLine).catch((err) => {
+ console.error("Failed to copy path to clipboard:", err);
+ });
}
},📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| function addCopyPathLineAction( | |
| editor: Monaco.editor.IStandaloneCodeEditor, | |
| filePath: string, | |
| ) { | |
| editor.addAction({ | |
| id: COPY_PATH_LINE_ACTION_ID, | |
| label: "Copy Path:Line", | |
| keybindings: [ | |
| monaco.KeyMod.CtrlCmd | monaco.KeyMod.Shift | monaco.KeyCode.KeyC, | |
| ], | |
| contextMenuGroupId: "9_cutcopypaste", | |
| contextMenuOrder: 4, | |
| run: (ed) => { | |
| const selection = ed.getSelection(); | |
| if (selection) { | |
| const startLine = selection.startLineNumber; | |
| const endLine = selection.endLineNumber; | |
| const pathWithLine = | |
| startLine === endLine | |
| ? `${filePath}:${startLine}` | |
| : `${filePath}:${startLine}-${endLine}`; | |
| navigator.clipboard.writeText(pathWithLine); | |
| } | |
| }, | |
| }); | |
| } | |
| function addCopyPathLineAction( | |
| editor: Monaco.editor.IStandaloneCodeEditor, | |
| filePath: string, | |
| ) { | |
| editor.addAction({ | |
| id: COPY_PATH_LINE_ACTION_ID, | |
| label: "Copy Path:Line", | |
| keybindings: [ | |
| monaco.KeyMod.CtrlCmd | monaco.KeyMod.Shift | monaco.KeyCode.KeyC, | |
| ], | |
| contextMenuGroupId: "9_cutcopypaste", | |
| contextMenuOrder: 4, | |
| run: (ed) => { | |
| const selection = ed.getSelection(); | |
| if (selection) { | |
| const startLine = selection.startLineNumber; | |
| const endLine = selection.endLineNumber; | |
| const pathWithLine = | |
| startLine === endLine | |
| ? `${filePath}:${startLine}` | |
| : `${filePath}:${startLine}-${endLine}`; | |
| navigator.clipboard.writeText(pathWithLine).catch((err) => { | |
| console.error("Failed to copy path to clipboard:", err); | |
| }); | |
| } | |
| }, | |
| }); | |
| } |
🤖 Prompt for AI Agents
In
apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/ChangesContent/components/DiffViewer/DiffViewer.tsx
around lines 9 to 34, the call to navigator.clipboard.writeText(...) is
unhandled and can fail; wrap the writeText call in an async/await or promise
.then/.catch to handle rejections, log the error (e.g., console.error or
existing logger) and provide user feedback (e.g., show a toast/notification or
fallback to copying via a hidden textarea) when the clipboard write fails;
ensure run becomes async if using await and that errors are caught and handled
to avoid silent failures.
Summary
Cmd+Shift+C(Mac) /Ctrl+Shift+C(Windows/Linux)path:lineorpath:startLine-endLinefor multi-line selectionsTest plan
filepath:lineNumberfilepath:startLine-endLine🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes
New Features
Refactor
✏️ Tip: You can customize this high-level summary in your review settings.