Recent

Author Topic: [SynEdit] Collecting folding state  (Read 5501 times)

Basile B.

  • Guest
[SynEdit] Collecting folding state
« on: December 12, 2014, 11:25:55 am »
How can I collect the fold state of an Editor ?

I'd like to store/restore to/from a collection whose items would encapsulate two props (line index, folding state), but it's not so obvious where the information are standing.

So far the editor use a TSynCustomFoldHighlighter which implements very simple folding (only one type).
I noticed the property TextView, returning a TSynEditFoldedView, but it doesn't seem to help that much in reaching my goal...

Any tip or help on the subject ? these deep parts of SynEdit are not well documented.
« Last Edit: December 13, 2014, 12:05:24 pm by Basile B. »

Edson

  • Hero Member
  • *****
  • Posts: 1301
Re: [SynEdit] Collecting folding state
« Reply #1 on: December 12, 2014, 04:37:59 pm »
All the information about Folding (and ranges) is stored in the Object Field associated to each line of the SynEdit -> CurrentRanges[].

All this information is obtained after scanning all the content of a SynEdit, and it's consistent with it. You could save/restore this information, but generally it's the highlighter who build this.

Do you want to have a syntactic tree?

There are several pages of documentation about "TSynCustomFoldHighlighter" in "La Biblia del SynEdit" (in spanish).
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

Basile B.

  • Guest
Re: [SynEdit] Collecting folding state
« Reply #2 on: December 12, 2014, 05:06:24 pm »
No, I don't need the AST, it's to store the document state between two cessions, so i just need to know if it's collapsed or not.

like this. So far only the position and the selection are saved.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9792
  • Debugger - SynEdit - and more
    • wiki
Re: [SynEdit] Collecting folding state
« Reply #3 on: December 12, 2014, 05:20:59 pm »
Code: [Select]
SynEdit.FoldState
It only works for highlighter based folds.

If you select text, and fold/hide the selection, thin this is not included, and will not be restored.

The returned value only contain printable chars, and can be used in an xml.

It calls:
Code: [Select]
TSynEditFoldedView.GetFoldDescription(
If you call that directly, you can get binary representation too (none printable chars...). That is used when copy and paste folded text.



Basile B.

  • Guest
Re: [SynEdit] Collecting folding state
« Reply #4 on: December 12, 2014, 06:32:37 pm »
Thx, it looks like the right thing, but... GetFoldState() result is always an empty string, even if every fold in the doc is collapsed.


Could it be explained by:
- GetFoldState() is called in TCustomSynEdit destructor
- my HL sets the folds in the most simple way possible, without BlockType (StartCodeFoldBlock(nil);

I' ve put some breakpoints in the function TSynEditFoldedView.GetFoldDescription(...): String;

and the method seems to be called as it should.
« Last Edit: December 12, 2014, 06:34:38 pm by Basile B. »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9792
  • Debugger - SynEdit - and more
    • wiki
Re: [SynEdit] Collecting folding state
« Reply #5 on: December 12, 2014, 06:45:49 pm »
It asks the HL for various info, such as the column at which the fold starts.

IIRC (and really it is a long time ...)

You need to override TSynCustomFoldHighlighter.InitFoldNodeInfo

So far this is only done in the pas highlighter.

The entire code needs at some time to be reviewed, cleaned, and them moved to the base class.

 

TinyPortal © 2005-2018