-
Notifications
You must be signed in to change notification settings - Fork 96
Code Folding #341
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
Open
thecoolwinter
wants to merge
19
commits into
main
Choose a base branch
from
feat/code-folding
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Code Folding #341
Conversation
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
### Description > [!NOTE] > For reviewers, this is merging into the dev branch. These changes require the version of CETV in [this PR](CodeEditApp/CodeEditTextView#93). Please pull those changes locally and test using that. > [!NOTE] > I'll be making some TODOs in the tracking issue #43 for things that aren't included here. Like the overlapping folds UI issue. Adds the first version of the code folding ribbon, with a very basic folding model. This is mostly a UI change. It includes changes to the gutter, and a new view for displaying folds. The model and related demo fold provider should be considered incomplete and only for demo purposes. This also doesn't implement the hover state yet. Just a very basic outline of everything. Things to review: - New `FoldingRibbonView` - New `LineFoldingModel` - Changes in `GutterView` - Changes to `TextViewController` - Changes to `CodeEditSourceEditor` ### Related Issues * #43 ### Checklist - [x] I read and understood the [contributing guide](https://github.com/CodeEditApp/CodeEdit/blob/main/CONTRIBUTING.md) as well as the [code of conduct](https://github.com/CodeEditApp/CodeEdit/blob/main/CODE_OF_CONDUCT.md) - [x] The issues this PR addresses are related to each other - [x] My changes generate no new warnings - [x] My code builds and runs on my machine - [x] My changes are all related to the related issue above - [x] I documented my code ### Screenshots Light mode.  Dark Mode.  Folds are transparent for scrolling text.  --------- Co-authored-by: Austin Condiff <[email protected]>
### Description Adds the hover interaction to the code folding ribbon. Details: - Animates in when entering the fold region. - Does not animate when moving between folds after animation. - Hovered lines are emphasized and not transparent. ### Related Issues * #43 ### Checklist - [x] I read and understood the [contributing guide](https://github.com/CodeEditApp/CodeEdit/blob/main/CONTRIBUTING.md) as well as the [code of conduct](https://github.com/CodeEditApp/CodeEdit/blob/main/CODE_OF_CONDUCT.md) - [x] The issues this PR addresses are related to each other - [x] My changes generate no new warnings - [x] My code builds and runs on my machine - [x] My changes are all related to the related issue above - [x] I documented my code ### Screenshots https://github.com/user-attachments/assets/164e61e9-07c0-4a0c-814d-7a70226e0136 --------- Co-authored-by: Austin Condiff <[email protected]>
### Description Updates line folding to happen asynchronously off the main thread, and to work while editing text. It now remembers folded ranges and correctly handles nested folds. > Sorry for this huge commit log, it's terrible! Thankfully it'll be squashed when merged. The meat of the changes here are in `LineFoldCalculator`, `LineFoldModel`, and `LineFoldStorage`. I've moved some files, resulting in the large diff and I'm sorry for that for reviewers I know that makes it hard. - Refactors the folding model to use a new `LineFoldCalculator` type. - This type accepts an async stream of edit notifications, and produces a stream of the new `LineFoldStorage` type. - Asynchronously accesses text on the main thread for safety. - Adds a new `LineFoldStorage` type. - Internally uses the `RangeStore` type to quickly store fold ranges as spans in a text document. - Has methods for querying text ranges, collapsing ranges, and updating using new values from the `LineFoldCalculator` stream. - Is `Sendable` to work easily with async streams. - Updates the drawing code to handle new behaviors of the fold model. ### Related Issues * #43 ### Checklist - [x] I read and understood the [contributing guide](https://github.com/CodeEditApp/CodeEdit/blob/main/CONTRIBUTING.md) as well as the [code of conduct](https://github.com/CodeEditApp/CodeEdit/blob/main/CODE_OF_CONDUCT.md) - [x] The issues this PR addresses are related to each other - [x] My changes generate no new warnings - [x] My code builds and runs on my machine - [x] My changes are all related to the related issue above - [x] I documented my code ### Screenshots https://github.com/user-attachments/assets/bc1d5bd1-bf87-45ba-ad0f-53655b2542fc --------- Co-authored-by: Austin Condiff <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Adds a code folding ribbon.
Note
For reviewers: Most of these changes have been reviewed individually in separate PRs. This shouldn't require a detailed combing over. If you can review a few things in particular like: architecture, naming, and bugs with real use I think those would be the best use of your limited time.
Detailed Changes
FoldingRibbonView
- A view that draws a set of folding ranges. This does all the drawing manually to avoid having to manage view reuse, it does the drawing in the regions macOS designates so it only draws a small part of the visible ribbon at a time.LineFoldProvider
- A protocol for classes to provide fold information to CodeEditSourceEditor. This takes a line number, range, depth, and a reference to the text controller and returns a list of 'line info' objects.LineIndentationFoldProvider
, an implementation ofLineFoldProvider
that calculates folds based on the user's indent setting.LineFoldCalculator
, which interfaces with the givenLineFoldProvider
to calculate new folds. This happens asynchronously and recalculates every so often. It's very fast but stays off the main thread to avoid ever gumming up the user's typing.LineFoldingModel
, which is the glue between the text view, calculator, and view.LineFoldPlaceholder
in the text view. This keeps a reference to theLineFoldingModel
via a delegate protocol to tell the model when it's dismissed.This is a slightly complicated object graph, so I've added a diagram here
showFoldingRibbon
toggles the visibility of the folding ribbon view.DispatchQueue.syncMainIfNot
towaitMainIfNot
and updated it to use a better method for waiting for a dispatched work item.NSBezierPath
for rounding corners.NSColor
convenience initializer for creating light and dark mode colors more easily.TextViewController
to anNSFont
extension.Related Issues
Checklist
Screenshots
Screen.Recording.2025-06-25.at.4.07.28.PM.mov