Fix Share GitHub Permalink as Markdown to use filename instead of cursor text
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` :bug: 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)
- Fixes microsoft/vscode-pull-request-github#4663
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.