mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-11-20 18:20:19 +01:00
SynEdit: Introduced TSynTextViewsManager
git-svn-id: trunk@63196 -
This commit is contained in:
parent
3ea592d076
commit
e04ce2539f
@ -395,9 +395,9 @@ type
|
||||
|
||||
TSynEditStringsLinked = class(TSynEditStrings)
|
||||
private
|
||||
procedure SetSynStrings(AValue: TSynEditStrings);
|
||||
protected
|
||||
fSynStrings: TSynEditStrings;
|
||||
protected
|
||||
procedure SetSynStrings(AValue: TSynEditStrings); virtual;
|
||||
|
||||
function GetIsUtf8 : Boolean; override;
|
||||
procedure SetIsUtf8(const AValue : Boolean); override;
|
||||
@ -439,8 +439,6 @@ type
|
||||
|
||||
function GetDisplayView: TLazSynDisplayView; override;
|
||||
public
|
||||
constructor Create(ASynStringSource: TSynEditStrings);
|
||||
|
||||
function Add(const S: string): integer; override;
|
||||
procedure AddStrings(AStrings: TStrings); override;
|
||||
procedure Clear; override;
|
||||
@ -490,6 +488,33 @@ type
|
||||
procedure EditRedo(Item: TSynEditUndoItem); override;
|
||||
end;
|
||||
|
||||
{ TSynTextViewsManager }
|
||||
|
||||
TSynEditStringsLinkedClass = class of TSynEditStringsLinked;
|
||||
|
||||
TSynTextViewsManager = class
|
||||
private
|
||||
FTextViewsList : TList;
|
||||
FTextBuffer: TSynEditStrings;
|
||||
FTopViewChangedCallback: TNotifyEvent;
|
||||
function GetSynTextView(Index: integer): TSynEditStringsLinked;
|
||||
function GetSynTextViewByClass(Index: TSynEditStringsLinkedClass): TSynEditStringsLinked;
|
||||
procedure ReconnectViews;
|
||||
procedure SetTextBuffer(AValue: TSynEditStrings);
|
||||
protected
|
||||
property TextBuffer: TSynEditStrings read FTextBuffer write SetTextBuffer;
|
||||
public
|
||||
constructor Create(ATextBuffer: TSynEditStrings; ATopViewChangedCallback: TNotifyEvent);
|
||||
destructor Destroy; override;
|
||||
|
||||
Procedure AddTextView(aTextView : TSynEditStringsLinked; AsFirst: Boolean = False);
|
||||
Procedure AddTextView(aTextView : TSynEditStringsLinked; AIndex: Integer);
|
||||
Procedure AddTextView(aTextView : TSynEditStringsLinked; AnAfter: TSynEditStringsLinked);
|
||||
Procedure RemoveSynTextView(aTextView : TSynEditStringsLinked; aDestroy: Boolean = False);
|
||||
function Count: Integer;
|
||||
property SynTextView[Index: integer]: TSynEditStringsLinked read GetSynTextView;
|
||||
property SynTextViewByClass[Index: TSynEditStringsLinkedClass]: TSynEditStringsLinked read GetSynTextViewByClass;
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
@ -1217,12 +1242,6 @@ end;
|
||||
|
||||
{ TSynEditStringsLinked }
|
||||
|
||||
constructor TSynEditStringsLinked.Create(ASynStringSource: TSynEditStrings);
|
||||
begin
|
||||
fSynStrings := ASynStringSource;
|
||||
Inherited Create;
|
||||
end;
|
||||
|
||||
function TSynEditStringsLinked.Add(const S: string): integer;
|
||||
begin
|
||||
Result := fSynStrings.Add(S);
|
||||
@ -1292,11 +1311,6 @@ procedure TSynEditStringsLinked.SetSynStrings(AValue: TSynEditStrings);
|
||||
begin
|
||||
if fSynStrings = AValue then Exit;
|
||||
fSynStrings := AValue;
|
||||
if DisplayView <> nil then begin
|
||||
if fSynStrings = nil
|
||||
then DisplayView.NextView := nil
|
||||
else DisplayView.NextView := fSynStrings.DisplayView;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TSynEditStringsLinked.GetIsUtf8: Boolean;
|
||||
@ -1306,7 +1320,8 @@ end;
|
||||
|
||||
procedure TSynEditStringsLinked.SetIsUtf8(const AValue: Boolean);
|
||||
begin
|
||||
FSynStrings.IsUtf8 := AValue;
|
||||
if FSynStrings <> nil then
|
||||
FSynStrings.IsUtf8 := AValue;
|
||||
end;
|
||||
|
||||
function TSynEditStringsLinked.GetTextChangeStamp: int64;
|
||||
@ -1556,5 +1571,121 @@ begin
|
||||
fSynStrings.DecIsInEditAction;
|
||||
end;
|
||||
|
||||
{ TSynTextViewsManager }
|
||||
|
||||
function TSynTextViewsManager.GetSynTextView(Index: integer): TSynEditStringsLinked;
|
||||
begin
|
||||
Result := TSynEditStringsLinked(FTextViewsList[Index]);
|
||||
end;
|
||||
|
||||
function TSynTextViewsManager.GetSynTextViewByClass(
|
||||
Index: TSynEditStringsLinkedClass): TSynEditStringsLinked;
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
Result := nil;
|
||||
for i := 0 to FTextViewsList.Count-1 do
|
||||
if TSynEditStringsLinked(FTextViewsList[i]).ClassType = Index then
|
||||
exit(TSynEditStringsLinked(FTextViewsList[i]));
|
||||
end;
|
||||
|
||||
procedure TSynTextViewsManager.ReconnectViews;
|
||||
var
|
||||
i: Integer;
|
||||
dsp: TLazSynDisplayView;
|
||||
begin
|
||||
SynTextView[0].NextLines := FTextBuffer;
|
||||
dsp := FTextBuffer.DisplayView;
|
||||
|
||||
for i := 1 to FTextViewsList.Count-1 do begin
|
||||
SynTextView[i].NextLines := SynTextView[i-1];
|
||||
|
||||
if (SynTextView[i].DisplayView <> dsp) then begin
|
||||
SynTextView[i].DisplayView.NextView := dsp;
|
||||
dsp := SynTextView[i].DisplayView.NextView;
|
||||
end;
|
||||
end;
|
||||
FTopViewChangedCallback(SynTextView[Count-1]);
|
||||
end;
|
||||
|
||||
procedure TSynTextViewsManager.SetTextBuffer(AValue: TSynEditStrings);
|
||||
begin
|
||||
if FTextBuffer = AValue then Exit;
|
||||
FTextBuffer := AValue;
|
||||
ReconnectViews;
|
||||
end;
|
||||
|
||||
constructor TSynTextViewsManager.Create(ATextBuffer: TSynEditStrings;
|
||||
ATopViewChangedCallback: TNotifyEvent);
|
||||
begin
|
||||
FTextBuffer := ATextBuffer;
|
||||
FTopViewChangedCallback := ATopViewChangedCallback;
|
||||
FTextViewsList := TList.Create;
|
||||
end;
|
||||
|
||||
destructor TSynTextViewsManager.Destroy;
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
// Destroy in reverse order / keep NextLines valid for each inner
|
||||
i := Count - 1;
|
||||
while i >= 0 do begin
|
||||
TSynEditStringsLinked(FTextViewsList[i]).Free;
|
||||
FTextViewsList.Delete(i);
|
||||
i := Count - 1;
|
||||
end;
|
||||
FTextViewsList.Free;
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
procedure TSynTextViewsManager.AddTextView(aTextView: TSynEditStringsLinked;
|
||||
AsFirst: Boolean);
|
||||
begin
|
||||
if AsFirst then
|
||||
FTextViewsList.Insert(0, aTextView)
|
||||
else
|
||||
FTextViewsList.Add(aTextView);
|
||||
ReconnectViews;
|
||||
end;
|
||||
|
||||
procedure TSynTextViewsManager.AddTextView(aTextView: TSynEditStringsLinked;
|
||||
AIndex: Integer);
|
||||
begin
|
||||
FTextViewsList.Insert(AIndex, aTextView);
|
||||
ReconnectViews;
|
||||
end;
|
||||
|
||||
procedure TSynTextViewsManager.AddTextView(
|
||||
aTextView: TSynEditStringsLinked; AnAfter: TSynEditStringsLinked);
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
i := FTextViewsList.IndexOf(AnAfter);
|
||||
if i >= 0 then
|
||||
FTextViewsList.Insert(i + 1, aTextView)
|
||||
else
|
||||
FTextViewsList.Add(aTextView);
|
||||
ReconnectViews;
|
||||
end;
|
||||
|
||||
procedure TSynTextViewsManager.RemoveSynTextView(aTextView: TSynEditStringsLinked;
|
||||
aDestroy: Boolean);
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
i := FTextViewsList.IndexOf(aTextView);
|
||||
if i >= 0 then begin
|
||||
if aDestroy then
|
||||
TSynEditStringsLinked(FTextViewsList[i]).Free;
|
||||
FTextViewsList.Delete(i);
|
||||
ReconnectViews
|
||||
end;
|
||||
end;
|
||||
|
||||
function TSynTextViewsManager.Count: Integer;
|
||||
begin
|
||||
Result := FTextViewsList.Count;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
|
||||
@ -531,6 +531,7 @@ type
|
||||
FFoldedLinesView: TSynEditFoldedView;
|
||||
FShareOptions: TSynEditorShareOptions;
|
||||
FVisibleSpecialChars: TSynVisibleSpecialChars;
|
||||
FTextViewsManager: TSynTextViewsManager;
|
||||
FTrimmedLinesView: TSynEditStringTrimmingList;
|
||||
FDoubleWidthChrLinesView: SynEditStringDoubleWidthChars;
|
||||
FBidiChrLinesView: TSynEditStringBidiChars;
|
||||
@ -541,8 +542,6 @@ type
|
||||
FTheLinesView: TSynEditStrings;
|
||||
FLines: TSynEditStrings; // The real (un-mapped) line-buffer
|
||||
FStrings: TStrings; // External TStrings based interface to the Textbuffer
|
||||
FTopLinesView: TSynEditStrings; // The linesview that holds the real line-buffer/FLines
|
||||
FDisplayView: TLazSynDisplayView;
|
||||
|
||||
fExtraCharSpacing: integer;
|
||||
fMaxLeftChar: Integer; // 1024
|
||||
@ -629,6 +628,7 @@ type
|
||||
FOnMouseLink: TSynMouseLinkEvent;
|
||||
FPendingFoldState: String;
|
||||
|
||||
procedure DoTopViewChanged(Sender: TObject);
|
||||
procedure UpdateScreenCaret;
|
||||
procedure AquirePrimarySelection;
|
||||
function GetChangeStamp: int64;
|
||||
@ -1171,6 +1171,8 @@ type
|
||||
property Markup[Index: integer]: TSynEditMarkup read GetMarkup;
|
||||
property MarkupByClass[Index: TSynEditMarkupClass]: TSynEditMarkup read GetMarkupByClass;
|
||||
property TrimSpaceType: TSynEditStringTrimmingType read GetTrimSpaceType write SetTrimSpaceType;
|
||||
|
||||
property TextViewsManager: TSynTextViewsManager read FTextViewsManager; experimental; // Only use to Add/remove views
|
||||
public
|
||||
// Caret
|
||||
procedure SetCaretTypeSize(AType: TSynCaretType;AWidth, AHeight, AXOffs, AYOffs: Integer);
|
||||
@ -1383,6 +1385,11 @@ const
|
||||
|
||||
type
|
||||
|
||||
TSynTextViewsManagerInternal = class(TSynTextViewsManager)
|
||||
public
|
||||
property TextBuffer;
|
||||
end;
|
||||
|
||||
{ TSynEditMarkListInternal }
|
||||
|
||||
TSynEditMarkListInternal = class(TSynEditMarkList)
|
||||
@ -2064,6 +2071,13 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TCustomSynEdit.DoTopViewChanged(Sender: TObject);
|
||||
begin
|
||||
FTheLinesView := TSynEditStrings(Sender);
|
||||
if FPaintArea <> nil then // maybe change order of creation
|
||||
FPaintArea.DisplayView := FTheLinesView.DisplayView;
|
||||
end;
|
||||
|
||||
constructor TCustomSynEdit.Create(AOwner: TComponent);
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
@ -2096,44 +2110,42 @@ begin
|
||||
FScreenCaretPainterClass{%H-} := TSynEditScreenCaretPainterSystem;
|
||||
{$endif}
|
||||
|
||||
// Create the lines/views
|
||||
FTrimmedLinesView := TSynEditStringTrimmingList.Create(fLines, fCaret);
|
||||
FTextViewsManager := TSynTextViewsManagerInternal.Create(FLines, @DoTopViewChanged);
|
||||
|
||||
FDoubleWidthChrLinesView := SynEditStringDoubleWidthChars.Create
|
||||
(FTrimmedLinesView);
|
||||
// Create the lines/views
|
||||
FTrimmedLinesView := TSynEditStringTrimmingList.Create(fCaret);
|
||||
FTextViewsManager.AddTextView(FTrimmedLinesView);
|
||||
|
||||
FDoubleWidthChrLinesView := SynEditStringDoubleWidthChars.Create();
|
||||
FTextViewsManager.AddTextView(FDoubleWidthChrLinesView);
|
||||
|
||||
{$IFDEF WithSynExperimentalCharWidth}
|
||||
//FSysCharWidthLinesView := TSynEditStringSystemWidthChars.Create(FDoubleWidthChrLinesView, Self.Canvas);
|
||||
FSysCharWidthLinesView := TSynEditStringSystemWidthChars.Create(FTrimmedLinesView, Self.Canvas);
|
||||
FSysCharWidthLinesView := TSynEditStringSystemWidthChars.Create(Self.Canvas);
|
||||
FTextViewsManager.AddTextView(FSysCharWidthLinesView);
|
||||
|
||||
FBidiChrLinesView := TSynEditStringBidiChars.Create(FSysCharWidthLinesView);
|
||||
FTabbedLinesView := TSynEditStringTabExpander.Create(FBidiChrLinesView);
|
||||
FBidiChrLinesView := TSynEditStringBidiChars.Create();
|
||||
FTextViewsManager.AddTextView(FBidiChrLinesView);
|
||||
|
||||
FTabbedLinesView := TSynEditStringTabExpander.Create();
|
||||
FTextViewsManager.AddTextView(FTabbedLinesView);
|
||||
{$ELSE}
|
||||
|
||||
{$IFnDEF WithOutSynBiDi}
|
||||
FBidiChrLinesView := TSynEditStringBidiChars.Create(FDoubleWidthChrLinesView);
|
||||
FBidiChrLinesView := TSynEditStringBidiChars.Create();
|
||||
FTextViewsManager.AddTextView(FBidiChrLinesView);
|
||||
{$ENDIF}
|
||||
|
||||
// ftab, currently has LengthOfLongestLine, therefore must be after DoubleWidthChar
|
||||
{$IFnDEF WithOutSynBiDi }
|
||||
FTabbedLinesView := TSynEditStringTabExpander.Create(FBidiChrLinesView);
|
||||
{$ELSE}
|
||||
FTabbedLinesView := TSynEditStringTabExpander.Create(FDoubleWidthChrLinesView);
|
||||
{$ENDIF}
|
||||
FTabbedLinesView := TSynEditStringTabExpander.Create();
|
||||
FTextViewsManager.AddTextView(FTabbedLinesView);
|
||||
|
||||
{$ENDIF} // WithSynExperimentalCharWidth
|
||||
|
||||
// Pointer to the First/Lowest View
|
||||
// TODO: this should be Folded...
|
||||
FTheLinesView := FTabbedLinesView;
|
||||
FTopLinesView := FTrimmedLinesView;
|
||||
|
||||
FFoldedLinesView := TSynEditFoldedView.Create(FTheLinesView, fCaret);
|
||||
FFoldedLinesView := TSynEditFoldedView.Create(fCaret);
|
||||
FFoldedLinesView.OnFoldChanged := @FoldChanged;
|
||||
FFoldedLinesView.OnLineInvalidate := @InvalidateGutterLines;
|
||||
FFoldedLinesView.DisplayView.NextView := FTheLinesView.DisplayView;
|
||||
|
||||
FDisplayView := FFoldedLinesView.DisplayView;
|
||||
FTextViewsManager.AddTextView(FFoldedLinesView);
|
||||
|
||||
// External Accessor
|
||||
FStrings := TSynEditLines.Create(TSynEditStringList(FLines), @MarkTextAsSaved);
|
||||
@ -2281,7 +2293,7 @@ begin
|
||||
FPaintArea.TextArea := FTextArea;
|
||||
FPaintArea.LeftGutterArea := FLeftGutterArea;
|
||||
FPaintArea.RightGutterArea := FRightGutterArea;
|
||||
FPaintArea.DisplayView := FDisplayView;
|
||||
FPaintArea.DisplayView := FTheLinesView.DisplayView;
|
||||
|
||||
Color := clWhite;
|
||||
Font.Assign(fFontDummy);
|
||||
@ -2595,19 +2607,10 @@ begin
|
||||
FreeAndNil(fFontDummy);
|
||||
DestroyMarkList; // before detach from FLines
|
||||
FreeAndNil(FWordBreaker);
|
||||
FreeAndNil(FFoldedLinesView); // has reference to caret
|
||||
FreeAndNil(FInternalBlockSelection);
|
||||
FreeAndNil(FBlockSelection);
|
||||
FreeAndNil(FStrings);
|
||||
FreeAndNil(FTabbedLinesView);
|
||||
FreeAndNil(FTrimmedLinesView); // has reference to caret
|
||||
{$IFnDEF WithOutSynBiDi}
|
||||
FreeAndNil(FBidiChrLinesView);
|
||||
{$ENDIF}
|
||||
{$IFDEF WithSynExperimentalCharWidth}
|
||||
FreeAndNil(FSysCharWidthLinesView);
|
||||
{$ENDIF}
|
||||
FreeAndNil(FDoubleWidthChrLinesView);
|
||||
FreeAndNil(FTextViewsManager);
|
||||
TSynEditStringList(FLines).DetachSynEdit(Self);
|
||||
if TSynEditStringList(FLines).AttachedSynEditCount = 0 then
|
||||
FreeAndNil(fLines);
|
||||
@ -5874,7 +5877,7 @@ begin
|
||||
|
||||
Flines := NewBuffer;
|
||||
TSynEditStringList(FLines).AttachSynEdit(Self);
|
||||
TSynEditStringsLinked(FTopLinesView).NextLines := FLines;
|
||||
TSynTextViewsManagerInternal(FTextViewsManager).TextBuffer := FLines;
|
||||
|
||||
// Todo: Todo Refactor all classes with events, so they an be told to re-attach
|
||||
NewBuffer.CopyHanlders(OldBuffer, self);
|
||||
@ -5883,7 +5886,6 @@ begin
|
||||
NewBuffer.CopyHanlders(OldBuffer, LView);
|
||||
LView := TSynEditStringsLinked(LView).NextLines;
|
||||
end;
|
||||
NewBuffer.CopyHanlders(OldBuffer, FFoldedLinesView);
|
||||
//NewBuffer.CopyHanlders(OldBuffer, FMarkList);
|
||||
NewBuffer.CopyHanlders(OldBuffer, FCaret);
|
||||
NewBuffer.CopyHanlders(OldBuffer, FInternalCaret);
|
||||
@ -6024,7 +6026,6 @@ begin
|
||||
TSynEditStringList(ALines).RemoveHanlders(LView);
|
||||
LView := TSynEditStringsLinked(LView).NextLines;
|
||||
end;
|
||||
TSynEditStringList(ALines).RemoveHanlders(FFoldedLinesView);
|
||||
TSynEditStringList(ALines).RemoveHanlders(FCaret);
|
||||
TSynEditStringList(ALines).RemoveHanlders(FInternalCaret);
|
||||
TSynEditStringList(ALines).RemoveHanlders(FBlockSelection);
|
||||
|
||||
@ -310,7 +310,7 @@ type
|
||||
protected
|
||||
property HighLighterWithLines: TSynCustomFoldHighlighter read GetHighLighterWithLines;
|
||||
public
|
||||
constructor Create(aTextView : TSynEditStrings; AFoldTree : TSynTextFoldAVLTree);
|
||||
constructor Create(AFoldTree : TSynTextFoldAVLTree);
|
||||
destructor Destroy; override;
|
||||
|
||||
// Info about Folds opening on ALineIdx
|
||||
@ -379,7 +379,6 @@ type
|
||||
fCaret: TSynEditCaret;
|
||||
FBlockSelection: TSynEditSelection;
|
||||
FFoldProvider: TSynEditFoldProvider;
|
||||
fLines : TSynEditStrings;
|
||||
fFoldTree : TSynTextFoldAVLTree; // Folds are stored 1-based (the 1st line is 1)
|
||||
FMarkupInfoFoldedCode: TSynSelectedColor;
|
||||
FMarkupInfoFoldedCodeLine: TSynSelectedColor;
|
||||
@ -411,6 +410,7 @@ type
|
||||
procedure SetLinesInWindow(const AValue : integer);
|
||||
procedure DoFoldChanged(AnIndex: Integer);
|
||||
protected
|
||||
procedure SetSynStrings(AValue: TSynEditStrings); override;
|
||||
function GetViewedLines(index : Integer) : String; override;
|
||||
function GetViewedCount: integer; override;
|
||||
function GetDisplayView: TLazSynDisplayView; override;
|
||||
@ -434,7 +434,7 @@ type
|
||||
// SkipFixFolding : Boolean = False);
|
||||
property FoldTree: TSynTextFoldAVLTree read fFoldTree;
|
||||
public
|
||||
constructor Create(aTextView : TSynEditStrings; ACaret: TSynEditCaret);
|
||||
constructor Create(ACaret: TSynEditCaret);
|
||||
destructor Destroy; override;
|
||||
|
||||
// Converting between Folded and Unfolded Lines/Indexes
|
||||
@ -2956,9 +2956,8 @@ begin
|
||||
FNestedFoldsList.Lines := FLines;
|
||||
end;
|
||||
|
||||
constructor TSynEditFoldProvider.Create(aTextView: TSynEditStrings; AFoldTree : TSynTextFoldAVLTree);
|
||||
constructor TSynEditFoldProvider.Create(AFoldTree: TSynTextFoldAVLTree);
|
||||
begin
|
||||
FLines := aTextView;
|
||||
FFoldTree := AFoldTree;
|
||||
end;
|
||||
|
||||
@ -3080,16 +3079,15 @@ end;
|
||||
|
||||
{ TSynEditFoldedView }
|
||||
|
||||
constructor TSynEditFoldedView.Create(aTextView : TSynEditStrings; ACaret: TSynEditCaret);
|
||||
constructor TSynEditFoldedView.Create(ACaret: TSynEditCaret);
|
||||
begin
|
||||
inherited Create(aTextView);
|
||||
inherited Create;
|
||||
fTopLine := 0;
|
||||
fLinesInWindow := -1;
|
||||
fLines := aTextView;
|
||||
fCaret := ACaret;
|
||||
fCaret.AddChangeHandler(@DoCaretChanged);
|
||||
fFoldTree := TSynTextFoldAVLTree.Create;
|
||||
FFoldProvider := TSynEditFoldProvider.Create(aTextView, fFoldTree);
|
||||
FFoldProvider := TSynEditFoldProvider.Create(fFoldTree);
|
||||
// TODO: if NextLineChanges, update FFoldProvider // DoSynStringsChanged
|
||||
FDisplayView := TLazSynDisplayFold.Create(Self);
|
||||
FFoldChangedHandlerList := TFoldChangedHandlerList.Create;
|
||||
@ -3108,17 +3106,11 @@ begin
|
||||
FMarkupInfoHiddenCodeLine.Background := clNone;
|
||||
FMarkupInfoHiddenCodeLine.Foreground := clNone;
|
||||
FMarkupInfoHiddenCodeLine.FrameColor := clNone;
|
||||
|
||||
fLines.AddChangeHandler(senrLineCount, @LineCountChanged);
|
||||
fLines.AddNotifyHandler(senrCleared, @LinesCleared);
|
||||
fLines.AddEditHandler(@LineEdited);
|
||||
end;
|
||||
|
||||
destructor TSynEditFoldedView.Destroy;
|
||||
begin
|
||||
fLines.RemoveChangeHandler(senrLineCount, @LineCountChanged);
|
||||
fLines.RemoveNotifyHandler(senrCleared, @LinesCleared);
|
||||
fLines.RemoveEditHandler(@LineEdited);
|
||||
NextLines := nil;
|
||||
fCaret.RemoveChangeHandler(@DoCaretChanged);
|
||||
FreeAndNil(FDisplayView);
|
||||
FreeAndNil(FFoldChangedHandlerList);
|
||||
@ -3228,7 +3220,7 @@ begin
|
||||
inc(LineOffset);
|
||||
end;
|
||||
end else begin
|
||||
boundary := fLines.Count;
|
||||
boundary := NextLines.Count;
|
||||
while LineOffset > 0 do begin
|
||||
if Result >= boundary then exit(boundary);
|
||||
inc(Result);
|
||||
@ -3273,7 +3265,7 @@ end;
|
||||
(* Count *)
|
||||
function TSynEditFoldedView.GetViewedCount : integer;
|
||||
begin
|
||||
Result := fLines.ViewedCount - fFoldTree.FindLastFold.FoldedBefore;
|
||||
Result := NextLines.ViewedCount - fFoldTree.FindLastFold.FoldedBefore;
|
||||
end;
|
||||
|
||||
function TSynEditFoldedView.GetDisplayView: TLazSynDisplayView;
|
||||
@ -3291,7 +3283,7 @@ function TSynEditFoldedView.GetHighLighter: TSynCustomHighlighter;
|
||||
begin
|
||||
Result := FFoldProvider.HighLighter;
|
||||
if assigned(Result) then
|
||||
Result.CurrentLines := fLines;
|
||||
Result.CurrentLines := NextLines;
|
||||
end;
|
||||
|
||||
(* Topline *)
|
||||
@ -3331,6 +3323,22 @@ begin
|
||||
FFoldChangedHandlerList.CallFoldChangedEvents(AnIndex);
|
||||
end;
|
||||
|
||||
procedure TSynEditFoldedView.SetSynStrings(AValue: TSynEditStrings);
|
||||
begin
|
||||
if NextLines <> nil then begin
|
||||
NextLines.RemoveChangeHandler(senrLineCount, @LineCountChanged);
|
||||
NextLines.RemoveNotifyHandler(senrCleared, @LinesCleared);
|
||||
NextLines.RemoveEditHandler(@LineEdited);
|
||||
end;
|
||||
inherited SetSynStrings(AValue);
|
||||
FFoldProvider.FLines := AValue;
|
||||
if NextLines <> nil then begin
|
||||
NextLines.AddChangeHandler(senrLineCount, @LineCountChanged);
|
||||
NextLines.AddNotifyHandler(senrCleared, @LinesCleared);
|
||||
NextLines.AddEditHandler(@LineEdited);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TSynEditFoldedView.DoBlockSelChanged(Sender: TObject);
|
||||
begin
|
||||
CalculateMaps;
|
||||
@ -3366,7 +3374,7 @@ begin
|
||||
tpos := tpos - node.MergedLineCount;
|
||||
end;
|
||||
{$IFDEF SynFoldDebug}debugln(['FOLD-- CalculateMaps fTopLine:=', fTopLine, ' tpos=',tpos]);{$ENDIF}
|
||||
cnt := fLines.Count;
|
||||
cnt := NextLines.Count;
|
||||
FirstChanged := -1;
|
||||
LastChanged := -1;
|
||||
for i := 0 to fLinesInWindow + 2 do begin
|
||||
@ -3414,8 +3422,8 @@ end;
|
||||
function TSynEditFoldedView.GetViewedLines(index : Integer) : String;
|
||||
begin
|
||||
if (index < -1) or (index > fLinesInWindow + 1) then
|
||||
exit(fLines.ViewedLines[ScreenLineToTextIndex(Index)]);
|
||||
Result := fLines.ViewedLines[fTextIndexList[index+1]];
|
||||
exit(NextLines.ViewedLines[ScreenLineToTextIndex(Index)]);
|
||||
Result := NextLines.ViewedLines[fTextIndexList[index+1]];
|
||||
end;
|
||||
|
||||
function TSynEditFoldedView.GetDisplayNumber(index : Integer) : Integer;
|
||||
@ -3560,7 +3568,7 @@ begin
|
||||
exit;
|
||||
|
||||
i := 0;
|
||||
while i < fLines.Count do begin
|
||||
while i < NextLines.Count do begin
|
||||
// Todo: Highlighter should return a list of types that can return default folded
|
||||
// Currently PascalHl Type 2 = Region
|
||||
c := hl.FoldBlockOpeningCount(i, 2);
|
||||
@ -3839,7 +3847,7 @@ begin
|
||||
if entry.Line > 0 then AStartCol := 0;
|
||||
|
||||
Line := AStartIndex + entry.Line;
|
||||
if Line >= FLines.Count then
|
||||
if Line >= NextLines.Count then
|
||||
continue;
|
||||
|
||||
ndinfo :=NdiHelper1.GotoOpenAtChar(Line, entry.LogX);
|
||||
@ -4051,7 +4059,7 @@ begin
|
||||
top := TopTextIndex;
|
||||
fFoldTree.Clear;
|
||||
i := 0;
|
||||
while i < fLines.Count do begin
|
||||
while i < NextLines.Count do begin
|
||||
if (hl.FoldBlockOpeningCount(i, t) > 0)
|
||||
and (hl.FoldBlockEndLevel(i, t) > StartLevel) then begin
|
||||
c := hl.FoldBlockOpeningCount(i) -1;
|
||||
@ -4272,7 +4280,7 @@ begin
|
||||
if (ACount < 0) and (AIndex < fNeedFixFrom) then inc(fNeedFixFrom, ACount);
|
||||
if (ACount > 0) and (AIndex < fNeedFixMinEnd) then inc(fNeedFixMinEnd, ACount);
|
||||
end;
|
||||
if fLines.IsInEditAction then exit;
|
||||
if NextLines.IsInEditAction then exit;
|
||||
if ACount<0
|
||||
then LinesDeletedAtTextIndex(AIndex+1, -ACount, 1, true)
|
||||
else LinesInsertedAtTextIndex(AIndex+1, ACount, 1, true);
|
||||
@ -4410,7 +4418,7 @@ begin
|
||||
end;
|
||||
Result.HNode := nd;
|
||||
Result.OpenCount := o;
|
||||
Result.Text := fLines[aStartIndex];
|
||||
Result.Text := NextLines[aStartIndex];
|
||||
if not(sfaInvalid in nd.FoldAction) then
|
||||
Result.Keyword := copy(Result.Text, 1 + nd.LogXStart, nd.LogXEnd-nd.LogXStart);
|
||||
Result.LineNum := aStartIndex + 1;
|
||||
@ -4474,7 +4482,7 @@ end;
|
||||
|
||||
function TSynEditFoldedView.GetPhysicalCharWidths(Index: Integer): TPhysicalCharWidths;
|
||||
begin
|
||||
Result := fLines.GetPhysicalCharWidths(InternViewToTextIndex(Index));
|
||||
Result := NextLines.GetPhysicalCharWidths(InternViewToTextIndex(Index));
|
||||
end;
|
||||
|
||||
function TSynEditFoldedView.CollapsedLineForFoldAtLine(ALine : Integer) : Integer;
|
||||
|
||||
@ -57,7 +57,7 @@ type
|
||||
procedure DoGetPhysicalCharWidths(Line: PChar; LineLen, Index: Integer; PWidths: PPhysicalCharWidth); override;
|
||||
{$endif}
|
||||
public
|
||||
constructor Create(ASynStringSource: TSynEditStrings; AHandleOwner: TCanvas);
|
||||
constructor Create(AHandleOwner: TCanvas);
|
||||
property HandleOwner: TCanvas read FHandleOwner;
|
||||
property CharWidth: Integer read FCharWidth write FCharWidth;
|
||||
property TextDrawer: TheTextDrawer read fTextDrawer write fTextDrawer;
|
||||
@ -72,10 +72,9 @@ var
|
||||
|
||||
{ TSynEditStringSystemWidthChars }
|
||||
|
||||
constructor TSynEditStringSystemWidthChars.Create(ASynStringSource: TSynEditStrings;
|
||||
AHandleOwner: TCanvas);
|
||||
constructor TSynEditStringSystemWidthChars.Create(AHandleOwner: TCanvas);
|
||||
begin
|
||||
inherited Create(ASynStringSource);
|
||||
inherited Create;
|
||||
FHandleOwner := AHandleOwner;
|
||||
end;
|
||||
|
||||
|
||||
@ -66,6 +66,7 @@ type
|
||||
function ExpandedString(Index: integer): string;
|
||||
function ExpandedStringLength(Index: integer): Integer;
|
||||
protected
|
||||
procedure SetSynStrings(AValue: TSynEditStrings); override;
|
||||
function GetViewChangeStamp: int64; override;
|
||||
function GetTabWidth : integer;
|
||||
procedure SetTabWidth(const AValue : integer);
|
||||
@ -73,7 +74,7 @@ type
|
||||
function GetLengthOfLongestLine: integer; override;
|
||||
procedure DoGetPhysicalCharWidths(Line: PChar; LineLen, Index: Integer; PWidths: PPhysicalCharWidth); override;
|
||||
public
|
||||
constructor Create(ASynStringSource: TSynEditStrings);
|
||||
constructor Create;
|
||||
destructor Destroy; override;
|
||||
|
||||
property LengthOfLongestLine: integer read GetLengthOfLongestLine;
|
||||
@ -134,34 +135,28 @@ end;
|
||||
|
||||
{ TSynEditStringTabExpander }
|
||||
|
||||
constructor TSynEditStringTabExpander.Create(ASynStringSource: TSynEditStrings);
|
||||
constructor TSynEditStringTabExpander.Create;
|
||||
begin
|
||||
FIndexOfLongestLine := -1;
|
||||
FFirstUnknownLongestLine := -1;
|
||||
FLastUnknownLongestLine := -1;
|
||||
inherited Create(ASynStringSource);
|
||||
TextBufferChanged(nil);
|
||||
inherited Create;
|
||||
TabWidth := 8;
|
||||
fSynStrings.AddChangeHandler(senrLineCount, @LineCountChanged);
|
||||
fSynStrings.AddChangeHandler(senrLineChange, @LineTextChanged);
|
||||
fSynStrings.AddNotifyHandler(senrTextBufferChanged, @TextBufferChanged);
|
||||
end;
|
||||
|
||||
destructor TSynEditStringTabExpander.Destroy;
|
||||
var
|
||||
Data: TSynEditStringTabData;
|
||||
begin
|
||||
Data := TSynEditStringTabData(fSynStrings.Ranges[Self]);
|
||||
Data := TSynEditStringTabData(NextLines.Ranges[Self]);
|
||||
if Assigned(Data) then begin
|
||||
Data.DecRefCount;
|
||||
if Data.RefCount = 0 then begin
|
||||
fSynStrings.Ranges[Self] := nil;
|
||||
NextLines.Ranges[Self] := nil;
|
||||
Data.Free;
|
||||
end;
|
||||
end;
|
||||
fSynStrings.RemoveChangeHandler(senrLineChange, @LineTextChanged);
|
||||
fSynStrings.RemoveChangeHandler(senrLineCount, @LineCountChanged);
|
||||
fSynStrings.RemoveNotifyHandler(senrTextBufferChanged, @TextBufferChanged);
|
||||
NextLines := nil;
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
@ -171,8 +166,6 @@ begin
|
||||
end;
|
||||
|
||||
procedure TSynEditStringTabExpander.SetTabWidth(const AValue: integer);
|
||||
var
|
||||
i: integer;
|
||||
begin
|
||||
if FTabWidth = AValue then exit;
|
||||
|
||||
@ -184,9 +177,6 @@ begin
|
||||
FIndexOfLongestLine := -1;
|
||||
FFirstUnknownLongestLine := -1;
|
||||
FLastUnknownLongestLine := -1;
|
||||
for i := 0 to Count - 1 do
|
||||
if not(FTabData[i] >= NO_TAB_IN_LINE_OFFSET) then
|
||||
FTabData[i] := LINE_LEN_UNKNOWN;
|
||||
end;
|
||||
|
||||
function TSynEditStringTabExpander.GetViewChangeStamp: int64;
|
||||
@ -200,6 +190,7 @@ end;
|
||||
procedure TSynEditStringTabExpander.TextBufferChanged(Sender: TObject);
|
||||
var
|
||||
Data: TSynEditStringTabData;
|
||||
i: integer;
|
||||
begin
|
||||
// Using self, instead as class, to register tab-width-data
|
||||
// other shared edits can have different tab-width
|
||||
@ -222,6 +213,9 @@ begin
|
||||
if FTabData = nil then begin
|
||||
FTabData := TSynEditStringTabData.Create;
|
||||
NextLines.Ranges[Self] := FTabData;
|
||||
for i := 0 to Count - 1 do
|
||||
if not(FTabData[i] >= NO_TAB_IN_LINE_OFFSET) then
|
||||
FTabData[i] := LINE_LEN_UNKNOWN;
|
||||
end
|
||||
else
|
||||
FTabData.IncRefCount;
|
||||
@ -278,7 +272,7 @@ var
|
||||
i, j, l: Integer;
|
||||
begin
|
||||
// this is only used by trimmer.lengthOfLongestLine / which is not called, if a tab module is present
|
||||
Line := fSynStrings[Index];
|
||||
Line := NextLines[Index];
|
||||
if (Line = '') or (not GetHasTabs(PChar(Line))) then begin
|
||||
Result := Line;
|
||||
// xxx wrong double width // none latin ...
|
||||
@ -312,7 +306,7 @@ var
|
||||
CharWidths: TPhysicalCharWidths;
|
||||
i: Integer;
|
||||
begin
|
||||
Line := fSynStrings[Index];
|
||||
Line := NextLines[Index];
|
||||
if (Line = '') then begin
|
||||
Result := 0;
|
||||
FTabData[Index] := Result + NO_TAB_IN_LINE_OFFSET;
|
||||
@ -331,11 +325,28 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TSynEditStringTabExpander.SetSynStrings(AValue: TSynEditStrings);
|
||||
begin
|
||||
if NextLines <> nil then begin
|
||||
NextLines.RemoveChangeHandler(senrLineChange, @LineTextChanged);
|
||||
NextLines.RemoveChangeHandler(senrLineCount, @LineCountChanged);
|
||||
NextLines.RemoveNotifyHandler(senrTextBufferChanged, @TextBufferChanged);
|
||||
end;
|
||||
inherited SetSynStrings(AValue);
|
||||
if NextLines <> nil then begin
|
||||
NextLines.AddChangeHandler(senrLineCount, @LineCountChanged);
|
||||
NextLines.AddChangeHandler(senrLineChange, @LineTextChanged);
|
||||
NextLines.AddNotifyHandler(senrTextBufferChanged, @TextBufferChanged);
|
||||
if FTabData = nil then
|
||||
TextBufferChanged(nil);
|
||||
end;
|
||||
end;
|
||||
|
||||
function TSynEditStringTabExpander.GetExpandedString(Index: integer): string;
|
||||
begin
|
||||
if (Index >= 0) and (Index < Count) then begin
|
||||
if FTabData[Index] >= NO_TAB_IN_LINE_OFFSET then
|
||||
Result := fSynStrings[Index]
|
||||
Result := NextLines[Index]
|
||||
else
|
||||
Result := ExpandedString(Index);
|
||||
end else
|
||||
@ -415,7 +426,7 @@ begin
|
||||
if j = LINE_LEN_UNKNOWN then begin
|
||||
// embedd a copy of ExpandedStringLength
|
||||
// allows one to re-use CharWidths
|
||||
Line := NextLines.GetPChar(i,LineLen); // fSynStrings[i];
|
||||
Line := NextLines.GetPChar(i,LineLen); // NextLines[i];
|
||||
j := 0;
|
||||
if (LineLen = 0) then begin
|
||||
FTabData[i] := j + NO_TAB_IN_LINE_OFFSET;
|
||||
|
||||
@ -110,7 +110,8 @@ type
|
||||
procedure UpdateLineText(LogY: Integer);
|
||||
procedure IncViewChangeStamp;
|
||||
protected
|
||||
function GetViewChangeStamp: int64; override;
|
||||
procedure SetSynStrings(AValue: TSynEditStrings); override;
|
||||
function GetViewChangeStamp: int64; override;
|
||||
function GetExpandedString(Index: integer): string; override;
|
||||
function GetLengthOfLongestLine: integer; override;
|
||||
function Get(Index: integer): string; override;
|
||||
@ -120,7 +121,7 @@ type
|
||||
function GetPCharSpaces(ALineIndex: Integer; out ALen: Integer): PChar; // experimental
|
||||
function GetDisplayView: TLazSynDisplayView; override;
|
||||
public
|
||||
constructor Create(ASynStringSource: TSynEditStrings; ACaret: TSynEditCaret);
|
||||
constructor Create(ACaret: TSynEditCaret);
|
||||
destructor Destroy; override;
|
||||
|
||||
function Add(const S: string): integer; override;
|
||||
@ -427,7 +428,7 @@ begin
|
||||
SendNotification(senrLineChange, TSynEditStringTrimmingList(Caller),
|
||||
FPosY - 1, 1);
|
||||
SendNotification(senrEditAction, TSynEditStringTrimmingList(Caller),
|
||||
FPosY, 0, length(fSynStrings[FPosY-1]) + FPosX, -FLen, '');
|
||||
FPosY, 0, length(NextLines[FPosY-1]) + FPosX, -FLen, '');
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
@ -457,7 +458,7 @@ begin
|
||||
SendNotification(senrLineChange, TSynEditStringTrimmingList(Caller),
|
||||
FPosY - 1, 1);
|
||||
SendNotification(senrEditAction, TSynEditStringTrimmingList(Caller),
|
||||
FPosY, 0, length(fSynStrings[FPosY-1]) + FPosX, length(FText), FText);
|
||||
FPosY, 0, length(NextLines[FPosY-1]) + FPosX, length(FText), FText);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
@ -488,7 +489,7 @@ begin
|
||||
SendNotification(senrLineChange, TSynEditStringTrimmingList(Caller),
|
||||
FPosY - 1, 1);
|
||||
SendNotification(senrEditAction, TSynEditStringTrimmingList(Caller),
|
||||
FPosY, 0, 1+length(fSynStrings[FPosY-1]), length(FText), FText);
|
||||
FPosY, 0, 1+length(NextLines[FPosY-1]), length(FText), FText);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
@ -503,14 +504,13 @@ end;
|
||||
|
||||
{ TSynEditStringTrimmingList }
|
||||
|
||||
constructor TSynEditStringTrimmingList.Create(ASynStringSource : TSynEditStrings; ACaret: TSynEditCaret);
|
||||
constructor TSynEditStringTrimmingList.Create(ACaret: TSynEditCaret);
|
||||
begin
|
||||
fCaret := ACaret;
|
||||
fCaret.AddChangeHandler(@DoCaretChanged);
|
||||
//fLockList := TSynEditTrimSpaceList.Create;
|
||||
fLockList.Clear;
|
||||
FDisplayView := TLazSynDisplayTrim.Create(Self);
|
||||
FDisplayView.NextView := ASynStringSource.DisplayView;
|
||||
fLineIndex:= -1;
|
||||
fSpaces := '';
|
||||
fEnabled:=false;
|
||||
@ -518,17 +518,12 @@ begin
|
||||
FIsTrimming := False;
|
||||
FLineEdited := False;
|
||||
FTrimType := settLeaveLine;
|
||||
Inherited Create(ASynStringSource);
|
||||
fSynStrings.AddChangeHandler(senrLineCount, @LineCountChanged);
|
||||
fSynStrings.AddChangeHandler(senrLineChange, @LinesChanged);
|
||||
fSynStrings.AddNotifyHandler(senrCleared, @ListCleared);
|
||||
Inherited Create;
|
||||
end;
|
||||
|
||||
destructor TSynEditStringTrimmingList.Destroy;
|
||||
begin
|
||||
fSynStrings.RemoveChangeHandler(senrLineCount, @LineCountChanged);
|
||||
fSynStrings.RemoveChangeHandler(senrLineChange, @LinesChanged);
|
||||
fSynStrings.RemoveNotifyHandler(senrCleared, @ListCleared);
|
||||
NextLines := nil;
|
||||
fCaret.RemoveChangeHandler(@DoCaretChanged);
|
||||
FreeAndNil(FDisplayView);
|
||||
//FreeAndNil(fLockList);
|
||||
@ -560,7 +555,7 @@ var
|
||||
begin
|
||||
if (not fEnabled) then exit;
|
||||
if (fLockCount > 0) or (length(fSpaces) = 0) or
|
||||
(fLineIndex < 0) or (fLineIndex >= fSynStrings.Count) or
|
||||
(fLineIndex < 0) or (fLineIndex >= NextLines.Count) or
|
||||
( (fLineIndex = ToIdx(TSynEditCaret(Sender).LinePos)) and
|
||||
( (FTrimType in [settLeaveLine]) or
|
||||
((FTrimType in [settEditLine]) and not FLineEdited) ))
|
||||
@ -586,10 +581,10 @@ begin
|
||||
TSynEditCaret(Sender).InvalidateBytePos; // tabs at EOL may now be spaces
|
||||
SendNotification(senrLineChange, self, fLineIndex, 1);
|
||||
SendNotification(senrEditAction, self, FLineIndex+1, 0,
|
||||
1+length(fSynStrings[FLineIndex]), -i, '');
|
||||
1+length(NextLines[FLineIndex]), -i, '');
|
||||
end else begin
|
||||
// same line, only right of caret
|
||||
s := fSynStrings[fLineIndex];
|
||||
s := NextLines[fLineIndex];
|
||||
i := TSynEditCaret(Sender).BytePos;
|
||||
if i <= length(s) + 1 then
|
||||
j := 0
|
||||
@ -602,7 +597,7 @@ begin
|
||||
MaybeAddUndoForget(FLineIndex+1, s);
|
||||
SendNotification(senrLineChange, self, fLineIndex, 1);
|
||||
SendNotification(senrEditAction, self, FLineIndex+1, 0,
|
||||
1+length(fSynStrings[FLineIndex]) + length(FSpaces), -i, '');
|
||||
1+length(NextLines[FLineIndex]) + length(FSpaces), -i, '');
|
||||
end;
|
||||
FIsTrimming := False;
|
||||
FLineEdited := False;
|
||||
@ -669,8 +664,8 @@ begin
|
||||
FLockList.Clear;
|
||||
FIsTrimming := True;
|
||||
FLineEdited := False;
|
||||
if fEnabled and (fLineIndex >= 0) and (fLineIndex < fSynStrings.Count) then
|
||||
fSynStrings[fLineIndex] := TrimLine(fSynStrings[fLineIndex], fLineIndex);
|
||||
if fEnabled and (fLineIndex >= 0) and (fLineIndex < NextLines.Count) then
|
||||
NextLines[fLineIndex] := TrimLine(NextLines[fLineIndex], fLineIndex);
|
||||
FIsTrimming := False;
|
||||
end;
|
||||
|
||||
@ -689,7 +684,7 @@ begin
|
||||
if (not fEnabled) then exit(s);
|
||||
{$IFDEF SynTrimDebug}debugln(['--- Trimmer -- TrimLine ', ' fLineIndex=', fLineIndex, ' fSpaces=',length(fSpaces), ' RealUndo=', RealUndo ]);{$ENDIF}
|
||||
if RealUndo then begin
|
||||
temp := fSynStrings.Strings[Index];
|
||||
temp := NextLines.Strings[Index];
|
||||
l := length(temp);
|
||||
i := LastNoneSpacePos(temp);
|
||||
// Add RealSpaceUndo
|
||||
@ -742,8 +737,8 @@ begin
|
||||
exit;
|
||||
end;
|
||||
if Index <> fLineIndex then exit('');
|
||||
if (fLineIndex < 0) or (fLineIndex >= fSynStrings.Count)
|
||||
or (fLineText <> fSynStrings[fLineIndex]) then begin
|
||||
if (fLineIndex < 0) or (fLineIndex >= NextLines.Count)
|
||||
or (fLineText <> NextLines[fLineIndex]) then begin
|
||||
if fSpaces <> '' then IncViewChangeStamp;
|
||||
fSpaces:='';
|
||||
fLineText:='';
|
||||
@ -781,8 +776,8 @@ begin
|
||||
if fSpaces <> fLockList.Entries[i].TrimmedSpaces then
|
||||
IncViewChangeStamp;
|
||||
fSpaces:= fLockList.Entries[i].TrimmedSpaces;
|
||||
if (fLineIndex >= 0) and (fLineIndex < fSynStrings.Count) then
|
||||
fLineText := fSynStrings[fLineIndex];
|
||||
if (fLineIndex >= 0) and (fLineIndex < NextLines.Count) then
|
||||
fLineText := NextLines[fLineIndex];
|
||||
fLockList.Delete(i);
|
||||
DoCaretChanged(fCaret);
|
||||
end
|
||||
@ -796,10 +791,10 @@ begin
|
||||
for i := 0 to fLockList.Count-1 do begin
|
||||
index := fLockList.Entries[i].LineIndex;
|
||||
slen := length(fLockList.Entries[i].TrimmedSpaces);
|
||||
if (slen > 0) and (index >= 0) and (index < fSynStrings.Count) then begin
|
||||
ltext := fSynStrings[index];
|
||||
if (slen > 0) and (index >= 0) and (index < NextLines.Count) then begin
|
||||
ltext := NextLines[index];
|
||||
// TODO: Avoid triggering the highlighter
|
||||
fSynStrings[index] := ltext; // trigger OnPutted, so the line gets repainted
|
||||
NextLines[index] := ltext; // trigger OnPutted, so the line gets repainted
|
||||
MaybeAddUndoForget(Index+1, fLockList.Entries[i].TrimmedSpaces);
|
||||
end;
|
||||
end;
|
||||
@ -823,14 +818,14 @@ end;
|
||||
// Lines
|
||||
function TSynEditStringTrimmingList.GetExpandedString(Index : integer) : string;
|
||||
begin
|
||||
Result:= fSynStrings.ExpandedStrings[Index] + Spaces(Index);
|
||||
Result:= NextLines.ExpandedStrings[Index] + Spaces(Index);
|
||||
end;
|
||||
|
||||
function TSynEditStringTrimmingList.GetLengthOfLongestLine : integer;
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
Result:= fSynStrings.LengthOfLongestLine;
|
||||
Result:= NextLines.LengthOfLongestLine;
|
||||
if (fLineIndex >= 0) and (fLineIndex < Count) then begin
|
||||
i:= length(ExpandedStrings[fLineIndex]);
|
||||
if (i > Result) then Result := i;
|
||||
@ -839,24 +834,24 @@ end;
|
||||
|
||||
function TSynEditStringTrimmingList.Get(Index : integer) : string;
|
||||
begin
|
||||
Result:= fSynStrings.Strings[Index] + Spaces(Index);
|
||||
Result:= NextLines.Strings[Index] + Spaces(Index);
|
||||
end;
|
||||
|
||||
function TSynEditStringTrimmingList.GetObject(Index : integer) : TObject;
|
||||
begin
|
||||
Result:= fSynStrings.Objects[Index];
|
||||
Result:= NextLines.Objects[Index];
|
||||
end;
|
||||
|
||||
procedure TSynEditStringTrimmingList.Put(Index : integer; const S : string);
|
||||
begin
|
||||
FLineEdited := True;
|
||||
fSynStrings.Strings[Index]:= TrimLine(S, Index, True);
|
||||
NextLines.Strings[Index]:= TrimLine(S, Index, True);
|
||||
end;
|
||||
|
||||
procedure TSynEditStringTrimmingList.PutObject(Index : integer; AObject : TObject);
|
||||
begin
|
||||
FLineEdited := True;
|
||||
fSynStrings.Objects[Index]:= AObject;
|
||||
NextLines.Objects[Index]:= AObject;
|
||||
end;
|
||||
|
||||
function TSynEditStringTrimmingList.Add(const S : string) : integer;
|
||||
@ -864,23 +859,23 @@ var
|
||||
c : Integer;
|
||||
begin
|
||||
FLineEdited := True;
|
||||
c := fSynStrings.Count;
|
||||
Result := fSynStrings.Add(TrimLine(S, c));
|
||||
c := NextLines.Count;
|
||||
Result := NextLines.Add(TrimLine(S, c));
|
||||
end;
|
||||
|
||||
procedure TSynEditStringTrimmingList.AddStrings(AStrings : TStrings);
|
||||
var
|
||||
i, c : Integer;
|
||||
begin
|
||||
c := fSynStrings.Count;
|
||||
c := NextLines.Count;
|
||||
for i := 0 to AStrings.Count-1 do
|
||||
AStrings[i] := TrimLine(AStrings[i], c + i);
|
||||
fSynStrings.AddStrings(AStrings);
|
||||
NextLines.AddStrings(AStrings);
|
||||
end;
|
||||
|
||||
procedure TSynEditStringTrimmingList.Clear;
|
||||
begin
|
||||
fSynStrings.Clear;
|
||||
NextLines.Clear;
|
||||
fLineIndex:=-1;
|
||||
end;
|
||||
|
||||
@ -888,7 +883,7 @@ procedure TSynEditStringTrimmingList.Delete(Index : integer);
|
||||
begin
|
||||
FLineEdited := True;
|
||||
TrimLine('', Index, True);
|
||||
fSynStrings.Delete(Index);
|
||||
NextLines.Delete(Index);
|
||||
end;
|
||||
|
||||
procedure TSynEditStringTrimmingList.DeleteLines(Index, NumLines : integer);
|
||||
@ -898,19 +893,19 @@ begin
|
||||
FLineEdited := True;
|
||||
for i := 0 to NumLines-1 do
|
||||
TrimLine('', Index+i, True);
|
||||
fSynStrings.DeleteLines(Index, NumLines);
|
||||
NextLines.DeleteLines(Index, NumLines);
|
||||
end;
|
||||
|
||||
procedure TSynEditStringTrimmingList.Insert(Index : integer; const S : string);
|
||||
begin
|
||||
FLineEdited := True;
|
||||
fSynStrings.Insert(Index, TrimLine(S, Index));
|
||||
NextLines.Insert(Index, TrimLine(S, Index));
|
||||
end;
|
||||
|
||||
procedure TSynEditStringTrimmingList.InsertLines(Index, NumLines : integer);
|
||||
begin
|
||||
FLineEdited := True;
|
||||
fSynStrings.InsertLines(Index, NumLines);
|
||||
NextLines.InsertLines(Index, NumLines);
|
||||
end;
|
||||
|
||||
procedure TSynEditStringTrimmingList.InsertStrings(Index : integer; NewStrings : TStrings);
|
||||
@ -920,7 +915,7 @@ begin
|
||||
FLineEdited := True;
|
||||
for i := 0 to NewStrings.Count-1 do
|
||||
NewStrings[i] := TrimLine(NewStrings[i], Index+i, True);
|
||||
fSynStrings.InsertStrings(Index, NewStrings);
|
||||
NextLines.InsertStrings(Index, NewStrings);
|
||||
end;
|
||||
|
||||
function TSynEditStringTrimmingList.GetPCharSpaces(ALineIndex: Integer; out
|
||||
@ -951,7 +946,7 @@ end;
|
||||
procedure TSynEditStringTrimmingList.Exchange(Index1, Index2 : integer);
|
||||
begin
|
||||
FLineEdited := True;
|
||||
fSynStrings.Exchange(Index1, Index2);
|
||||
NextLines.Exchange(Index1, Index2);
|
||||
if fLineIndex = Index1 then
|
||||
fLineIndex := Index2
|
||||
else if fLineIndex = Index2 then
|
||||
@ -969,7 +964,7 @@ begin
|
||||
s := Spaces(LogY - 1);
|
||||
StoreSpacesForLine(LogY - 1,
|
||||
copy(s,1, LogX - 1) + AText + copy(s, LogX, length(s)),
|
||||
fSynStrings.Strings[LogY - 1]);
|
||||
NextLines.Strings[LogY - 1]);
|
||||
CurUndoList.AddChange(TSynEditUndoTrimInsert.Create(LogX, LogY, Length(AText)));
|
||||
IncViewChangeStamp;
|
||||
end;
|
||||
@ -986,7 +981,7 @@ begin
|
||||
Result := copy(s, LogX, ByteLen);
|
||||
StoreSpacesForLine(LogY - 1,
|
||||
copy(s,1, LogX - 1) + copy(s, LogX + ByteLen, length(s)),
|
||||
fSynStrings.Strings[LogY - 1]);
|
||||
NextLines.Strings[LogY - 1]);
|
||||
if Result <> '' then
|
||||
CurUndoList.AddChange(TSynEditUndoTrimDelete.Create(LogX, LogY, Result));
|
||||
IncViewChangeStamp;
|
||||
@ -999,11 +994,11 @@ begin
|
||||
if Len <= 0 then
|
||||
exit;
|
||||
{$IFDEF SynTrimDebug}debugln(['--- Trimmer -- EditMoveToTrim()', ' fLineIndex=', fLineIndex, ' fSpaces=',length(fSpaces), ' Y=',LogY, ' len=',Len]);{$ENDIF}
|
||||
t := fSynStrings[LogY - 1];
|
||||
t := NextLines[LogY - 1];
|
||||
s := copy(t, 1 + length(t) - Len, Len) + Spaces(LogY - 1);
|
||||
t := copy(t, 1, length(t) - Len);
|
||||
StoreSpacesForLine(LogY - 1, s, t);
|
||||
fSynStrings[LogY - 1] := t;
|
||||
NextLines[LogY - 1] := t;
|
||||
CurUndoList.AddChange(TSynEditUndoTrimMoveTo.Create(LogY, Len));
|
||||
IncViewChangeStamp;
|
||||
end;
|
||||
@ -1016,10 +1011,10 @@ begin
|
||||
exit;
|
||||
{$IFDEF SynTrimDebug}debugln(['--- Trimmer -- EditMoveFromTrim()', ' fLineIndex=', fLineIndex, ' fSpaces=',length(fSpaces), ' Y=',LogY, ' len=',Len]);{$ENDIF}
|
||||
s := Spaces(LogY - 1);
|
||||
t := fSynStrings[LogY - 1] + copy(s, 1, Len);
|
||||
t := NextLines[LogY - 1] + copy(s, 1, Len);
|
||||
s := copy(s, 1 + Len, length(s));
|
||||
StoreSpacesForLine(LogY - 1, s, t);
|
||||
fSynStrings[LogY - 1] := t;
|
||||
NextLines[LogY - 1] := t;
|
||||
CurUndoList.AddChange(TSynEditUndoTrimMoveFrom.Create(LogY, Len));
|
||||
IncViewChangeStamp;
|
||||
end;
|
||||
@ -1027,7 +1022,7 @@ end;
|
||||
procedure TSynEditStringTrimmingList.UpdateLineText(LogY: Integer);
|
||||
begin
|
||||
if LogY - 1 = fLineIndex then
|
||||
fLineText := fSynStrings[LogY - 1];
|
||||
fLineText := NextLines[LogY - 1];
|
||||
end;
|
||||
|
||||
procedure TSynEditStringTrimmingList.IncViewChangeStamp;
|
||||
@ -1037,6 +1032,21 @@ begin
|
||||
{$POP}
|
||||
end;
|
||||
|
||||
procedure TSynEditStringTrimmingList.SetSynStrings(AValue: TSynEditStrings);
|
||||
begin
|
||||
if NextLines <> nil then begin
|
||||
NextLines.RemoveChangeHandler(senrLineCount, @LineCountChanged);
|
||||
NextLines.RemoveChangeHandler(senrLineChange, @LinesChanged);
|
||||
NextLines.RemoveNotifyHandler(senrCleared, @ListCleared);
|
||||
end;
|
||||
inherited SetSynStrings(AValue);
|
||||
if NextLines <> nil then begin
|
||||
NextLines.AddChangeHandler(senrLineCount, @LineCountChanged);
|
||||
NextLines.AddChangeHandler(senrLineChange, @LinesChanged);
|
||||
NextLines.AddNotifyHandler(senrCleared, @ListCleared);
|
||||
end;
|
||||
end;
|
||||
|
||||
function TSynEditStringTrimmingList.GetViewChangeStamp: int64;
|
||||
begin
|
||||
Result := inherited GetViewChangeStamp;
|
||||
@ -1053,22 +1063,22 @@ var
|
||||
SaveText: String;
|
||||
begin
|
||||
if (not fEnabled) then begin
|
||||
fSynStrings.EditInsert(LogX, LogY, AText);
|
||||
NextLines.EditInsert(LogX, LogY, AText);
|
||||
exit;
|
||||
end;
|
||||
|
||||
t := fSynStrings[LogY - 1];
|
||||
t := NextLines[LogY - 1];
|
||||
Len := length(t);
|
||||
if ( (LogX <= Len) and not(t[Len] in [#9, #32]) ) or
|
||||
( AText = '') or
|
||||
( (LogX <= Len+1) and not(AText[Length(AText)] in [#9, #32]) )
|
||||
then begin
|
||||
fSynStrings.EditInsert(LogX, LogY, AText);
|
||||
NextLines.EditInsert(LogX, LogY, AText);
|
||||
exit;
|
||||
end;
|
||||
|
||||
IncIsInEditAction;
|
||||
if Count = 0 then fSynStrings.Add('');
|
||||
if Count = 0 then NextLines.Add('');
|
||||
FlushNotificationCache;
|
||||
IgnoreSendNotification(senrEditAction, True);
|
||||
SaveText := AText;
|
||||
@ -1129,14 +1139,14 @@ var
|
||||
begin
|
||||
Result := '';
|
||||
if (not fEnabled) or (ByteLen <= 0) then begin
|
||||
fSynStrings.EditDelete(LogX, LogY, ByteLen);
|
||||
NextLines.EditDelete(LogX, LogY, ByteLen);
|
||||
exit;
|
||||
end;
|
||||
|
||||
t := fSynStrings[LogY - 1];
|
||||
t := NextLines[LogY - 1];
|
||||
Len := length(t);
|
||||
if (LogX + ByteLen <= Len) and not(t[Len] in [#9, #32]) then begin
|
||||
fSynStrings.EditDelete(LogX, LogY, ByteLen);
|
||||
NextLines.EditDelete(LogX, LogY, ByteLen);
|
||||
exit;
|
||||
end;
|
||||
|
||||
@ -1162,7 +1172,7 @@ begin
|
||||
UpdateLineText(LogY);
|
||||
|
||||
// Trim any existing (committed/real) spaces
|
||||
t := fSynStrings[LogY - 1];
|
||||
t := NextLines[LogY - 1];
|
||||
EditMoveToTrim(LogY, length(t) - LastNoneSpacePos(t));
|
||||
|
||||
IgnoreSendNotification(senrEditAction, False);
|
||||
@ -1191,7 +1201,7 @@ begin
|
||||
exit;
|
||||
end;
|
||||
|
||||
t := fSynStrings[LogY - 1];
|
||||
t := NextLines[LogY - 1];
|
||||
Len := length(t);
|
||||
if ( (LogX + ByteLen <= Len) and not(t[Len] in [#9, #32]) ) or
|
||||
( AText = '') or
|
||||
@ -1226,12 +1236,12 @@ begin
|
||||
end;
|
||||
|
||||
//// Trim any existing (committed/real) spaces
|
||||
//t := fSynStrings[LogY - 1];
|
||||
//t := NextLines[LogY - 1];
|
||||
//EditMoveToTrim(LogY, length(t) - LastNoneSpacePos(t));
|
||||
|
||||
// Insert
|
||||
|
||||
t := fSynStrings[LogY - 1];
|
||||
t := NextLines[LogY - 1];
|
||||
Len := Length(t) + Length(Spaces(LogY-1));
|
||||
if LogX - 1 > Len then begin
|
||||
AText := StringOfChar(' ', LogX - 1 - Len) + AText;
|
||||
@ -1286,7 +1296,7 @@ var
|
||||
s, t: string;
|
||||
begin
|
||||
if (not fEnabled) then begin
|
||||
fSynStrings.EditLineBreak(LogX, LogY);
|
||||
NextLines.EditLineBreak(LogX, LogY);
|
||||
exit;
|
||||
end;
|
||||
|
||||
@ -1294,24 +1304,24 @@ begin
|
||||
FlushNotificationCache;
|
||||
IgnoreSendNotification(senrEditAction, True);
|
||||
s := Spaces(LogY - 1);
|
||||
t := fSynStrings[LogY - 1];
|
||||
t := NextLines[LogY - 1];
|
||||
if LogX > length(t) then begin
|
||||
fSynStrings.EditLineBreak(1 + length(t), LogY);
|
||||
NextLines.EditLineBreak(1 + length(t), LogY);
|
||||
FlushNotificationCache; // senrEditaction is ignored, so we need to flush by hand
|
||||
if s <> '' then
|
||||
s := EditDeleteTrim(LogX - length(t), LogY, length(s) - (LogX - 1 - length(t)));
|
||||
end
|
||||
else begin
|
||||
s := EditDeleteTrim(1, LogY, length(s));
|
||||
fSynStrings.EditLineBreak(LogX, LogY);
|
||||
NextLines.EditLineBreak(LogX, LogY);
|
||||
FlushNotificationCache; // senrEditaction is ignored, so we need to flush by hand
|
||||
end;
|
||||
UpdateLineText(LogY + 1);
|
||||
EditInsertTrim(1, LogY + 1, s);
|
||||
// Trim any existing (committed/real) spaces
|
||||
s := fSynStrings[LogY - 1];
|
||||
s := NextLines[LogY - 1];
|
||||
EditMoveToTrim(LogY, length(s) - LastNoneSpacePos(s));
|
||||
s := fSynStrings[LogY];
|
||||
s := NextLines[LogY];
|
||||
EditMoveToTrim(LogY + 1, length(s) - LastNoneSpacePos(s));
|
||||
IgnoreSendNotification(senrEditAction, False);
|
||||
SendNotification(senrEditAction, self, LogY, 1, LogX, 0, '');
|
||||
@ -1324,7 +1334,7 @@ var
|
||||
s: String;
|
||||
begin
|
||||
if (not fEnabled) then begin
|
||||
fSynStrings.EditLineJoin(LogY, FillText);
|
||||
NextLines.EditLineJoin(LogY, FillText);
|
||||
exit;
|
||||
end;
|
||||
|
||||
@ -1334,13 +1344,13 @@ begin
|
||||
|
||||
s := EditDeleteTrim(1, LogY + 1, length(Spaces(LogY))); // next line
|
||||
//Todo: if FillText isSpacesOnly AND NextLineIsSpacesOnly => add direct to trailing
|
||||
fSynStrings.EditLineJoin(LogY, FillText);
|
||||
NextLines.EditLineJoin(LogY, FillText);
|
||||
FlushNotificationCache; // senrEditaction is ignored, so we need to flush by hand
|
||||
UpdateLineText(LogY);
|
||||
EditInsertTrim(1, LogY, s);
|
||||
|
||||
// Trim any existing (committed/real) spaces
|
||||
s := fSynStrings[LogY - 1];
|
||||
s := NextLines[LogY - 1];
|
||||
EditMoveToTrim(LogY, length(s) - LastNoneSpacePos(s));
|
||||
DecIsInEditAction;
|
||||
end;
|
||||
@ -1352,8 +1362,8 @@ var
|
||||
begin
|
||||
IncIsInEditAction;
|
||||
FlushNotificationCache;
|
||||
fSynStrings.EditLinesInsert(LogY, ACount, AText);
|
||||
s := fSynStrings[LogY - 1];
|
||||
NextLines.EditLinesInsert(LogY, ACount, AText);
|
||||
s := NextLines[LogY - 1];
|
||||
EditMoveToTrim(LogY, length(s) - LastNoneSpacePos(s));
|
||||
DecIsInEditAction;
|
||||
end;
|
||||
@ -1366,7 +1376,7 @@ begin
|
||||
FlushNotificationCache;
|
||||
for i := LogY to LogY + ACount - 1 do
|
||||
EditMoveFromTrim(i, length(Spaces(i - 1)));
|
||||
fSynStrings.EditLinesDelete(LogY, ACount);
|
||||
NextLines.EditLinesDelete(LogY, ACount);
|
||||
DecIsInEditAction;
|
||||
end;
|
||||
|
||||
|
||||
@ -124,6 +124,7 @@ type
|
||||
procedure SetHighlighter(AValue: TSynCustomHighlighter); override;
|
||||
protected
|
||||
procedure DoPaint(ACanvas: TCanvas; AClip: TRect); override;
|
||||
procedure DoDisplayViewChanged; override;
|
||||
procedure BoundsChanged; override;
|
||||
public
|
||||
constructor Create(AOwner: TWinControl; AnOriginalManager: TLazSynSurfaceManager);
|
||||
@ -1352,6 +1353,11 @@ begin
|
||||
FExtraManager.Paint(ACanvas, AClip);
|
||||
end;
|
||||
|
||||
procedure TSourceLazSynSurfaceManager.DoDisplayViewChanged;
|
||||
begin
|
||||
FOriginalManager.DisplayView := DisplayView;
|
||||
end;
|
||||
|
||||
procedure TSourceLazSynSurfaceManager.BoundsChanged;
|
||||
var
|
||||
t: Integer;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user