Skip to content

feat(desktop): add Copy Path:Line to Monaco editor context menu - #415

Merged
Kitenite merged 2 commits into
mainfrom
feat/copy-path-line-monaco
Dec 18, 2025
Merged

Kitenite merged 2 commits into
mainfrom
feat/copy-path-line-monaco

Conversation

@Kitenite

@Kitenite Kitenite commented Dec 18, 2025 •

Copy link
Copy Markdown
Member

Summary

  • Add "Copy Path:Line" action to Monaco diff editor's right-click context menu
  • Add keyboard shortcut Cmd+Shift+C (Mac) / Ctrl+Shift+C (Windows/Linux)
  • Copies file path with line number in format path:line or path:startLine-endLine for multi-line selections
  • Works on both original and modified editor panels

Test plan

  • Open a file in the diff viewer
  • Right-click to see "Copy Path:Line" in context menu with keyboard shortcut shown
  • Click cursor on a line, use context menu or hotkey, verify clipboard contains filepath:lineNumber
  • Select multiple lines, use context menu or hotkey, verify clipboard contains filepath:startLine-endLine

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • New Features

    • Added ability to copy file paths directly from diff viewer lines for both original and modified files
  • Refactor

    • Enhanced stability of save command operations in the diff viewer

✏️ Tip: You can customize this high-level summary in your review settings.

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>
@coderabbitai

coderabbitai Bot commented Dec 18, 2025 •

Copy link
Copy Markdown
Contributor

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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.

📥 Commits

Reviewing files that changed from the base of the PR and between c1731da and 5f36d97.

📒 Files selected for processing (2)
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/ChangesContent/components/DiffViewer/DiffViewer.tsx (1 hunks)
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/ChangesContent/components/DiffViewer/editor-actions.ts (1 hunks)

Walkthrough

The pull request adds a filePath prop to the DiffViewer component, enabling it to receive and use the currently selected file's path. ChangesContent passes this prop, and DiffViewer uses it to register copy-path-line actions on Monaco editors and updates effect dependencies accordingly.

Changes

Cohort / File(s) Summary
Prop Threading
apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/ChangesContent/ChangesContent.tsx
Passes new filePath prop to DiffViewer component
DiffViewer Enhancement
apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/ChangesContent/components/DiffViewer/DiffViewer.tsx
Adds filePath: string to DiffViewerProps interface; destructures and uses prop to register copy-path-line actions on original and modified Monaco editors; updates effect dependencies to include filePath

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Public API change: Verify filePath prop signature is correctly applied across component tree and that callers provide the required string
  • Action registration: Confirm copy-path-line actions are properly bound to both editors and use the correct file path reference
  • Effect dependencies: Review updated dependency arrays to ensure filePath is included where needed and no stale closures occur

Possibly related PRs

Poem

🐰 A path now travels through the code,
From parent down the component road,
Copy actions spring to life anew,
Monaco editors know what's true!
✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main feature being added: a Copy Path:Line action to Monaco editor context menu.
Description check ✅ Passed The description provides a clear summary of changes, test plan with checkboxes, and keyboard shortcuts. It covers the main aspects required by the template structure.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

- 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>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 handleMount callback correctly:

  • Retrieves both editors to add the copy-path-line action
  • Stores the modified editor reference for save operations
  • Updates dependencies to include filePath

The implementation properly enables the copy-path-line feature on both editor panels.

The modifiedEditor check on line 70 is defensive but redundant since modifiedEditor is assigned on line 65 from editor.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

📥 Commits

Reviewing files that changed from the base of the PR and between 910a281 and c1731da.

📒 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.tsx
  • apps/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 in tsconfig.json when 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.tsx
  • apps/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.tsx
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/ChangesContent/components/DiffViewer/DiffViewer.tsx
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Avoid any type and prioritize type safety in TypeScript code

Files:

  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/ChangesContent/ChangesContent.tsx
  • apps/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.tsx
  • apps/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.tsx
  • apps/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 filePath prop to DiffViewer is clean and correctly passes selectedFile.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: string prop addition is correctly typed and appropriately required for the copy-path-line functionality.


47-47: LGTM!

The filePath prop is correctly destructured and used in the component logic.

Comment on lines +9 to +34
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);
}
},
});
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

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.

Suggested change
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.

@Kitenite
Kitenite merged commit c114eac into main Dec 18, 2025
5 checks passed
@Kitenite
Kitenite deleted the feat/copy-path-line-monaco branch December 18, 2025 22:26
@github-actions

Copy link
Copy Markdown
Contributor

🧹 Preview Cleanup Complete

The following preview resources have been cleaned up:

Service Status
Neon Database (Neon) ⚠️

Thank you for your contribution! 🎉


Preview resources have been processed for cleanup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant