Browse Source

Fixes timeline webview not loading properly

main
Eric Amodio 2 years ago
parent
commit
9101ed9747
3 changed files with 30 additions and 38 deletions
  1. +6
    -10
      src/webviews/rebase/rebaseEditor.ts
  2. +12
    -14
      src/webviews/webviewBase.ts
  3. +12
    -14
      src/webviews/webviewViewBase.ts

+ 6
- 10
src/webviews/rebase/rebaseEditor.ts View File

@ -503,21 +503,16 @@ export class RebaseEditorProvider implements CustomTextEditorProvider, Disposabl
const root = context.panel.webview.asWebviewUri(this.container.context.extensionUri).toString(); const root = context.panel.webview.asWebviewUri(this.container.context.extensionUri).toString();
const webRoot = context.panel.webview.asWebviewUri(webRootUri).toString(); const webRoot = context.panel.webview.asWebviewUri(webRootUri).toString();
const html = content
.replace(/#{(head|body|endOfBody|placement)}/i, (_substring, token) => {
const html = content.replace(
/#{(head|body|endOfBody|placement|cspSource|cspNonce|root|webroot)}/i,
(_substring, token) => {
switch (token) { switch (token) {
case 'endOfBody': case 'endOfBody':
return `<script type="text/javascript" nonce="#{cspNonce}">window.bootstrap = ${JSON.stringify(
return `<script type="text/javascript" nonce="${cspNonce}">window.bootstrap=${JSON.stringify(
bootstrap, bootstrap,
)};</script>`; )};</script>`;
case 'placement': case 'placement':
return 'editor'; return 'editor';
default:
return '';
}
})
.replace(/#{(cspSource|cspNonce|root|webroot)}/g, (_substring, token) => {
switch (token) {
case 'cspSource': case 'cspSource':
return cspSource; return cspSource;
case 'cspNonce': case 'cspNonce':
@ -529,7 +524,8 @@ export class RebaseEditorProvider implements CustomTextEditorProvider, Disposabl
default: default:
return ''; return '';
} }
});
},
);
return html; return html;
} }

+ 12
- 14
src/webviews/webviewBase.ts View File

@ -203,27 +203,24 @@ export abstract class WebviewBase implements Disposable {
const root = webview.asWebviewUri(this.container.context.extensionUri).toString(); const root = webview.asWebviewUri(this.container.context.extensionUri).toString();
const webRoot = webview.asWebviewUri(webRootUri).toString(); const webRoot = webview.asWebviewUri(webRootUri).toString();
const html = content
.replace(/#{(head|body|endOfBody|placement)}/i, (_substring, token) => {
const html = content.replace(
/#{(head|body|endOfBody|placement|cspSource|cspNonce|root|webroot)}/g,
(_substring, token) => {
switch (token) { switch (token) {
case 'head': case 'head':
return head ?? ''; return head ?? '';
case 'body': case 'body':
return body ?? ''; return body ?? '';
case 'endOfBody': case 'endOfBody':
return bootstrap != null
? `<script type="text/javascript" nonce="#{cspNonce}">window.bootstrap = ${JSON.stringify(
bootstrap,
)};</script>${endOfBody ?? ''}`
: endOfBody ?? '';
return `${
bootstrap != null
? `<script type="text/javascript" nonce="${cspNonce}">window.bootstrap=${JSON.stringify(
bootstrap,
)};</script>`
: ''
}${endOfBody ?? ''}`;
case 'placement': case 'placement':
return 'editor'; return 'editor';
default:
return '';
}
})
.replace(/#{(cspSource|cspNonce|root|webroot)}/g, (_substring, token) => {
switch (token) {
case 'cspSource': case 'cspSource':
return cspSource; return cspSource;
case 'cspNonce': case 'cspNonce':
@ -235,7 +232,8 @@ export abstract class WebviewBase implements Disposable {
default: default:
return ''; return '';
} }
});
},
);
return html; return html;
} }

+ 12
- 14
src/webviews/webviewViewBase.ts View File

@ -208,27 +208,24 @@ export abstract class WebviewViewBase implements WebviewViewProvider, Dis
const root = webview.asWebviewUri(this.container.context.extensionUri).toString(); const root = webview.asWebviewUri(this.container.context.extensionUri).toString();
const webRoot = webview.asWebviewUri(webRootUri).toString(); const webRoot = webview.asWebviewUri(webRootUri).toString();
const html = content
.replace(/#{(head|body|endOfBody|placement)}/i, (_substring, token) => {
const html = content.replace(
/#{(head|body|endOfBody|placement|cspSource|cspNonce|root|webroot)}/g,
(_substring, token) => {
switch (token) { switch (token) {
case 'head': case 'head':
return head ?? ''; return head ?? '';
case 'body': case 'body':
return body ?? ''; return body ?? '';
case 'endOfBody': case 'endOfBody':
return bootstrap != null
? `<script type="text/javascript" nonce="#{cspNonce}">window.bootstrap = ${JSON.stringify(
bootstrap,
)};</script>${endOfBody ?? ''}`
: endOfBody ?? '';
return `${
bootstrap != null
? `<script type="text/javascript" nonce="${cspNonce}">window.bootstrap=${JSON.stringify(
bootstrap,
)};</script>`
: ''
}${endOfBody ?? ''}`;
case 'placement': case 'placement':
return 'view'; return 'view';
default:
return '';
}
})
.replace(/#{(cspSource|cspNonce|root|webroot)}/g, (_substring, token) => {
switch (token) {
case 'cspSource': case 'cspSource':
return cspSource; return cspSource;
case 'cspNonce': case 'cspNonce':
@ -240,7 +237,8 @@ export abstract class WebviewViewBase implements WebviewViewProvider, Dis
default: default:
return ''; return '';
} }
});
},
);
return html; return html;
} }

Loading…
Cancel
Save