SynEdit, Refactor: Separated the interface to Lines, from the TextBuffer implementation

git-svn-id: trunk@18846 -
This commit is contained in:
martin 2009-02-28 18:13:43 +00:00
parent 83fb21fe1b
commit b183a0ba51
12 changed files with 107 additions and 372 deletions

View File

@ -5,7 +5,7 @@ unit SynBeautifier;
interface
uses
Classes, SysUtils, SynEditMiscClasses;
Classes, SysUtils, SynEditMiscClasses, SynEditTextBase;
type
{ TSynCustomBeautifier }
@ -15,14 +15,16 @@ type
function CanUnindent(const Editor: TSynEditBase; const Line: string;
const PhysCaretX: Integer): Boolean; virtual; abstract;
function UnIndentLine(const Editor: TSynEditBase; const Line: string;
const PhysCaret: TPoint; out DelChars, InsChars: String;
const Lines: TSynEditStrings; const PhysCaret: TPoint;
out DelChars, InsChars: String;
out CaretNewX: Integer): String; virtual; abstract; // Todo InsChar are not supprted for undo
function IndentLine(const Editor: TSynEditBase; Line: string;
const PhysCaret: TPoint; out DelChars, InsChars: String;
out CaretNewX: Integer;
const Lines: TSynEditStrings; const PhysCaret: TPoint;
out DelChars, InsChars: String; out CaretNewX: Integer;
RemoveCurrentIndent: Boolean = False): String;
virtual; abstract; // Todo DelChar are not supprted for undo
function GetIndentForLine(Editor: TSynEditBase; const Line: string;
const Lines: TSynEditStrings;
const PhysCaret: TPoint): Integer; virtual; abstract;
end;
@ -39,13 +41,15 @@ type
function CanUnindent(const Editor: TSynEditBase; const Line: string;
const PhysCaretX: Integer): Boolean; override;
function UnIndentLine(const Editor: TSynEditBase; const Line: string;
const PhysCaret: TPoint; out DelChars, InsChars: String;
const Lines: TSynEditStrings; const PhysCaret: TPoint;
out DelChars, InsChars: String;
out CaretNewX: Integer): String; override; // Todo InsChar are not supprted for undo
function IndentLine(const Editor: TSynEditBase; Line: string;
const PhysCaret: TPoint; out DelChars, InsChars: String;
out CaretNewX: Integer;
const Lines: TSynEditStrings; const PhysCaret: TPoint;
out DelChars, InsChars: String; out CaretNewX: Integer;
RemoveCurrentIndent: Boolean = False): String; override; // Todo DelChar are not supprted for undo
function GetIndentForLine(Editor: TSynEditBase; const Line: string;
const Lines: TSynEditStrings;
const PhysCaret: TPoint): Integer; override;
published
property IndentType: TSynBeautifierIndentType read FIndentType write FIndentType;
@ -73,13 +77,16 @@ begin
Result := 0;
end;
function TSynBeautifier.CanUnindent(const Editor: TSynEditBase; const Line: string; const PhysCaretX: Integer): Boolean;
function TSynBeautifier.CanUnindent(const Editor: TSynEditBase;
const Line: string; const PhysCaretX: Integer): Boolean;
begin
Result := (LeftSpaces(Editor, Line, True) = PhysCaretX - 1);
end;
function TSynBeautifier.UnIndentLine(const Editor: TSynEditBase; const Line: string; const PhysCaret: TPoint; out DelChars, InsChars: String; out
CaretNewX: Integer): String;
function TSynBeautifier.UnIndentLine(const Editor: TSynEditBase;
// XXXXX viewed
const Line: string; const Lines: TSynEditStrings; const PhysCaret: TPoint;
out DelChars, InsChars: String; out CaretNewX: Integer): String;
var
SpaceCount1, SpaceCount2: Integer;
BackCounter, LogSpacePos: Integer;
@ -90,7 +97,7 @@ begin
if (SpaceCount1 > 0) then begin
BackCounter := PhysCaret.Y - 2;
while BackCounter >= 0 do begin
SpaceCount2 := LeftSpaces(Editor, Editor.RealLines[BackCounter], true);
SpaceCount2 := LeftSpaces(Editor, Lines[BackCounter], true);
if SpaceCount2 < SpaceCount1 then
break;
Dec(BackCounter);
@ -107,8 +114,10 @@ begin
Result :=copy(Line, 1, LogSpacePos-1) + copy(Line, LogCaret.X, MaxInt);
end;
function TSynBeautifier.IndentLine(const Editor: TSynEditBase; Line: string; const PhysCaret: TPoint; out DelChars, InsChars: String; out
CaretNewX: Integer; RemoveCurrentIndent: Boolean): String;
function TSynBeautifier.IndentLine(const Editor: TSynEditBase; Line: string;
// XXXXX viewed
const Lines: TSynEditStrings; const PhysCaret: TPoint; out DelChars,
InsChars: String; out CaretNewX: Integer; RemoveCurrentIndent: Boolean): String;
var
SpaceCount1, SpaceCount2: Integer;
BackCounter: Integer;
@ -126,7 +135,7 @@ begin
if BackCounter > 0 then
repeat
Dec(BackCounter);
Temp := Editor.RealLines[BackCounter];
Temp := Lines[BackCounter];
SpaceCount2 := LeftSpaces(Editor, Temp, True);
until (BackCounter = 0) or (Temp <> '');
@ -146,11 +155,12 @@ begin
CaretNewX := TSynEdit(Editor).LogicalToPhysicalCol(Result, PhysCaret.y - 1, SpaceCount2+1);
end;
function TSynBeautifier.GetIndentForLine(Editor: TSynEditBase; const Line: string; const PhysCaret: TPoint): Integer;
function TSynBeautifier.GetIndentForLine(Editor: TSynEditBase;
const Line: string; const Lines: TSynEditStrings; const PhysCaret: TPoint): Integer;
var
s1, s2: string;
begin
IndentLine(Editor, Line, PhysCaret, s1, s2, Result, False);
IndentLine(Editor, Line, Lines, PhysCaret, s1, s2, Result, False);
end;
end.

