[Monaco] Add monaco.editor.registerLinkOpener
method to be able to intercept opening links from the editor
#177055
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.
Fixes microsoft/monaco-editor#3354
By default the Monaco editor opens links clicked in the editor in a new tab. As stated in my comment in the above issue this is a good thing! However, there are situations where you want to handle the links yourself. For example, we have types of links that should be opened in the same tab, and we have types of links that should use our own window open method that transfers some state to the new tab/window. Everything else should still use the default.
This PR addresses that need by providing a
monaco.editor.registerLinkOpener
function that can be used to intercept the openening of links from the embedded editor and handle them however the embedder wishes to. The function delegates to theIOpenerService
and returns anIDisposable
instance to unregister the handler again.Monaco Playground Code: