Repository navigation
Add command to post a message to an html preview document - #18422
Matt Bierner (mjbvz) wants to merge 2 commits into
Conversation
**Bug** There is currently no easy way to communicate with an html preview document after the preview has been created. **Fix** Adds a command called `vscode.htmlPreview.postMessage` to post a message to a visible html preview. This message will only be posted if the target preview is visible. Inside the preview, the event is recieved using the standard dom event:
| .filter(c => c instanceof HtmlPreviewPart) | ||
| .map(e => e as HtmlPreviewPart) | ||
| .filter(e => e.model.uri.scheme == uri.scheme && e.model.uri.path === uri.path); | ||
| if (activePreview.length) { |
There was a problem hiding this comment.
You may want to highlight in the description or doc that only the first visible matched htmlPreview document can get the message.
TBH that's the idea of the preview command. It's a fire and forget command to preview a string as html, not a PreviewPart that you can interact with. I am against adding more commands around this. It seems to me we are trying improve Markdown but need new API for each feature. So we can either add more APIs for this (special) case or we simply move Markdown back into the core. |
|
I've implemented some generic code to provide a similar feature here. It uses websockets to send & recieve messages. Maybe it should be spun off into a standalone library via npm or as an exported extension API? Supported functions:
|
Bug
There is currently no easy way to communicate from the editor to an html preview document after the preview has been created.
Fix
Adds a command called
vscode.htmlPreview.postMessageto post a message to a visible html preview. This message will only be posted if the target preview is visible (meaning this is mainly for side by side editor use cases).Inside the preview, the event is recieved using the standard dom event: