Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #969 adds copy relative path to context menu
- Loading branch information
Showing
5 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { env, TextEditor, Uri } from 'vscode'; | ||
import { Commands } from '../constants'; | ||
import type { Container } from '../container'; | ||
import { command } from '../system/command'; | ||
import { ActiveEditorCommand, getCommandUri } from './base'; | ||
|
||
@command() | ||
export class CopyRelativePathToClipboardCommand extends ActiveEditorCommand { | ||
constructor(private readonly container: Container) { | ||
super(Commands.CopyRelativePathToClipboard); | ||
} | ||
|
||
async execute(editor?: TextEditor, uri?: Uri) { | ||
uri = getCommandUri(uri, editor); | ||
let relativePath = ''; | ||
if (uri != null) { | ||
const repoPath = this.container.git.getBestRepository(editor)?.uri; | ||
if (repoPath != null) { | ||
relativePath = this.container.git.getRelativePath(uri, repoPath); | ||
} | ||
} | ||
|
||
void (await env.clipboard.writeText(relativePath)); | ||
return undefined; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters