3

I'm working on a simple editor for the C programming language (without using an AST), and I need to implement a code folding feature.

When the user opens a file, an initial parse is performed, and all {} code blocks are easily detected. I store these blocks in a tree structure, where nested blocks are children of their enclosing block.

The challenge arises when the user makes edits. For each edit, I have the following information:

  • startLineIndex (the index of the first affected line),
  • endLineIndex (the index of the last affected line),
  • addedLineCount,
  • removedLineCount.

At this point, I need to update the folding model in the most efficient way possible — ideally by re-parsing only a minimal portion of the code.

Can someone suggest which algorithms or techniques could be used to efficiently update the folding block model after user edits?

SilverCube
  • 131
  • 3

0 Answers0