-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FR: Code folding changed event #1218
FR: Code folding changed event #1218
Comments
I was looking for something similar recently and just ended up doing this - yet another hack:
|
Thanks! That's just what I was looking for. If you support more than one model, this needs to be a bit more involved to work: const registerOnDidChangeFolding = () => {
const foldingContrib = this.editor.getContribution('editor.contrib.folding');
foldingContrib.getFoldingModel().then(foldingModel => {
foldingModel.onDidChange(() => {
... // Handle the model changing
});
});
};
registerOnDidChangeFolding();
editor.onDidChangeModel(registerOnDidChangeFolding); This almost looks legit now. The main missing piece is TypeScript typing. Is there a reason why the types of the contribs pulled into Monaco aren't added to |
@trevorade Because those types are not API... The API surface of the editor is already very large and we try not to break it needlessly, we try to document (relatively rare) breakages in release notes, etc... Having our entire code base be API would mean there would be no API at all. I would also no longer try to write down breaking changes since every change to a public method would be public :). |
@alexandrudima Sure, that's fine. Not all implementation needs to be exposed as public. The issue is that Monaco does not support every use case required by integrators. This is in fact desirable but when a particular use-case can only be implemented via private APIs, whether to expose some sort of public API should be decided. In my case, I need to support dynamically changing the height of the editor based on the number of visible lines. When a code folding event happens, I need to change the height. The only way I can do this is via the undocumented API I listed above. What I'm asking for is a public event on one of the existing Interfaces to notify me when code is folded. In a more general sense, I would be fine with an event which notifies me when the number of lines visible to the user changes as that would serve my use-case more directly and be more efficient as I wouldn't have to check the line-count after every edit. |
monaco-editor version: 0.15.6
Browser: Any
OS: Any
Steps or JS usage snippet reproducing the issue:
Fold some code.
Actual behavior:
No event is fired informing me that a block of code has been folded.
Desired behavior:
I'd like an event telling me a block of code has been folded.
Maybe
monaco.editor.IStandaloneCodeEditor.onDidCodeFold
or something.Use case:
I'm implementing the work-around described here: #103 and I'd like to be able to trigger resizing the editor when code is folded as well.
Current work around I'm using:
You can detect many of the code folding events by listening to
onMouseUp
. This obviously has lots of false-positives though.The text was updated successfully, but these errors were encountered: