[Monaco] Add monaco.editor.registerEditorOpener method to be able to intercept editor open operations#177064
Merged
Merged
Conversation
956c4f1 to
9216747
Compare
2 tasks
Contributor
Author
|
@hediet Could this be considered for one of the next Monaco versions? Thank you! |
hediet
reviewed
Apr 5, 2023
| } | ||
|
|
||
| export interface ICodeEditorOpener { | ||
| openCodeEditor(source: ICodeEditor, resource: URI, selectionOrPosition?: IRange | IPosition): boolean | Promise<boolean>; |
Member
There was a problem hiding this comment.
Please add some doc comments explaining when this method is called (copying the comment from the register call).
hediet
previously approved these changes
Apr 5, 2023
…ept editor open operations
Contributor
Author
|
Addressed review and rebased onto main. |
Member
|
Thanks!
Generally, please don't rebase in PRs, as that resets the review. |
hediet
approved these changes
Apr 5, 2023
aiday-mar
approved these changes
Apr 5, 2023
Contributor
Author
|
This seems stuck, do I need to do something? |
alexr00
approved these changes
Apr 13, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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#2000
By default the "go to defintion" action in the Monaco editor does nothing if the definition is in another model, or opens a peek window when multiple definitions are found. This default is a good thing because just changing the underlying model would be very detrimental when embedding the editor. However, there are use-cases where you maybe want to control what happens when you go to a definition. For example, when we embed the Monaco editor we would like to open a new tab to the source code containing the definition for certain models but not all of them.
This PR adds a new function
monaco.editor.registerEditorOpenerthat lets the embedder intercept such open operations and handle those themselves. By using a boolean return value the embedder can indicate if the resource was handled or the editor should fallback to the default. The function returns anIDisposableinstance that can be used to unregister the handler again. This interception can be tested in the code below by e.g. Ctrl-clicking on thealertfunction. By intercepting the open operation you can also choose to change the underlying editor model yourself if that makes sense in your application (see linked issue).Edit: I decided to remove a second commit because it didn't work properly in some cases. This reduces the PR to just the new method to intercept the editor open operation.
Monaco Playground Code: