diff --git a/extensions/github1s/package.json b/extensions/github1s/package.json index a592b1ef8..2a589bc57 100644 --- a/extensions/github1s/package.json +++ b/extensions/github1s/package.json @@ -19,6 +19,7 @@ "onCommand:github1s.switch-to-commit", "onCommand:github1s.diff-view-open-left-file", "onCommand:github1s.diff-view-open-right-file", + "onCommand:github1s.open-on-github", "onView:github1s" ], "browser": "./dist/extension", @@ -198,6 +199,11 @@ "light": "assets/icons/light/close-blame.svg" }, "enablement": "!isInDiffEditor && resourceScheme =~ /^github1s$/" + }, + { + "command": "github1s.open-on-github", + "title": "Open on GitHub", + "category": "GitHub1s" } ], "colors": [ diff --git a/extensions/github1s/src/commands/global.ts b/extensions/github1s/src/commands/global.ts new file mode 100644 index 000000000..9b12ed8a4 --- /dev/null +++ b/extensions/github1s/src/commands/global.ts @@ -0,0 +1,19 @@ +/** + * @file GitHub1s Ref Related Commands + * @author netcon + */ + +import * as vscode from 'vscode'; +import router from '@/router'; + +export const commandOpenOnGitHub = async () => { + const location = router.history.location; + const githubPath = + location.pathname === '/' + ? '/conwnet/github1s' + : `${location.pathname}${location.search}${location.hash}`; + const GITHUB_ORIGIN = 'https://github.com'; + const gitHubUri = vscode.Uri.parse(GITHUB_ORIGIN + githubPath); + + return vscode.commands.executeCommand('vscode.open', gitHubUri); +}; diff --git a/extensions/github1s/src/commands/index.ts b/extensions/github1s/src/commands/index.ts index d8e1522a2..871e6c8f2 100644 --- a/extensions/github1s/src/commands/index.ts +++ b/extensions/github1s/src/commands/index.ts @@ -5,7 +5,6 @@ import * as vscode from 'vscode'; import { getExtensionContext } from '@/helpers/context'; -import { pullRequestTreeDataProvider, commitTreeDataProvider } from '@/views'; import { commandValidateToken, commandUpdateToken, @@ -40,6 +39,7 @@ import { commandOpenEditorGutterBlame, commandCloseEditorGutterBlame, } from './blame'; +import { commandOpenOnGitHub } from './global'; const commands: { id: string; callback: (...args: any[]) => any }[] = [ // validate GitHub OAuth Token @@ -98,6 +98,9 @@ const commands: { id: string; callback: (...args: any[]) => any }[] = [ { id: 'github1s.open-editor-gutter-blame', callback: commandOpenEditorGutterBlame }, // prettier-ignore // close the gutter blame of a editor { id: 'github1s.close-editor-gutter-blame', callback: commandCloseEditorGutterBlame }, // prettier-ignore + + // open current page on GitHub + { id: 'github1s.open-on-github', callback: commandOpenOnGitHub }, ]; export const registerGitHub1sCommands = () => {