inject webview-events.js script into preview html #5766
+866
−183
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Implementation
Mainly, I used the "Create some sort of proxy layer of our own to inject the script" idea from #4276, with a bit of "Run away from home and live in the woods" sprinkled in the process.
Positron Proxy
scripts_preview.html
file that serves a similar purpose for the Viewer as thescripts_help.html
for the Help Pane, which is used as a "template" to inject resources like styles and scripts into the HTML content being presented in the Viewerwebview-events.js
script (see extensions/positron-proxy/resources/webview-events.js) into this template. The webview-events.js script is a copy of the existing Electron version of the script (see src/vs/workbench/contrib/webview/browser/pre/webview-events.js), with a couple modifications for running in a Web context. Changes are fenced between// --- Start Positron Proxy Changes ---
and// --- End Positron Proxy Changes ---
comments.Webview land
previewOverlayWebview.ts:loadUri()
to align more closely with the HTML structure of src/vs/workbench/contrib/positronHelp/browser/resources/help.htmlpreviewOverlayWebview.ts:loadUri()
no longer handles reload/navigation and instead forwards messages along to the Webview or the iframe containing the content as applicable__positron_preview_message
is passedonmessage
handler inwebviewElement.ts
to unwrap messages flagged with__positron_preview_message
and pass them to the appropriate handlersHTML Nesting Structure
Here's a summary of the HTML nesting situation, with some pseudo-HTML.
QA Notes
The changes in this PR should only impact the Viewer in Positron Server Web / Workbench.
The following keyboard actions should work:
In the Viewer menu bar, the following buttons should work:
Preview an HTML file directly
Things to verify
OilandGasMetadata.html
file, save the changes and click the Refresh button in the Viewer. The page in the Viewer should refresh and show the change you made.Preview an HTML page being served
Any of the qa-examples-content directory app frameworks should do, but I tested with the flask_example, as it's easier to test the back/forward navigation and copy/paste keyboard actions.
__init__.py
file in an editorThings to verify
Back/Forward navigation buttons work
back_forward_nav_viewer.mp4
Refresh button works
refresh_button_viewer.mp4
Copy/Cut/Paste/Select All should all work