View File

@ -45,7 +45,7 @@ interface
uses
Classes, SysUtils, LCLProc, SynEdit, SynBeautifier, SynEditTextBuffer,
SynEditHighlighter, SynHighlighterPas;
SynEditHighlighter, SynHighlighterPas, SynEditTextBase;
type
@ -54,18 +54,19 @@ type
TSynBeautifierPas = class(TSynBeautifier)
public
function TokenKindIsComment(Kind: integer): boolean;
function InComment(Editor: TCustomSynEdit; XY: TPoint): boolean;
procedure ReadPriorToken(Editor: TCustomSynEdit; var Y, StartX, EndX: integer);
function InComment(Editor: TCustomSynEdit; Lines: TSynEditStrings;
XY: TPoint): boolean;
procedure ReadPriorToken(Editor: TCustomSynEdit; Lines: TSynEditStrings;
var Y, StartX, EndX: integer);
end;
implementation
{ TSynBeautifierPas }
procedure TSynBeautifierPas.ReadPriorToken(Editor: TCustomSynEdit; var Y,
StartX, EndX: integer);
procedure TSynBeautifierPas.ReadPriorToken(Editor: TCustomSynEdit;
Lines: TSynEditStrings; var Y, StartX, EndX: integer);
var
Lines: TSynEditStringList;
TokenStart: Integer;
Line: string;
Highlighter: TSynCustomHighlighter;
@ -77,7 +78,6 @@ begin
exit;
end;
Lines:=TSynEditStringList(Editor.Lines);
if Y>Lines.Count then begin
// cursor after end of code
// => move to end of last line
@ -120,11 +120,10 @@ begin
Result:=(ord(tkComment)=Kind) or (ord(tkDirective)=Kind);
end;
function TSynBeautifierPas.InComment(Editor: TCustomSynEdit; XY: TPoint
): boolean;
function TSynBeautifierPas.InComment(Editor: TCustomSynEdit;
Lines: TSynEditStrings; XY: TPoint): boolean;
var
Highlighter: TSynPasSyn;
Lines: TSynEditStringList;
Line: string;
Start: Integer;
Token: String;
@ -137,7 +136,6 @@ begin
exit(false);
end;
Lines:=TSynEditStringList(Editor.Lines);
if Lines.Count=0 then begin
DebugLn(['TSynBeautifierPas.InComment Lines empty']);
exit(false); // no code

View File

