File tree Expand file tree Collapse file tree 3 files changed +11
-8
lines changed
Expand file tree Collapse file tree 3 files changed +11
-8
lines changed Original file line number Diff line number Diff line change @@ -61,13 +61,10 @@ const initialVSCodeState = async () => {
6161 let documentShowOptions : vscode . TextDocumentShowOptions = { } ;
6262 if ( startLine || endLine ) {
6363 const startPosition = new vscode . Position ( ( startLine || endLine ) ! - 1 , 0 ) ;
64- const endPosition = new vscode . Position ( ( endLine || startLine ) ! - 1 , 999999 ) ;
64+ const endPosition = new vscode . Position ( ( endLine || startLine ) ! - 1 , 1 << 20 ) ;
6565 documentShowOptions = { selection : new vscode . Range ( startPosition , endPosition ) } ;
6666 }
67- // TODO: the selection of the opening file may be cleared
68- // when editor try to restore previous state in the same file
69- vscode . commands . executeCommand (
70- 'vscode.open' ,
67+ vscode . window . showTextDocument (
7168 vscode . Uri . parse ( '' ) . with ( { scheme, path : `/${ routerState . filePath } ` } ) ,
7269 documentShowOptions
7370 ) ;
Original file line number Diff line number Diff line change @@ -54,7 +54,7 @@ const handleRouterOnTextEditorSelectionChange = async (editor: vscode.TextEditor
5454 const routerParser = await router . resolveParser ( ) ;
5555
5656 // only add the line number anchor when pageType is PageType.Blob
57- if ( pageType !== PageType . Blob || ! editor . selection ) {
57+ if ( pageType !== PageType . Blob || ! editor ? .selection ) {
5858 return ;
5959 }
6060
@@ -63,11 +63,11 @@ const handleRouterOnTextEditorSelectionChange = async (editor: vscode.TextEditor
6363 repo ,
6464 ref ,
6565 activeFileUri . path . slice ( 1 ) ,
66- editor . selection . start . line + 1 ,
66+ ! editor . selection . isEmpty ? editor . selection . start . line + 1 : undefined ,
6767 editor . selection . end . line !== editor . selection . start . line ? editor . selection . end . line + 1 : undefined
6868 ) ;
6969
70- router . replace ( browserPath ) ;
70+ browserPath !== ( await router . getPath ( ) ) && router . replace ( browserPath ) ;
7171} ;
7272
7373// refresh file history view if active editor changed
Original file line number Diff line number Diff line change @@ -70,6 +70,12 @@ export class Router extends EventEmitter<RouterState> {
7070 return this . _history ! ;
7171 }
7272
73+ public async getPath ( ) {
74+ await this . _barrier . wait ( ) ;
75+ const { pathname, search, hash } = this . _history ! . location ;
76+ return `${ pathname } ${ search } ${ hash } ` ;
77+ }
78+
7379 // push the url with current history
7480 public async push ( path : string ) {
7581 await this . _barrier . wait ( ) ;
You can’t perform that action at this time.
0 commit comments