parent
2272f36e59
commit
f36cae36dc
4 changed files with 33 additions and 9 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -5,15 +5,17 @@
|
||||||
|
|
||||||
import { getSettings } from './settings';
|
import { getSettings } from './settings';
|
||||||
|
|
||||||
|
declare var vscode: any;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Post a message to the markdown extension
|
* Post a message to the markdown extension
|
||||||
*/
|
*/
|
||||||
export function postMessage(type: string, body: object) {
|
export function postMessage(type: string, body: object) {
|
||||||
window.parent.postMessage({
|
vscode.postMessage({
|
||||||
type,
|
type,
|
||||||
source: getSettings().source,
|
source: getSettings().source,
|
||||||
body
|
body
|
||||||
}, '*');
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
const ipcRenderer = require('electron').ipcRenderer;
|
const ipcRenderer = require('electron').ipcRenderer;
|
||||||
|
|
||||||
|
|
||||||
const registerVscodeResourceScheme = (function() {
|
const registerVscodeResourceScheme = (function () {
|
||||||
let hasRegistered = false;
|
let hasRegistered = false;
|
||||||
return () => {
|
return () => {
|
||||||
if (hasRegistered) {
|
if (hasRegistered) {
|
||||||
|
@ -174,6 +174,28 @@
|
||||||
newDocument.head.appendChild(baseElement);
|
newDocument.head.appendChild(baseElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// apply default script
|
||||||
|
if (enableWrappedPostMessage) {
|
||||||
|
const defaultScript = newDocument.createElement('script');
|
||||||
|
defaultScript.textContent = `
|
||||||
|
const vscode = Object.freeze((function() {
|
||||||
|
const originalPostMessage = window.parent.postMessage.bind(window.parent);
|
||||||
|
return {
|
||||||
|
postMessage: function(msg) {
|
||||||
|
return originalPostMessage(msg, '*');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
})());
|
||||||
|
delete window.parent;
|
||||||
|
`;
|
||||||
|
|
||||||
|
if (newDocument.head.hasChildNodes()) {
|
||||||
|
newDocument.head.insertBefore(defaultScript, newDocument.head.firstChild);
|
||||||
|
} else {
|
||||||
|
newDocument.head.appendChild(defaultScript);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// apply default styles
|
// apply default styles
|
||||||
const defaultStyles = newDocument.createElement('style');
|
const defaultStyles = newDocument.createElement('style');
|
||||||
defaultStyles.id = '_defaultStyles';
|
defaultStyles.id = '_defaultStyles';
|
||||||
|
|
Loading…
Reference in a new issue