Allow saving for Makie png/html plots and improve clipboard behavior #3780
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.
The "save plot" button was not working for Makie plots ever since Makie started to show them via html MIME types, as the png MIME type doesn't show them at the intended pixel density. This PR wraps html content in an id'ed div so the plot detection code can pick that up and extract a possible single
<img>tag. With that, the existing code works for the Makie case as well.Also, I had trouble with the "copy plot to clipboard" functionality for a long time, so while I was at it, I looked into improving that as well. It seems that the focus check for clipboard access often fails because of a race condition inherent in this system, so apparently adding a small timeout improves that https://stackoverflow.com/questions/77465342/how-do-i-ensure-that-the-website-has-focus-so-the-copy-to-clipboard-can-happen. Anecdotally, this feels much better on my system. With the 0.05 timeout I seem to almost never get the "not focused" error while before I was getting that all the time. But would probably be good for others to test this, too, because the error is already nondeterministic, so the "fix" kind of is as well.
I didn't see these two functions in tests, but maybe I overlooked where the behavior is currently tested. If so, I could add tests there.