Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: does not work on VSCode 1.47.0 and later #144

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function activate(context) {
vscode.window.registerWebviewPanelSerializer('polacode', {
async deserializeWebviewPanel(_panel, state) {
panel = _panel
panel.webview.html = getHtmlContent(htmlPath)
panel.webview.html = getHtmlContent()
panel.webview.postMessage({
type: 'restore',
innerHTML: state.innerHTML,
Expand All @@ -42,7 +42,7 @@ function activate(context) {
localResourceRoots: [vscode.Uri.file(path.join(context.extensionPath, 'webview'))]
})

panel.webview.html = getHtmlContent(htmlPath)
panel.webview.html = getHtmlContent()

const selectionListener = setupSelectionSync()
panel.onDidDispose(() => {
Expand Down Expand Up @@ -129,14 +129,14 @@ function activate(context) {
}
})
}
}

function getHtmlContent(htmlPath) {
const htmlContent = fs.readFileSync(htmlPath, 'utf-8')
return htmlContent.replace(/script src="([^"]*)"/g, (match, src) => {
const realSource = 'vscode-resource:' + path.resolve(htmlPath, '..', src)
return `script src="${realSource}"`
})
function getHtmlContent() {
const htmlContent = fs.readFileSync(htmlPath, 'utf-8')
const absolutePath = vscode.Uri.file(context.asAbsolutePath('./webview'))
const webviewPath = panel.webview.asWebviewUri(absolutePath).toString()

return htmlContent.replace(/{{root}}/g, webviewPath);
}
}

exports.activate = activate
6 changes: 3 additions & 3 deletions webview/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@
</svg>
</div>

<script src="./dom2image.js"></script>
<script src="./vivus.js"></script>
<script src="./index.js"></script>
<script src="{{root}}/dom2image.js"></script>
<script src="{{root}}/vivus.js"></script>
<script src="{{root}}/index.js"></script>
</body>
</html>