Skip to content
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

Open
trevorade opened this issue Dec 3, 2018 · 4 comments · May be fixed by MarcelRaschke/monaco-editor#25
Open

FR: Code folding changed event #1218

trevorade opened this issue Dec 3, 2018 · 4 comments · May be fixed by MarcelRaschke/monaco-editor#25
Assignees
Labels
editor-api feature-request Request for new features or functionality
Milestone

Comments

@trevorade
Copy link

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.

@alexdima alexdima added the feature-request Request for new features or functionality label Dec 5, 2018
@bhuemer
Copy link

bhuemer commented Dec 9, 2018

I was looking for something similar recently and just ended up doing this - yet another hack:

editor._contributions["editor.contrib.folding"].foldingModel.onDidChange(e => ...)

@trevorade
Copy link
Author

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 monaco.d.ts? I specifically would like to access the types found in https://github.com/Microsoft/vscode/blob/master/src/vs/editor/contrib/folding/

@alexdima
Copy link
Member

alexdima commented Jan 9, 2019

@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 :).

@trevorade
Copy link
Author

trevorade commented Jan 9, 2019

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
editor-api feature-request Request for new features or functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants