mirror of https://gitlab.com/basile.b/dexed.git
added folding to cache system
This commit is contained in:
parent
96be761415
commit
b93810099f
|
@ -5,15 +5,14 @@ unit ce_synmemo;
|
||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, SynEdit, ce_d2syn, ce_txtsyn ,SynEditHighlighter,
|
Classes, SysUtils, SynEdit, ce_d2syn, ce_txtsyn ,SynEditHighlighter, controls,
|
||||||
controls, lcltype, LazSynEditText, SynEditKeyCmds, SynHighlighterLFM, SynEditMouseCmds,
|
lcltype, LazSynEditText, SynEditKeyCmds, SynHighlighterLFM, SynEditMouseCmds,
|
||||||
ce_common, ce_observer, ce_writableComponent, crc, SynEditFoldedView;
|
SynEditFoldedView, crc, ce_common, ce_observer, ce_writableComponent;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
TCESynMemo = class;
|
TCESynMemo = class;
|
||||||
|
|
||||||
// TextView, TSynEditFoldedView
|
|
||||||
TCEFoldCache = class(TCollectionItem)
|
TCEFoldCache = class(TCollectionItem)
|
||||||
private
|
private
|
||||||
fCollapsed: boolean;
|
fCollapsed: boolean;
|
||||||
|
@ -31,11 +30,13 @@ type
|
||||||
fFolds: TCollection;
|
fFolds: TCollection;
|
||||||
fCaretPosition: Integer;
|
fCaretPosition: Integer;
|
||||||
fSelectionEnd: Integer;
|
fSelectionEnd: Integer;
|
||||||
|
fSourceFilename: string;
|
||||||
procedure setFolds(someFolds: TCollection);
|
procedure setFolds(someFolds: TCollection);
|
||||||
published
|
published
|
||||||
property caretPosition: Integer read fCaretPosition write fCaretPosition;
|
property caretPosition: Integer read fCaretPosition write fCaretPosition;
|
||||||
|
property sourceFilename: string read fSourceFilename write fSourceFilename;
|
||||||
|
property folds: TCollection read fFolds write setFolds;
|
||||||
property selectionEnd: Integer read fSelectionEnd write fSelectionEnd;
|
property selectionEnd: Integer read fSelectionEnd write fSelectionEnd;
|
||||||
//property folds: TCollection read fFolds write setFolds;
|
|
||||||
public
|
public
|
||||||
constructor create(aComponent: TComponent); override;
|
constructor create(aComponent: TComponent); override;
|
||||||
destructor destroy; override;
|
destructor destroy; override;
|
||||||
|
@ -136,21 +137,51 @@ begin
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCESynMemoCache.beforeSave;
|
procedure TCESynMemoCache.beforeSave;
|
||||||
//var
|
var
|
||||||
// i: Integer;
|
i, start, prev: Integer;
|
||||||
// itm : TCEFoldCache;
|
itm : TCEFoldCache;
|
||||||
begin
|
begin
|
||||||
if fMemo = nil then exit;
|
if fMemo = nil then exit;
|
||||||
//
|
//
|
||||||
fCaretPosition := fMemo.SelStart;
|
fCaretPosition := fMemo.SelStart;
|
||||||
|
fSourceFilename := fMemo.fileName;
|
||||||
fSelectionEnd := fMemo.SelEnd;
|
fSelectionEnd := fMemo.SelEnd;
|
||||||
//
|
//
|
||||||
//TODO-cEditor Cache: folding persistence
|
// TODO-cEditor Cache: >nested< folding persistence
|
||||||
|
// cf. other ways: http://forum.lazarus.freepascal.org/index.php?topic=26748.msg164722#msg164722
|
||||||
|
prev := fMemo.Lines.Count-1;
|
||||||
|
for i := fMemo.Lines.Count-1 downto 0 do
|
||||||
|
begin
|
||||||
|
// - CollapsedLineForFoldAtLine() does not handle the sub-folding.
|
||||||
|
// - TextView visibility is increased so this is not the standard way of getting the infos.
|
||||||
|
start := fMemo.TextView.CollapsedLineForFoldAtLine(i);
|
||||||
|
if start = -1 then
|
||||||
|
continue;
|
||||||
|
if start = prev then
|
||||||
|
continue;
|
||||||
|
prev := start;
|
||||||
|
itm := TCEFoldCache(fFolds.Add);
|
||||||
|
itm.isCollapsed := true;
|
||||||
|
itm.fLineIndex := start;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCESynMemoCache.afterLoad;
|
procedure TCESynMemoCache.afterLoad;
|
||||||
|
var
|
||||||
|
i: integer;
|
||||||
|
itm : TCEFoldCache;
|
||||||
begin
|
begin
|
||||||
if fMemo = nil then exit;
|
if fMemo = nil then exit;
|
||||||
|
// Currently collisions are not handled.
|
||||||
|
if fMemo.fileName <> fSourceFilename then exit;
|
||||||
|
//
|
||||||
|
for i := 0 to fFolds.Count-1 do
|
||||||
|
begin
|
||||||
|
itm := TCEFoldCache(fFolds.Items[i]);
|
||||||
|
if not itm.isCollapsed then
|
||||||
|
continue;
|
||||||
|
fMemo.TextView.FoldAtLine(itm.lineIndex-1);
|
||||||
|
end;
|
||||||
//
|
//
|
||||||
fMemo.SelStart := fCaretPosition;
|
fMemo.SelStart := fCaretPosition;
|
||||||
fMemo.SelEnd := fSelectionEnd;
|
fMemo.SelEnd := fSelectionEnd;
|
||||||
|
|
Loading…
Reference in New Issue