@@ -169,6 +169,11 @@ interface IExtensionEditorTemplate {
169
169
header : HTMLElement ;
170
170
}
171
171
172
+ const enum WebviewIndex {
173
+ Readme ,
174
+ Changelog
175
+ }
176
+
172
177
export class ExtensionEditor extends EditorPane {
173
178
174
179
static readonly ID : string = 'workbench.editor.extension' ;
@@ -179,6 +184,12 @@ export class ExtensionEditor extends EditorPane {
179
184
private extensionChangelog : Cache < string > | null ;
180
185
private extensionManifest : Cache < IExtensionManifest | null > | null ;
181
186
187
+ // Some action bar items use a webview whose vertical scroll position we track in this map
188
+ private initialScrollProgress : Map < WebviewIndex , number > = new Map ( ) ;
189
+
190
+ // Spot when an ExtensionEditor instance gets reused for a different extension, in which case the vertical scroll positions must be zeroed
191
+ private currentIdentifier : string = '' ;
192
+
182
193
private layoutParticipants : ILayoutParticipant [ ] = [ ] ;
183
194
private readonly contentDisposables = this . _register ( new DisposableStore ( ) ) ;
184
195
private readonly transientDisposables = this . _register ( new DisposableStore ( ) ) ;
@@ -336,6 +347,11 @@ export class ExtensionEditor extends EditorPane {
336
347
this . editorLoadComplete = false ;
337
348
const extension = input . extension ;
338
349
350
+ if ( this . currentIdentifier !== extension . identifier . id ) {
351
+ this . initialScrollProgress . clear ( ) ;
352
+ this . currentIdentifier = extension . identifier . id ;
353
+ }
354
+
339
355
this . transientDisposables . clear ( ) ;
340
356
341
357
this . extensionReadme = new Cache ( ( ) => createCancelablePromise ( token => extension . getReadme ( token ) ) ) ;
@@ -563,7 +579,7 @@ export class ExtensionEditor extends EditorPane {
563
579
return Promise . resolve ( null ) ;
564
580
}
565
581
566
- private async openMarkdown ( cacheResult : CacheResult < string > , noContentCopy : string , template : IExtensionEditorTemplate , token : CancellationToken ) : Promise < IActiveElement | null > {
582
+ private async openMarkdown ( cacheResult : CacheResult < string > , noContentCopy : string , template : IExtensionEditorTemplate , webviewIndex : WebviewIndex , token : CancellationToken ) : Promise < IActiveElement > {
567
583
try {
568
584
const body = await this . renderMarkdown ( cacheResult , template ) ;
569
585
if ( token . isCancellationRequested ) {
@@ -572,15 +588,22 @@ export class ExtensionEditor extends EditorPane {
572
588
573
589
const webview = this . contentDisposables . add ( this . webviewService . createWebviewOverlay ( 'extensionEditor' , {
574
590
enableFindWidget : true ,
591
+ tryRestoreScrollPosition : true ,
575
592
} , { } , undefined ) ) ;
576
593
594
+ webview . initialScrollProgress = this . initialScrollProgress . get ( webviewIndex ) || 0 ;
595
+
577
596
webview . claim ( this , this . scopedContextKeyService ) ;
578
597
setParentFlowTo ( webview . container , template . content ) ;
579
598
webview . layoutWebviewOverElement ( template . content ) ;
580
599
581
600
webview . html = body ;
601
+ webview . claim ( this ) ;
582
602
583
603
this . contentDisposables . add ( webview . onDidFocus ( ( ) => this . fireOnDidFocus ( ) ) ) ;
604
+
605
+ this . contentDisposables . add ( webview . onDidScroll ( ( ) => this . initialScrollProgress . set ( webviewIndex , webview . initialScrollProgress ) ) ) ;
606
+
584
607
const removeLayoutParticipant = arrays . insert ( this . layoutParticipants , {
585
608
layout : ( ) => {
586
609
webview . layoutWebviewOverElement ( template . content ) ;
@@ -823,7 +846,7 @@ export class ExtensionEditor extends EditorPane {
823
846
if ( manifest && manifest . extensionPack && manifest . extensionPack . length ) {
824
847
return this . openExtensionPackReadme ( manifest , template , token ) ;
825
848
}
826
- return this . openMarkdown ( this . extensionReadme ! . get ( ) , localize ( 'noReadme' , "No README available." ) , template , token ) ;
849
+ return this . openMarkdown ( this . extensionReadme ! . get ( ) , localize ( 'noReadme' , "No README available." ) , template , WebviewIndex . Readme , token ) ;
827
850
}
828
851
829
852
private async openExtensionPackReadme ( manifest : IExtensionManifest , template : IExtensionEditorTemplate , token : CancellationToken ) : Promise < IActiveElement | null > {
@@ -854,15 +877,15 @@ export class ExtensionEditor extends EditorPane {
854
877
const readmeContent = append ( extensionPackReadme , $ ( 'div.readme-content' ) ) ;
855
878
856
879
await Promise . all ( [
857
- this . renderExtensionPack ( manifest , extensionPackContent , token ) ,
858
- this . openMarkdown ( this . extensionReadme ! . get ( ) , localize ( 'noReadme' , "No README available." ) , { ...template , ...{ content : readmeContent } } , token ) ,
880
+ this . renderExtensionPack ( manifest , extensionPackContent ) ,
881
+ this . openMarkdown ( this . extensionReadme ! . get ( ) , localize ( 'noReadme' , "No README available." ) , { ...template , ...{ content : readmeContent } } , WebviewIndex . Readme , token ) ,
859
882
] ) ;
860
883
861
884
return { focus : ( ) => extensionPackContent . focus ( ) } ;
862
885
}
863
886
864
- private openChangelog ( template : IExtensionEditorTemplate , token : CancellationToken ) : Promise < IActiveElement | null > {
865
- return this . openMarkdown ( this . extensionChangelog ! . get ( ) , localize ( 'noChangelog' , "No Changelog available." ) , template , token ) ;
887
+ private openChangelog ( template : IExtensionEditorTemplate , token : CancellationToken ) : Promise < IActiveElement > {
888
+ return this . openMarkdown ( this . extensionChangelog ! . get ( ) , localize ( 'noChangelog' , "No Changelog available." ) , template , WebviewIndex . Changelog , token ) ;
866
889
}
867
890
868
891
private openContributions ( template : IExtensionEditorTemplate , token : CancellationToken ) : Promise < IActiveElement | null > {
0 commit comments