@@ -17,7 +17,7 @@ import { registerEventListeners } from '@/listeners';
1717import { PageType } from './router/types' ;
1818
1919export async function activate ( context : vscode . ExtensionContext ) {
20- const browserUrl = ( await await vscode . commands . executeCommand (
20+ const browserUrl = ( await vscode . commands . executeCommand (
2121 'github1s.vscode.get-browser-url'
2222 ) ) as string ;
2323
@@ -40,17 +40,37 @@ export async function activate(context: vscode.ExtensionContext) {
4040
4141 // sponsors in Status Bar
4242 showSponsors ( ) ;
43- await showGitpod ( ) ;
43+ showGitpod ( ) ;
4444
45- // open corresponding editor if there is a filePath specified in browser url
46- const { filePath, pageType } = await router . getState ( ) ;
47- if ( filePath && [ PageType . TREE , PageType . BLOB ] . includes ( pageType ) ) {
45+ // initialize the VSCode's state
46+ initialVSCodeState ( ) ;
47+ }
48+
49+ // initialize the VSCode's state according to the router url
50+ const initialVSCodeState = async ( ) => {
51+ const routerState = await router . getState ( ) ;
52+ const { filePath, pageType } = routerState ;
53+ const scheme = GitHub1sFileSystemProvider . scheme ;
54+
55+ if ( filePath && pageType === PageType . TREE ) {
4856 vscode . commands . executeCommand (
49- pageType === PageType . TREE ? 'revealInExplorer' : 'vscode.open' ,
50- vscode . Uri . parse ( '' ) . with ( {
51- scheme : GitHub1sFileSystemProvider . scheme ,
52- path : filePath ,
53- } )
57+ 'revealInExplorer' ,
58+ vscode . Uri . parse ( '' ) . with ( { scheme, path : filePath } )
59+ ) ;
60+ } else if ( filePath && pageType === PageType . BLOB ) {
61+ const { startLineNumber, endLineNumber } = routerState ;
62+ const start = new vscode . Position ( startLineNumber - 1 , 0 ) ;
63+ const end = new vscode . Position ( endLineNumber - 1 , 999999 ) ;
64+ const documentShowOptions : vscode . TextDocumentShowOptions = startLineNumber
65+ ? { selection : new vscode . Range ( start , end ) }
66+ : { } ;
67+
68+ // TODO: the selection of the opening file may be cleared
69+ // when editor try to restore previous state in the same file
70+ vscode . commands . executeCommand (
71+ 'vscode.open' ,
72+ vscode . Uri . parse ( '' ) . with ( { scheme, path : filePath } ) ,
73+ documentShowOptions
5474 ) ;
5575 } else if ( pageType === PageType . PULL_LIST ) {
5676 vscode . commands . executeCommand ( 'github1s.views.pull-request-list.focus' ) ;
@@ -59,4 +79,4 @@ export async function activate(context: vscode.ExtensionContext) {
5979 } else if ( [ PageType . PULL , PageType . COMMIT ] . includes ( pageType ) ) {
6080 vscode . commands . executeCommand ( 'workbench.scm.focus' ) ;
6181 }
62- }
82+ } ;
0 commit comments