@ -84,6 +84,7 @@ uses
SynGutterLineNumber, SynGutterMarks,
{$ENDIF}
SynEditMiscClasses, SynEditTextBuffer, SynEditHighlighter, SynTextDrawer,
SynEditLines,
LResources;
const
@ -355,8 +356,9 @@ type
FTrimmedLinesView: TSynEditStringTrimmingList;
FDoubleWidthChrLinesView: SynEditStringDoubleWidthChars;
FTabbedLinesView: TSynEditStringTabExpander;
FTheLinesView: TStrings;
fLines: TStrings; // The real (un-mapped) line-buffer
FTheLinesView: TSynEditStrings;
FLines: TSynEditStrings; // The real (un-mapped) line-buffer
FStrings: TStrings; // External TStrings based interface to the Textbuffer
fLinesInWindow: Integer;// MG: fully visible lines in window
fLeftChar: Integer; // first visible screen column
fMaxLeftChar: Integer; // 1024
@ -449,6 +451,7 @@ type
function GetCanUndo: Boolean;
function GetCaretXY: TPoint;
function GetFoldedCodeColor: TSynSelectedColor;
function GetLines: TStrings; override;
function GetMarkup(Index: integer): TSynEditMarkup;
function GetMarkupByClass(Index: TSynEditMarkupClass): TSynEditMarkup;
{$IFDEF SYN_LAZARUS}
@ -582,10 +585,9 @@ type
procedure RealSetText(const Value: TCaption); override;
procedure IncreaseChangeStamp;
{$ENDIF}
procedure SetRealLines(const AValue : TStrings); override;
function GetTheLinesView: TStrings; override;
function GetLines: TStrings; override;
procedure SetLines(Value: TStrings); override;
function GetViewedTextBuffer: TSynEditStrings; override;
function GetTextBuffer: TSynEditStrings; override;
procedure SetLines(Value: TStrings); override;
procedure DecPaintLock;
procedure DestroyWnd; override;
procedure DragOver(Source: TObject; X, Y: Integer;
@ -1376,25 +1378,24 @@ begin
FInternalCaret.MaxLeftChar := @FMaxLeftChar;
// Create the lines/views
FTrimmedLinesView := TSynEditStringTrimmingList.Create
(TSynEditStrings(fLines), fCaret);
FTrimmedLinesView := TSynEditStringTrimmingList.Create(fLines, fCaret);
FDoubleWidthChrLinesView := SynEditStringDoubleWidthChars.Create
(TSynEditStrings(FTrimmedLinesView));
(FTrimmedLinesView);
FTabbedLinesView := TSynEditStringTabExpander.Create
(TSynEditStrings(FDoubleWidthChrLinesView));
FTabbedLinesView := TSynEditStringTabExpander.Create(FDoubleWidthChrLinesView);
FFoldedLinesView := TSynEditFoldedView.Create
(TSynEditStrings(FTabbedLinesView), fCaret);
FFoldedLinesView := TSynEditFoldedView.Create(FTabbedLinesView, fCaret);
FFoldedLinesView.OnFoldChanged := {$IFDEF FPC}@{$ENDIF}FoldChanged;
// Pointer to the First/Lowest View
// TODO: this should be Folded...
FTheLinesView := FTabbedLinesView;
// External Accessor
FStrings := TSynEditLines.Create(FLines, {$IFDEF FPC}@{$ENDIF}MarkTextAsSaved);
FCaret.Lines := TSynEditStrings(FTheLinesView);
FInternalCaret.Lines := TSynEditStrings(FTheLinesView);
FCaret.Lines := FTheLinesView;
FInternalCaret.Lines := FTheLinesView;
TSynEditStringList(fLines).AddChangeHandler(senrLineCount,
{$IFDEF FPC}@{$ENDIF}LineCountChanged);
@ -1414,7 +1415,7 @@ begin
FTrimmedLinesView.UndoList := fUndoList;
FBlockSelection := TSynEditSelection.Create(TSynEditStrings(FTheLinesView));
FBlockSelection := TSynEditSelection.Create(FTheLinesView);
FBlockSelection.MaxLeftChar := @FMaxLeftChar;
FBlockSelection.Caret := FCaret;
FBlockSelection.UndoList := fUndoList;
@ -1467,7 +1468,7 @@ begin
fMarkupManager.AddMarkUp(fMarkupBracket);
fMarkupManager.AddMarkUp(fMarkupWordGroup);
fMarkupManager.AddMarkUp(fMarkupSelection);
fMarkupManager.Lines := TSynEditStrings(FTheLinesView);
fMarkupManager.Lines := FTheLinesView;
fMarkupManager.InvalidateLinesMethod := @InvalidateLines;
Color := clWhite;
@ -1649,6 +1650,7 @@ begin
fTextDrawer.Free;
fFontDummy.Free;
fBlockSelection.Free;
FStrings.Free;
FTabbedLinesView.Free;
FTrimmedLinesView.Free;
FDoubleWidthChrLinesView.Free;
@ -1671,6 +1673,7 @@ begin
FreeAndNil(fFontDummy);
FreeAndNil(FFoldedLinesView);
FreeAndNil(fBlockSelection);
FreeAndNil(FStrings);
FreeAndNil(FTabbedLinesView);
FreeAndNil(FTrimmedLinesView);
FreeAndNil(FDoubleWidthChrLinesView);
@ -1715,7 +1718,7 @@ begin
SizeOrFontChanged(TRUE);
end;
function TCustomSynEdit.GetLines: TStrings;
function TCustomSynEdit.GetTextBuffer: TSynEditStrings;
begin
Result := FLines;
end;
@ -1788,7 +1791,7 @@ begin
Result := FTrimmedLinesView.TrimType;
end;
function TCustomSynEdit.GetTheLinesView: TStrings;
function TCustomSynEdit.GetViewedTextBuffer: TSynEditStrings;
begin
Result := FTheLinesView;
end;
@ -1804,12 +1807,6 @@ begin
fGutter.OnGutterClick := AValue;
end;
procedure TCustomSynEdit.SetRealLines(const AValue : TStrings);
begin
if HandleAllocated then
FTheLinesView.Assign(AValue);
end;
procedure TCustomSynEdit.SetUseIncrementalColor(const AValue : Boolean);
begin
fMarkupSelection.UseIncrementalColor:=AValue;
@ -3590,6 +3587,11 @@ begin
Result := FFoldedLinesView.MarkupInfoFoldedCode;
end;
function TCustomSynEdit.GetLines: TStrings;
begin
Result := FStrings;
end;
procedure TCustomSynEdit.SetCaretXY(Value: TPoint);
// physical position (screen)
begin
@ -3621,7 +3623,7 @@ begin
if eoScrollPastEol in Options then
MaxVal := fMaxLeftChar
else
MaxVal := TSynEditStrings(FTheLinesView).LengthOfLongestLine;
MaxVal := FTheLinesView.LengthOfLongestLine;
Value := Min(Value, MaxVal - fCharsInWindow + 1);
{end} //mh 2000-10-19
Value := Max(Value, 1);
@ -3637,7 +3639,7 @@ end;
procedure TCustomSynEdit.SetLines(Value: TStrings);
begin
if HandleAllocated then
FLines.Assign(Value);
FStrings.Assign(Value);
end;
procedure TCustomSynEdit.SetLineText(Value: string);
@ -3909,17 +3911,10 @@ begin
ScrollInfo.nMin := 1;
ScrollInfo.nTrackPos := 0;
if fScrollBars in [ssBoth, ssHorizontal] then begin
{begin} //mh 2000-10-19
// ScrollInfo.nMax := fMaxLeftChar;
if eoScrollPastEol in Options then
ScrollInfo.nMax := fMaxLeftChar
else
{$IFDEF SYN_LAZARUS}
ScrollInfo.nMax := TSynEditStrings(FTheLinesView).LengthOfLongestLine;
{$ELSE}
ScrollInfo.nMax := TSynEditStringList(Lines).LengthOfLongestLine;
{$ENDIF}
{end} //mh 2000-10-19
ScrollInfo.nMax := FTheLinesView.LengthOfLongestLine;
ScrollInfo.nPage := CharsInWindow;
ScrollInfo.nPos := LeftChar;
{$IFDEF SYN_LAZARUS}
@ -4234,10 +4229,10 @@ begin
end;
FixFStart := Index;
if Result > 0 then
fHighlighter.SetRange(TSynEditStrings(FTheLinesView).Ranges[Result])
fHighlighter.SetRange(FTheLinesView.Ranges[Result])
else begin
fHighlighter.ReSetRange;
TSynEditStrings(FTheLinesView).Ranges[0] := fHighlighter.GetRange;
FTheLinesView.Ranges[0] := fHighlighter.GetRange;
end;
if Index >= FTheLinesView.Count - 1 then begin
FFoldedLinesView.FixFoldingAtTextIndex(Index);
@ -4251,18 +4246,18 @@ begin
fHighlighter.NextToEol;
LastLineDiffers := True;
SkipPrev := True;
while (fHighlighter.GetRange <> TSynEditStrings(FTheLinesView).Ranges[Result])
while (fHighlighter.GetRange <> FTheLinesView.Ranges[Result])
or (fHighlighter.LastLineCodeFoldLevelFix <> 0)
or (FFoldedLinesView.FoldMinLevel[Result-1] <> fHighlighter.MinimumCodeFoldBlockLevel)
or (FFoldedLinesView.FoldEndLevel[Result-1] <> fHighlighter.CurrentCodeFoldBlockLevel)
or LastLineDiffers or (Result<=AtLeastTilIndex+1)
do begin
//debugln(['TSynCustomHighlighter.ScanFrom WHILE Y=',Result,' Level=',fHighlighter.CurrentCodeFoldBlockLevel,' ScannedLine="',Lines[Result-1],'"']);
LastLineDiffers := (fHighlighter.GetRange <> TSynEditStrings(FTheLinesView).Ranges[Result])
LastLineDiffers := (fHighlighter.GetRange <> FTheLinesView.Ranges[Result])
or (fHighlighter.LastLineCodeFoldLevelFix <> 0)
or (FFoldedLinesView.FoldMinLevel[Result-1] <> fHighlighter.MinimumCodeFoldBlockLevel)
or (FFoldedLinesView.FoldEndLevel[Result-1] <> fHighlighter.CurrentCodeFoldBlockLevel);
TSynEditStrings(FTheLinesView).Ranges[Result] := fHighlighter.GetRange;
FTheLinesView.Ranges[Result] := fHighlighter.GetRange;
SetCodeFoldAttributes;
SkipPrev := False;
//if (Result and $fff)=0 then
@ -4287,7 +4282,6 @@ begin
Dec(Result);
end;
// Called with (0, 0) => to invalidate all lines => redraw
procedure TCustomSynEdit.LineCountChanged(Sender: TSynEditStrings; AIndex, ACount: Integer);
begin
ScanFrom(AIndex - 1, Min(AIndex, AIndex + ACount));
@ -4382,7 +4376,7 @@ begin
*)
i := 0;
repeat
TSynEditStrings(FTheLinesView).Ranges[i] := fHighlighter.GetRange;
FTheLinesView.Ranges[i] := fHighlighter.GetRange;
fHighlighter.SetLine(Lines[i], i);
fHighlighter.NextToEol;
Inc(i);
@ -4593,7 +4587,7 @@ begin
FBlockSelection.EndLineBytePos := Runner;
FBlockSelection.ActiveSelectionMode := smNormal;
// set caret to the end of selected block
CaretXY := TSynEditStrings(FTheLinesView).LogicalToPhysicalPos(Runner);
CaretXY := FTheLinesView.LogicalToPhysicalPos(Runner);
end;
{$ENDIF}
@ -4619,7 +4613,7 @@ begin
FBlockSelection.EndLineBytePos := Point(x2, MinMax(Value.y, 1, FTheLinesView.Count));
end;
FBlockSelection.ActiveSelectionMode := smNormal;
CaretXY := TSynEditStrings(FTheLinesView).LogicalToPhysicalPos(FBlockSelection.EndLineBytePos);
CaretXY := FTheLinesView.LogicalToPhysicalPos(FBlockSelection.EndLineBytePos);
//DebugLn(' FFF2 ',Value.X,',',Value.Y,' BlockBegin=',BlockBegin.X,',',BlockBegin.Y,' BlockEnd=',BlockEnd.X,',',BlockEnd.Y);
end;
@ -5486,7 +5480,7 @@ begin
{$IFDEF SYN_LAZARUS}
if fHighlighter<>nil then begin
fHighlighter.ResetRange;
TSynEditStrings(FTheLinesView).ClearRanges(fHighlighter.GetRange);
FTheLinesView.ClearRanges(fHighlighter.GetRange);
fTSearch.IdentChars:=fHighlighter.IdentChars;
end else begin
fTSearch.ResetIdentChars;
@ -6035,8 +6029,8 @@ begin
FBeautifier.CanUnindent(Self, Temp, CaretX) then
begin
// unindent
Temp := FBeautifier.UnIndentLine(Self, Temp, CaretXY,
Helper, Temp2, CX); // TODO: Temp2 must be added as crInsert to undolist
Temp := FBeautifier.UnIndentLine(Self, Temp, ViewedTextBuffer,
CaretXY, Helper, Temp2, CX); // TODO: Temp2 must be added as crInsert to undolist
FTheLinesView[CaretY - 1] := Temp;
CaretX := CX;
fLastCaretX := CaretX;
@ -6273,8 +6267,8 @@ begin
if (eoAutoIndent in fOptions) then begin
Caret := CaretXY;
Caret.Y := Caret.Y + 1;
Temp2 := FBeautifier.IndentLine(Self, Temp2, Caret, Helper,
Temp, CX, False);
Temp2 := FBeautifier.IndentLine(Self, Temp2, ViewedTextBuffer,
Caret, Helper, Temp, CX, False);
end else
CX := 1;
FTheLinesView[CaretY] := Temp2;
@ -6303,8 +6297,8 @@ begin
if (eoAutoIndent in fOptions) then begin
Caret := CaretXY;
Caret.Y := Caret.Y + 1;
Temp2 := FBeautifier.IndentLine(Self, Temp2, Caret, Helper,
Temp, CX, False);
Temp2 := FBeautifier.IndentLine(Self, Temp2, ViewedTextBuffer,
Caret, Helper, Temp, CX, False);
end else
CX := 1;
FTheLinesView.Insert(CaretY, Temp);
@ -6655,7 +6649,7 @@ begin
FindFirstNonWhiteSpaceCharInNextLine;
end else begin
if fHighlighter<>nil then begin
fHighlighter.SetRange(TSynEditStrings(FTheLinesView).Ranges[CY - 1]);
fHighlighter.SetRange(FTheLinesView.Ranges[CY - 1]);
fHighlighter.SetLine(Line, CY - 1);
while not fHighlighter.GetEol do begin
nTokenPos := fHighlighter.GetTokenPos; // zero-based
@ -7874,7 +7868,7 @@ begin
end;
{$IFDEF SYN_LAZARUS}
FUseUTF8:=fTextDrawer.UseUTF8;
TSynEditStrings(fLines).IsUtf8 := FUseUTF8;
FLines.IsUtf8 := FUseUTF8;
//debugln('TCustomSynEdit.RecalcCharExtent UseUTF8=',dbgs(UseUTF8),' Font.CanUTF8=',dbgs(Font.CanUTF8));
{$ENDIF}
GutterChanged(Self);
@ -8285,7 +8279,7 @@ begin
begin
// this line is blank
// -> use automatic line indent
LineStart := FBeautifier.GetIndentForLine(Self, FTheLinesView[CaretY-1], CaretXY);
LineStart := FBeautifier.GetIndentForLine(Self, FTheLinesView[CaretY-1], FTheLinesView, CaretXY);
end;
NewPos.X:=LineStart;
@ -8332,7 +8326,7 @@ begin
end else begin
// this line is blank
// -> use automatic line indent
LineEnd := FBeautifier.GetIndentForLine(Self, FTheLinesView[CaretY-1], CaretXY);
LineEnd := FBeautifier.GetIndentForLine(Self, FTheLinesView[CaretY-1], FTheLinesView, CaretXY);
end;
NewPos.X:=LineEnd;
@ -8583,7 +8577,7 @@ var
end;
// Init the Highlighter only once per line
if MaxKnownTokenPos < 1 then begin
fHighlighter.SetRange(TSynEditStrings(FTheLinesView).Ranges[PosY - 1]);
fHighlighter.SetRange(FTheLinesView.Ranges[PosY - 1]);
fHighlighter.SetLine(Line, PosY - 1);
TokenListCnt := 0;
end
@ -8834,11 +8828,7 @@ begin
if Assigned(Highlighter) and (PosY >= 0) and (PosY < FTheLinesView.Count) then
begin
Line := FTheLinesView[PosY];
{$IFDEF SYN_LAZARUS}
Highlighter.SetRange(TSynEditStrings(FTheLinesView).Ranges[PosY]);
{$ELSE}
Highlighter.SetRange(TSynEditStringList(Lines).Ranges[PosY]);
{$ENDIF}
Highlighter.SetRange(FTheLinesView.Ranges[PosY]);
Highlighter.SetLine(Line, PosY);
PosX := XY.X;
if (PosX > 0) and (PosX <= Length(Line)) then begin
@ -9080,7 +9070,7 @@ end;
function TCustomSynEdit.LogicalToPhysicalPos(const p: TPoint): TPoint;
begin
Result := TSynEditStrings(FTheLinesView).LogicalToPhysicalPos(p);
Result := FTheLinesView.LogicalToPhysicalPos(p);
end;
function TCustomSynEdit.LogicalToPhysicalCol(const Line: String;
@ -9088,7 +9078,7 @@ function TCustomSynEdit.LogicalToPhysicalCol(const Line: String;
// LogicalPos is 1-based
// Index 0-based LineNumber
begin
Result := TSynEditStrings(FTheLinesView).LogicalToPhysicalCol(Line, Index,
Result := FTheLinesView.LogicalToPhysicalCol(Line, Index,
LogicalPos);
end;
@ -9099,13 +9089,13 @@ end;
function TCustomSynEdit.PhysicalToLogicalPos(const p: TPoint): TPoint;
begin
Result := TSynEditStrings(FTheLinesView).PhysicalToLogicalPos(p);
Result := FTheLinesView.PhysicalToLogicalPos(p);
end;
function TCustomSynEdit.PhysicalToLogicalCol(const Line: string;
Index, PhysicalPos: integer): integer;
begin
Result := TSynEditStrings(FTheLinesView).PhysicalToLogicalCol(Line, Index,
Result := FTheLinesView.PhysicalToLogicalCol(Line, Index,
PhysicalPos);
end;

View File

@ -47,7 +47,8 @@ uses
{$ELSE}
Windows,
{$ENDIF}
Classes, Graphics, Controls, SysUtils, SynEditMiscProcs, SynEditTypes;
Classes, Graphics, Controls, SysUtils, SynEditMiscProcs, SynEditTypes,
SynEditTextBase;
type
@ -55,13 +56,14 @@ type
// in places where TCustomSynEdit can not be used due to circular unit refs
TSynEditBase = class(TCustomControl)
protected
function GetTheLinesView: TStrings; virtual; abstract;
procedure SetRealLines(const AValue : TStrings); virtual; abstract;
function GetLines: TStrings; virtual; abstract;
procedure SetLines(Value: TStrings); virtual; abstract;
function GetViewedTextBuffer: TSynEditStrings; virtual; abstract;
function GetTextBuffer: TSynEditStrings; virtual; abstract;
property ViewedTextBuffer: TSynEditStrings read GetViewedTextBuffer; // As viewed internally (with uncommited spaces / TODO: expanded tabs, folds). This may change, use with care
property TextBuffer: TSynEditStrings read GetTextBuffer; // No uncommited (trailing/trimmable) spaces
public
property RealLines: TStrings read GetTheLinesView write SetRealLines; // As viewed internally (with uncommited spaces / TODO: expanded tabs, folds). This may change, use with care
property Lines: TStrings read GetLines write SetLines; // No uncommited (trailing/trimmable) spaces
property Lines: TStrings read GetLines write SetLines;
end;
TSynObjectListItem = class;

View File

@ -610,7 +610,7 @@ var
TempString := Copy(FLines[BB.Y - 1], 1, BB.X - 1) +
Copy(FLines[BE.Y - 1], BE.X, MaxInt);
// Delete all FLines in the selection range.
TSynEditStrings(FLines).DeleteLines(BB.Y-1, BE.Y - BB.Y);
FLines.DeleteLines(BB.Y-1, BE.Y - BB.Y);
FLines[BB.Y - 1] := TempString;
end;
UpdateMarks := TRUE;
@ -713,7 +713,7 @@ var
P := GetEOL(Start);
if P^ <> #0 then begin
SetString(Str, Value, P - Start);
TSynEditStrings(FLines).InsertLines(FCaret.LinePos - 1, CountLines(P));
FLines.InsertLines(FCaret.LinePos - 1, CountLines(P));
FLines[FCaret.LinePos - 1] := sLeftSide + Str;
end else begin
FLines[FCaret.LinePos - 1] := sLeftSide + Value + sRightSide;

View File

@ -121,7 +121,6 @@ type
procedure Insert(Index: integer; const S: string); override;
procedure InsertLines(Index, NumLines: integer); override;
procedure InsertStrings(Index: integer; NewStrings: TStrings); override;
procedure Exchange(Index1, Index2: integer); override;
procedure ClearRanges(ARange: TSynEditRange); override;
@ -303,11 +302,6 @@ begin
fSynStrings.InsertStrings(Index, NewStrings);
end;
procedure TSynEditStringsLinked.Exchange(Index1, Index2: integer);
begin
fSynStrings.Exchange(Index1, Index2);
end;
function TSynEditStringsLinked.GetIsUtf8: Boolean;
begin
Result := FSynStrings.IsUtf8;

View File

@ -183,14 +183,11 @@ type
procedure RegisterAttribute(const Index: TClass; const Size: Word); override;
procedure DeleteLines(Index, NumLines: integer); // DJLP 2000-11-01
{$IFDEF SYN_LAZARUS}override;{$ENDIF}
procedure Exchange(Index1, Index2: integer); override;
procedure Insert(Index: integer; const S: string); override;
procedure InsertLines(Index, NumLines: integer); // DJLP 2000-11-01
{$IFDEF SYN_LAZARUS}override;{$ENDIF}
procedure InsertStrings(Index: integer; NewStrings: TStrings); // DJLP 2000-11-01
{$IFDEF SYN_LAZARUS}override;{$ENDIF}
procedure LoadFromFile(const FileName: string); override;
procedure SaveToFile(const FileName: string); override;
{$IFDEF SYN_LAZARUS}
procedure ClearRanges(ARange: TSynEditRange); override;
procedure MarkModified(AFirst, ALast: Integer; AUndo: Boolean; AReason: TSynChangeReason);
@ -297,206 +294,6 @@ const
{$ENDIF}
SListIndexOutOfBounds = 'Invalid stringlist index %d';
{ TSynEditFiler }
type
TSynEditFiler = class(TObject)
protected
fBuffer: PChar;
fBufPtr: Cardinal;
fBufSize: Cardinal;
fDosFile: boolean;
fFiler: TFileStream;
procedure Flush; virtual;
procedure SetBufferSize(NewSize: Cardinal);
public
constructor Create;
destructor Destroy; override;
public
property DosFile: boolean read fDosFile write fDosFile;
end;
constructor TSynEditFiler.Create;
const
kByte = 1024;
begin
inherited Create;
fDosFile := FALSE;
SetBufferSize(16 * kByte);
fBuffer[0] := #0;
end;
destructor TSynEditFiler.Destroy;
begin
Flush;
fFiler.Free;
SetBufferSize(0);
inherited Destroy;
end;
procedure TSynEditFiler.Flush;
begin
end;
procedure TSynEditFiler.SetBufferSize(NewSize: Cardinal);
begin
if NewSize <> fBufSize then begin
ReallocMem(fBuffer, NewSize);
fBufSize := NewSize;
end;
end;
{ TSynEditFileReader }
type
TSynEditFileReader = class(TSynEditFiler)
protected
{$IFDEF SYN_LAZARUS}
fFilePos: TStreamSeekType;
fFileSize: TStreamSeekType;
{$ELSE}
fFilePos: Cardinal;
fFileSize: Cardinal;
{$ENDIF}
procedure FillBuffer;
public
constructor Create(const FileName: string);
function EOF: boolean;
function ReadLine: string;
end;
constructor TSynEditFileReader.Create(const FileName: string);
begin
inherited Create;
fFiler := TFileStream.Create(UTF8ToSys(FileName), fmOpenRead{ ToDo: or fmShareDenyWrite});
fFileSize := fFiler.Size;
fFiler.Seek(0, soFromBeginning);
end;
function TSynEditFileReader.EOF: boolean;
begin
Result := (fBuffer[fBufPtr] = #0) and (fFilePos >= fFileSize);
end;
procedure TSynEditFileReader.FillBuffer;
var
Count: Cardinal;
begin
if fBufPtr >= fBufSize - 1 then
fBufPtr := 0;
Count := fFileSize - fFilePos;
if Count >= fBufSize - fBufPtr then
Count := fBufSize - fBufPtr - 1;
fFiler.ReadBuffer(fBuffer[fBufPtr], Count);
fBuffer[fBufPtr + Count] := #0;
fFilePos := fFilePos + Count;
fBufPtr := 0;
end;
function TSynEditFileReader.ReadLine: string;
var
E, P, S: PChar;
begin
Result := '';
repeat
S := PChar(@fBuffer[fBufPtr]);
if S[0] = #0 then begin
FillBuffer;
S := PChar(@fBuffer[0]);
end;
E := PChar(@fBuffer[fBufSize]);
P := S;
while P + 2 < E do begin
case P[0] of
#10, #13:
begin
SetString(Result, S, P - S);
{$IFDEF SYN_LAZARUS}
// a single #13 is used in Mac OS files
if (P[0] = #13) and (P[1] = #10) then begin
{$ELSE}
if P[0] = #13 then begin
{$ENDIF}
fDosFile := TRUE;
Inc(P);
end;
Inc(P);
fBufPtr := P - fBuffer;
exit;
end;
#0:
if fFilePos >= fFileSize then begin
fBufPtr := P - fBuffer;
SetString(Result, S, P - S);
exit;
end;
end;
Inc(P);
end;
// put the partial string to the start of the buffer, and refill the buffer
Inc(P);
if S > fBuffer then
StrLCopy(fBuffer, S, P - S);
fBufPtr := P - S;
fBuffer[fBufPtr] := #0;
// if line is longer than half the buffer then grow it first
if 2 * Cardinal(P - S) > fBufSize then
SetBufferSize(fBufSize + fBufSize);
until FALSE;
end;
{ TSynEditFileWriter }
type
TSynEditFileWriter = class(TSynEditFiler)
protected
procedure Flush; override;
public
constructor Create(const FileName: string);
procedure WriteLine(const S: string);
end;
constructor TSynEditFileWriter.Create(const FileName: string);
begin
inherited Create;
fFiler := TFileStream.Create(UTF8ToSys(FileName), fmCreate);
fFiler.Seek(0, soFromBeginning);
end;
procedure TSynEditFileWriter.Flush;
begin
if fBufPtr > 0 then begin
fFiler.WriteBuffer(fBuffer[0], fBufPtr);
fBufPtr := 0;
end;
end;
procedure TSynEditFileWriter.WriteLine(const S: string);
var
L, NL: Cardinal;
begin
L := Length(S);
NL := 1 + Ord(fDosFile);
repeat
if fBufPtr + L + NL <= fBufSize then begin
if L > 0 then begin
Move(S[1], fBuffer[fBufPtr], L);
fBufPtr := fBufPtr + L;
end;
if fDosFile then begin
fBuffer[fBufPtr] := #13;
Inc(fBufPtr);
end;
fBuffer[fBufPtr] := #10;
Inc(fBufPtr);
exit;
end;
Flush;
if L + NL > fBufSize then
SetBufferSize(L + NL);
until FALSE;
end;
{ TSynEditStringList }
procedure ListIndexOutOfBounds(Index: integer);
@ -626,25 +423,6 @@ begin
end;
{end} // DJLP 2000-11-01
procedure TSynEditStringList.Exchange(Index1, Index2: integer);
begin
if (Index1 < 0) or (Index1 >= Count) then
ListIndexOutOfBounds(Index1);
if (Index2 < 0) or (Index2 >= Count) then
ListIndexOutOfBounds(Index2);
BeginUpdate;
If Count+1 >= Capacity then Grow;
FList.Move(Index1, Count, 1);
FList.Move(Index2, Index1, 1);
FList.Move(Count, Index2, 1);
FList.Move(Count+1, Count, 1); // clean it
if fIndexOfLongestLine = Index1 then
fIndexOfLongestLine := Index2
else if fIndexOfLongestLine = Index2 then
fIndexOfLongestLine := Index1;
EndUpdate;
end;
{$IFDEF SYN_LAZARUS}
function TSynEditStringList.GetFlags(Index: Integer): TSynEditStringFlags;
begin
@ -830,26 +608,6 @@ begin
end;
{end} // DJLP 2000-11-01
procedure TSynEditStringList.LoadFromFile(const FileName: string);
var
Reader: TSynEditFileReader;
begin
Reader := TSynEditFileReader.Create(FileName);
try
BeginUpdate;
try
Clear;
while not Reader.EOF do
Add(Reader.ReadLine);
fDosFileFormat := Reader.DosFile;
finally
EndUpdate;
end;
finally
Reader.Free;
end;
end;
procedure TSynEditStringList.Put(Index: integer; const S: string);
begin
if (Index = 0) and (Count = 0) then
@ -956,23 +714,6 @@ begin
SetAttribute(TSynEditFlagsClass, Index, Pointer(PtrUInt(Integer(AValue))));
end;
procedure TSynEditStringList.SaveToFile(const FileName: string);
var
Writer: TSynEditFileWriter;
i: integer;
begin
Writer := TSynEditFileWriter.Create(FileName);
try
Writer.DosFile := fDosFileFormat;
for i := 0 to Count - 1 do
Writer.WriteLine(Get(i));
finally
Writer.Free;
end;
MarkSaved;
FLineRangeNotificationList.CallRangeNotifyEvents(self, 0, 0);
end;
{$IFDEF SYN_LAZARUS}
procedure TSynEditStringList.ClearRanges(ARange: TSynEditRange);
var

View File

@ -214,7 +214,7 @@ var
allmrk: TSynEditMarks;
begin
line := TSynEdit(FEdit).PixelsToRowColumn(Point(X, Y)).Y;
if line <= TSynEdit(FEdit).Lines.Count then begin
if line <= FEdit.Lines.Count then begin
mark := nil;
TSynEdit(FEdit).Marks.GetMarksForLine(line, allmrk);
offs := 0;

View File

@ -72,7 +72,7 @@ var
line : integer;
begin
line := TSynEdit(SynEdit).PixelsToRowColumn(Point(X, Y)).Y;
if line <= TSynEdit(SynEdit).Lines.Count then
if line <= SynEdit.Lines.Count then
TSynEdit(SynEdit).CodeFoldAction(line);
end;

View File

@ -240,7 +240,7 @@ begin
// or a multiple of ShowOnlyLineNumbersMultiplesOf
ShowDot := ((iLine mod ShowOnlyLineNumbersMultiplesOf) <> 0)
and (iLine <> TSynEdit(SynEdit).CaretY) and (iLine <> 1)
and (iLine <> TSynEdit(SynEdit).Lines.Count);
and (iLine <> SynEdit.Lines.Count);
// Get the formatted line number or dot
s := FormatLineNumber(iLine, ShowDot);
Inc(rcLine.Bottom, LineHeight);

View File

@ -82,7 +82,7 @@ var
begin
iTop := 0;
CurMark := TSynEdit(SynEdit).Marks[iMark];
if (CurMark.Line<1) or (CurMark.Line>TSynEdit(SynEdit).Lines.Count) then exit;
if (CurMark.Line<1) or (CurMark.Line > SynEdit.Lines.Count) then exit;
if FFoldView.FoldedAtTextIndex[CurMark.Line-1] then exit;
iLine := FFoldView.TextIndexToScreenLine(CurMark.Line-1);

View File

@ -204,8 +204,8 @@ begin
e:=LineEnding;
LineEndLen:=length(e);
Chars := 0;
while y < Lines.Count do begin
x := Length(Lines[y]);
while y < TextBuffer.Count do begin
x := Length(TextBuffer[y]);
if Chars + x + LineEndLen > Index then begin
x := Index - Chars;
break;
@ -224,11 +224,11 @@ var
LineEndLen: Integer;
begin
Result := 0;
RowCol.y := Min(Lines.Count, RowCol.y) - 1;
RowCol.y := Min(TextBuffer.Count, RowCol.y) - 1;
e:=LineEnding;
LineEndLen:=length(e);
for i := 0 to RowCol.y - 1 do
Result := Result + Length(Lines[i]) + LineEndLen;
Result := Result + Length(TextBuffer[i]) + LineEndLen;
Result := Result + RowCol.x;
end;