CodeEditSourceEditor icon indicating copy to clipboard operation
CodeEditSourceEditor copied to clipboard

Async and Faster Folding Calculation

Open thecoolwinter opened this issue 7 months ago • 0 comments

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 as well as the code of conduct
  • [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

thecoolwinter avatar Jun 03 '25 20:06 thecoolwinter