Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 9, 2025

When invoked from the file tab context menu, "Share GitHub Permalink as Markdown" was using text from the cursor position for the link text instead of the filename.

Changes:

  • Removed selection-based text extraction logic from GitHubPermalinkAsMarkdownShareProvider.getMarkdownLinkText()
  • Method now always returns the filename

Before:

private async getMarkdownLinkText(item: vscode.ShareableItem): Promise<string | undefined> {
  const fileName = pathLib.basename(item.resourceUri.path);
  
  if (item.selection) {
    const document = await vscode.workspace.openTextDocument(item.resourceUri);
    const selectedText = document.getText(editorSelection);
    if (selectedText) return selectedText;
    // ... more fallback logic
  }
  
  return fileName;
}

After:

private async getMarkdownLinkText(item: vscode.ShareableItem): Promise<string | undefined> {
  return pathLib.basename(item.resourceUri.path);
}

The ShareableItem includes cursor selection even when invoked from tab context, causing the wrong text to be used. Now generates [filename.ts](url) consistently.

Original prompt

This section details on the original issue you should resolve

<issue_title>Share permalink as markdown on tab should use filename for link text</issue_title>
<issue_description>Testing microsoft/vscode#177486

open a file and place your cursor somewhere in that file
right click the file tab and 'share github permalink as markdown`
🐛 the generated link will use the text at the cursor location, but seems like it should just be the filename
if the cursor isn't in that file, then the text seems to be picked up from its last location, possibly from another window</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits December 9, 2025 16:32
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix permalink generated text to use filename for markdown Fix Share GitHub Permalink as Markdown to use filename instead of cursor text Dec 9, 2025
Copilot AI requested a review from alexr00 December 9, 2025 16:39
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.

Share permalink as markdown on tab should use filename for link text

2 participants