@@ -34,13 +34,15 @@ import { SimpleSettingRenderer } from '../../markdown/browser/markdownSettingRen
34
34
import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js' ;
35
35
import { Schemas } from '../../../../base/common/network.js' ;
36
36
import { ICodeEditorService } from '../../../../editor/browser/services/codeEditorService.js' ;
37
+ import { dirname } from '../../../../base/common/resources.js' ;
38
+ import { asWebviewUri } from '../../webview/common/webview.js' ;
37
39
38
40
export class ReleaseNotesManager {
39
41
private readonly _simpleSettingRenderer : SimpleSettingRenderer ;
40
42
private readonly _releaseNotesCache = new Map < string , Promise < string > > ( ) ;
41
43
42
44
private _currentReleaseNotes : WebviewInput | undefined = undefined ;
43
- private _lastText : string | undefined ;
45
+ private _lastMeta : { text : string ; base : URI } | undefined ;
44
46
private readonly disposables = new DisposableStore ( ) ;
45
47
46
48
public constructor (
@@ -68,19 +70,30 @@ export class ReleaseNotesManager {
68
70
}
69
71
70
72
private async updateHtml ( ) {
71
- if ( ! this . _currentReleaseNotes || ! this . _lastText ) {
73
+ if ( ! this . _currentReleaseNotes || ! this . _lastMeta ) {
72
74
return ;
73
75
}
74
- const html = await this . renderBody ( this . _lastText ) ;
76
+ const html = await this . renderBody ( this . _lastMeta ) ;
75
77
if ( this . _currentReleaseNotes ) {
76
78
this . _currentReleaseNotes . webview . setHtml ( html ) ;
77
79
}
78
80
}
79
81
82
+ private async getBase ( useCurrentFile : boolean ) {
83
+ if ( useCurrentFile ) {
84
+ const currentFileUri = this . _codeEditorService . getActiveCodeEditor ( ) ?. getModel ( ) ?. uri ;
85
+ if ( currentFileUri ) {
86
+ return dirname ( currentFileUri ) ;
87
+ }
88
+ }
89
+ return URI . parse ( 'https://code.visualstudio.com/raw' ) ;
90
+ }
91
+
80
92
public async show ( version : string , useCurrentFile : boolean ) : Promise < boolean > {
81
93
const releaseNoteText = await this . loadReleaseNotes ( version , useCurrentFile ) ;
82
- this . _lastText = releaseNoteText ;
83
- const html = await this . renderBody ( releaseNoteText ) ;
94
+ const base = await this . getBase ( useCurrentFile ) ;
95
+ this . _lastMeta = { text : releaseNoteText , base } ;
96
+ const html = await this . renderBody ( this . _lastMeta ) ;
84
97
const title = nls . localize ( 'releaseNotesInputName' , "Release Notes: {0}" , version ) ;
85
98
86
99
const activeEditorPane = this . _editorService . activeEditorPane ;
@@ -95,10 +108,10 @@ export class ReleaseNotesManager {
95
108
options : {
96
109
tryRestoreScrollPosition : true ,
97
110
enableFindWidget : true ,
98
- disableServiceWorker : true ,
111
+ disableServiceWorker : useCurrentFile ? false : true ,
99
112
} ,
100
113
contentOptions : {
101
- localResourceRoots : [ ] ,
114
+ localResourceRoots : useCurrentFile ? [ base ] : [ ] ,
102
115
allowScripts : true
103
116
} ,
104
117
extension : undefined
@@ -247,10 +260,10 @@ export class ReleaseNotesManager {
247
260
return uri ;
248
261
}
249
262
250
- private async renderBody ( text : string ) {
263
+ private async renderBody ( fileContent : { text : string ; base : URI } ) {
251
264
const nonce = generateUuid ( ) ;
252
265
253
- const content = await renderMarkdownDocument ( text , this . _extensionService , this . _languageService , {
266
+ const content = await renderMarkdownDocument ( fileContent . text , this . _extensionService , this . _languageService , {
254
267
shouldSanitize : false ,
255
268
markedExtensions : [ {
256
269
renderer : {
@@ -266,7 +279,7 @@ export class ReleaseNotesManager {
266
279
return `<!DOCTYPE html>
267
280
<html>
268
281
<head>
269
- <base href="https://code.visualstudio.com/raw/" >
282
+ <base href="${ asWebviewUri ( fileContent . base ) . toString ( true ) } /" >
270
283
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
271
284
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src https: data:; media-src https:; style-src 'nonce-${ nonce } ' https://code.visualstudio.com; script-src 'nonce-${ nonce } ';">
272
285
<style nonce="${ nonce } ">
0 commit comments