feat: add copy remote URL to line number context menu (#253)

* feat: add copy remote URL to line number context menu

Add 'Copy Remote URL' option to the line number gutter right-click menu,
allowing users to quickly copy a shareable link to a file and line on
GitHub, GitLab, Bitbucket, or other hosted git providers.

- Install hosted-git-info to parse remote URLs and generate browse URLs
- Add getRemoteFileUrl() to resolve file URLs using default branch
- Wire up IPC handler, preload bridge, and renderer UI
- Use ExternalLink icon to distinguish from path copy options

* refactor: use @types/hosted-git-info instead of custom type declarations

Replace the custom hosted-git-info.d.ts with the @types package from
DefinitelyTyped. Use a targeted cast for browseFile() which the @types
package doesn't include yet (stuck on v3 API).

* refactor: revert to local type declarations for hosted-git-info

The @types/hosted-git-info package is stuck on the v3 API and lacks
browseFile(). A local .d.ts is cleaner than casting around stale types.
This commit is contained in:
Matheus Nogueira
2026-04-01 20:02:05 -03:00
committed by GitHub
parent e8e7d2ea8f
commit 2ec433f6df
8 changed files with 143 additions and 2 deletions
@@ -1,7 +1,7 @@
import React, { useRef, useCallback, useEffect, useState } from 'react'
import Editor, { type OnMount } from '@monaco-editor/react'
import type { editor } from 'monaco-editor'
import { Copy } from 'lucide-react'
import { Copy, ExternalLink } from 'lucide-react'
import {
DropdownMenu,
DropdownMenuContent,
@@ -206,6 +206,23 @@ export default function MonacoEditor({
<Copy className="w-3.5 h-3.5 mr-1.5" />
Copy Rel. Path to Line
</DropdownMenuItem>
<DropdownMenuItem
onSelect={async () => {
// Derive worktree root from the absolute and relative paths
const worktreePath = filePath.slice(0, -(relativePath.length + 1))
const url = await window.api.git.remoteFileUrl({
worktreePath,
relativePath,
line: gutterMenuLine
})
if (url) {
window.api.ui.writeClipboardText(url)
}
}}
>
<ExternalLink className="w-3.5 h-3.5 mr-1.5" />
Copy Remote URL
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</>