Commit 8a47aa4
Code Folding (#341)
### 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
- Folding-related changes
- Added `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.
- Added `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.
- Added `LineIndentationFoldProvider`, an implementation of
`LineFoldProvider` that calculates folds based on the user's indent
setting.
- Added `LineFoldCalculator`, which interfaces with the given
`LineFoldProvider` 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.
- Added `LineFoldingModel`, which is the glue between the text view,
calculator, and view.
- To display folded folds, we display a `LineFoldPlaceholder` in the
text view. This keeps a reference to the `LineFoldingModel` via a
delegate protocol to tell the model when it's dismissed.
<details><summary>This is a slightly complicated object graph, so I've
added a diagram here</summary>
```mermaid
flowchart TD
TV["TextView"] -->|Text Updates| LFM["LineFoldingModel"]
PL["LineFoldPlaceholder"] --> |Placeholder Removed| LFM
LFM -->|Text Updates| LFC["LineFoldCalculator"]
LFC -->|LineFoldStorage| LFM
LFM -->|Storage Updated| FRV["FoldingRibbonView"]
LFC <--> |Fold Info| LFP["any LineFoldProvider"]
```
</details>
- Gutter View changes
- New property `showFoldingRibbon` toggles the visibility of the folding
ribbon view.
- The gutter now manages the folding ribbon view as a subview.
- Added an additional padding option on the gutter for the folding
ribbon.
- Makes a slight modification to how it draws line numbers by using a
line iterator in the drawn lines, rather than the 'visible lines'. Uses
less resources when macOS only requests a redraw for a specific rect
rather than the whole gutter.
- Other, related changes
- Modified the minimap. The minimap is now an attachment delegate to the
text view's attachment object. It receives updates to the text view's
attachments and adds a fake attachment to it's own layout manager. This
effectively syncs the text view's attachments to the minimap.
- Renamed `DispatchQueue.syncMainIfNot` to `waitMainIfNot` and updated
it to use a better method for waiting for a dispatched work item.
- Added an extension to `NSBezierPath` for rounding corners.
- Added a new `NSColor` convenience initializer for creating light and
dark mode colors more easily.
- Moved the font character width calculation from `TextViewController`
to an `NSFont` extension.
### Related Issues
* #43
### Checklist
- [x] Folds reflected in minimap.
- [x] Double-click fold expands it.
- [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/25e46ae4-3db5-4f08-8027-1fea9a8e64cb
---------
Co-authored-by: Austin Condiff <[email protected]>1 parent a148366 commit 8a47aa4
File tree
49 files changed
+1930
-131
lines changed- Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Views
- Sources/CodeEditSourceEditor
- Controller
- Enums
- Extensions
- NSEdgeInsets
- NSFont
- TextView+
- Find/ViewModel
- Gutter
- Highlighting
- StyledRangeContainer
- LineFolding
- LineFoldProviders
- Model
- Placeholder
- View
- Minimap
- RangeStore
- ReformattingGuide
- SourceEditorConfiguration
- TreeSitter
- Tests/CodeEditSourceEditorTests
- Controller
- LineFoldingTests
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
49 files changed
+1930
-131
lines changedLines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| 36 | + | |
35 | 37 | | |
36 | 38 | | |
37 | 39 | | |
| |||
86 | 88 | | |
87 | 89 | | |
88 | 90 | | |
| 91 | + | |
89 | 92 | | |
90 | 93 | | |
91 | 94 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
| |||
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
| 51 | + | |
50 | 52 | | |
51 | 53 | | |
52 | 54 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| |||
Lines changed: 2 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | | - | |
13 | | - | |
| 11 | + | |
| 12 | + | |
14 | 13 | | |
15 | 14 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
12 | 29 | | |
13 | 30 | | |
14 | 31 | | |
| |||
17 | 34 | | |
18 | 35 | | |
19 | 36 | | |
20 | | - | |
| 37 | + | |
21 | 38 | | |
22 | 39 | | |
23 | 40 | | |
| |||
129 | 146 | | |
130 | 147 | | |
131 | 148 | | |
| 149 | + | |
132 | 150 | | |
133 | 151 | | |
134 | 152 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| |||
Lines changed: 0 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | 14 | | |
32 | 15 | | |
33 | 16 | | |
| |||
Lines changed: 11 additions & 28 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
51 | 54 | | |
52 | 55 | | |
53 | 56 | | |
| |||
170 | 173 | | |
171 | 174 | | |
172 | 175 | | |
173 | | - | |
| 176 | + | |
174 | 177 | | |
175 | 178 | | |
176 | | - | |
| 179 | + | |
177 | 180 | | |
178 | | - | |
| 181 | + | |
179 | 182 | | |
180 | 183 | | |
181 | | - | |
| 184 | + | |
182 | 185 | | |
183 | 186 | | |
184 | 187 | | |
185 | 188 | | |
186 | 189 | | |
187 | | - | |
| 190 | + | |
188 | 191 | | |
189 | | - | |
| 192 | + | |
190 | 193 | | |
191 | 194 | | |
192 | 195 | | |
| |||
199 | 202 | | |
200 | 203 | | |
201 | 204 | | |
| 205 | + | |
202 | 206 | | |
203 | 207 | | |
204 | 208 | | |
205 | 209 | | |
206 | 210 | | |
207 | 211 | | |
208 | 212 | | |
| 213 | + | |
209 | 214 | | |
210 | 215 | | |
211 | 216 | | |
| |||
249 | 254 | | |
250 | 255 | | |
251 | 256 | | |
252 | | - | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | | - | |
273 | | - | |
274 | 257 | | |
275 | 258 | | |
276 | 259 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
0 commit comments