📄 synedittextbuffer.pas
字号:
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);
procedure WriteLine(const S: string; const FileFormat: TSynEditFileFormat); //Fiala
procedure Write(const S: String); //GBN 2002-04-16
end;
constructor TSynEditFileWriter.Create(const FileName: string);
begin
inherited Create;
fFiler := TFileStream.Create(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;
//GBN 2002-04-16
procedure TSynEditFileWriter.Write(const S: String);
var L: Cardinal;
begin
L := Length(S);
repeat
if fBufPtr + L <= fBufSize then begin
if L > 0 then begin
Move(S[1], fBuffer[fBufPtr], L);
fBufPtr := fBufPtr + L;
end;
exit;
end;
Flush;
if L > fBufSize then
SetBufferSize(L);
until False;
end;
procedure TSynEditFileWriter.WriteLine(const S: string;
const FileFormat: TSynEditFileFormat); //Fiala 2001-12-17
var
L, NL: Cardinal;
begin
L := Length(S);
NL := 1 + Ord(fFileFormat = sffDos);
repeat
if fBufPtr + L + NL <= fBufSize then begin
if L > 0 then begin
Move(S[1], fBuffer[fBufPtr], L);
fBufPtr := fBufPtr + L;
end;
if (fFileFormat <> sffUnix) then
begin
fBuffer[fBufPtr] := #13; // CR
Inc(fBufPtr);
end;
if (fFileFormat <> sffMac) then
begin
fBuffer[fBufPtr] := #10; // LF
Inc(fBufPtr);
end;
Exit;
end;
Flush;
if L + NL > fBufSize then
SetBufferSize(L + NL);
until FALSE;
end;
{ TSynEditStringList }
procedure ListIndexOutOfBounds(Index: integer);
begin
raise ESynEditStringList.CreateFmt(SListIndexOutOfBounds, [Index]);
end;
constructor TSynEditStringList.Create;
begin
inherited Create;
fAppendNewLineAtEOF:=true; //Retain current behavior gbn 2002-04-25
fWordWrap := False;
fWordWrapWidth := 80;
fFileFormat := sffDos;
{begin} //mh 2000-10-19
fIndexOfLongestLine := -1;
TabWidth := 8;
{end} //mh 2000-10-19
end;
destructor TSynEditStringList.Destroy;
begin
fOnChange := nil;
fOnChanging := nil;
inherited Destroy;
if fCount <> 0 then
Finalize(fList^[0], fCount);
fCount := 0;
SetCapacity(0);
end;
function TSynEditStringList.Add(const S: string): integer;
begin
BeginUpdate;
Result := fCount;
InsertItem(Result, S);
if Assigned(fOnAdded) then
fOnAdded(Result, S);
EndUpdate;
end;
procedure TSynEditStringList.AddStrings(Strings: TStrings);
var
i, FirstAdded: integer;
begin
{begin} //mh 2000-10-19
if Strings.Count > 0 then begin
fIndexOfLongestLine := -1;
BeginUpdate;
try
i := fCount + Strings.Count;
if i > fCapacity then
SetCapacity((i + 15) and (not 15));
FirstAdded := fCount;
for i := 0 to Strings.Count - 1 do begin
with fList^[fCount] do begin
Pointer(fString) := nil;
fString := Strings[i];
fObject := Strings.Objects[i];
fRange := NullRange;
fExpandedLength := -1;
fFlags := [sfExpandedLengthUnknown];
end;
Inc(fCount);
end;
if Assigned(fOnAdded) then
fOnAdded(FirstAdded, '');
finally
EndUpdate;
end;
end;
{end} //mh 2000-10-19
end;
procedure TSynEditStringList.Clear;
begin
if fCount <> 0 then begin
BeginUpdate;
Finalize(fList^[0], fCount);
fCount := 0;
SetCapacity(0);
if Assigned(fOnCleared) then
fOnCleared(Self);
EndUpdate;
end;
fIndexOfLongestLine := -1; //mh 2000-10-19
end;
procedure TSynEditStringList.Delete(Index: integer);
begin
if (Index < 0) or (Index > fCount) then
ListIndexOutOfBounds(Index);
BeginUpdate;
Finalize(fList^[Index]);
Dec(fCount);
if Index < fCount then begin
System.Move(fList^[Index + 1], fList^[Index],
(fCount - Index) * SynEditStringRecSize);
end;
fIndexOfLongestLine := -1; //mh 2000-10-19
if Assigned(fOnDeleted) then
fOnDeleted(Index);
EndUpdate;
end;
{begin} // DJLP 2000-11-01
procedure TSynEditStringList.DeleteLines(Index, NumLines: Integer);
var
LinesAfter: integer;
begin
if NumLines > 0 then begin
if (Index < 0) or (Index > fCount) then
ListIndexOutOfBounds(Index);
LinesAfter := fCount - (Index + NumLines - 1);
if LinesAfter < 0 then
NumLines := fCount - Index - 1;
Finalize(fList^[Index], NumLines);
if LinesAfter > 0 then begin
BeginUpdate;
try
System.Move(fList^[Index + NumLines], fList^[Index],
LinesAfter * SynEditStringRecSize);
finally
EndUpdate;
end;
end;
Dec(fCount, NumLines);
if Assigned(fOnDeleted) then
fOnDeleted(Index);
end;
end;
{end} // DJLP 2000-11-01
procedure TSynEditStringList.Exchange(Index1, Index2: integer);
var
Temp: TSynEditStringRec;
begin
if (Index1 < 0) or (Index1 >= fCount) then
ListIndexOutOfBounds(Index1);
if (Index2 < 0) or (Index2 >= fCount) then
ListIndexOutOfBounds(Index2);
BeginUpdate;
Temp := fList^[Index1];
fList^[Index1] := fList^[Index2];
fList^[Index2] := Temp;
{begin} //mh 2000-10-19
if fIndexOfLongestLine = Index1 then
fIndexOfLongestLine := Index2
else if fIndexOfLongestLine = Index2 then
fIndexOfLongestLine := Index1;
{end} //mh 2000-10-19
EndUpdate;
end;
{begin} //mh 2000-10-19
function TSynEditStringList.ExpandString(Index: integer): string;
var
HasTabs: boolean;
begin
with fList^[Index] do
if fString = '' then begin
Result := '';
Exclude(fFlags, sfExpandedLengthUnknown);
Exclude(fFlags, sfHasTabs);
Include(fFlags, sfHasNoTabs);
fExpandedLength := 0;
end else begin
Result := fConvertTabsProc(fString, fTabWidth, HasTabs);
fExpandedLength := Length(Result);
Exclude(fFlags, sfExpandedLengthUnknown);
Exclude(fFlags, sfHasTabs);
Exclude(fFlags, sfHasNoTabs);
if HasTabs then
Include(fFlags, sfHasTabs)
else
Include(fFlags, sfHasNoTabs);
end;
end;
{end} //mh 2000-10-19
function TSynEditStringList.Get(Index: integer): string;
begin
if (Index >= 0) and (Index < fCount) then
Result := fList^[Index].fString
else
Result := '';
end;
function TSynEditStringList.GetCapacity: integer;
begin
Result := fCapacity;
end;
function TSynEditStringList.GetCount: integer;
begin
Result := fCount;
end;
{begin} //mh 2000-10-19
function TSynEditStringList.GetExpandedString(Index: integer): string;
begin
if (Index >= 0) and (Index < fCount) then begin
if sfHasNoTabs in fList^[Index].fFlags then
Result := fList^[Index].fString
else
Result := ExpandString(Index);
end else
Result := '';
end;
function TSynEditStringList.GetExpandedStringLength(Index: integer): integer;
begin
if (Index >= 0) and (Index < fCount) then
begin
if sfExpandedLengthUnknown in fList^[Index].fFlags then
Result := Length( ExpandedStrings[index] )
else
Result := fList^[Index].fExpandedLength;
end
else
Result := 0;
end;
function TSynEditStringList.GetLengthOfLongestLine: integer; //mh 2000-10-19
var
i, MaxLen: integer;
PRec: PSynEditStringRec;
begin
if fIndexOfLongestLine < 0 then begin
MaxLen := 0;
if fCount > 0 then begin
PRec := @fList^[0];
for i := 0 to fCount - 1 do begin
if sfExpandedLengthUnknown in PRec^.fFlags then
ExpandString(i);
if PRec^.fExpandedLength > MaxLen then begin
MaxLen := PRec^.fExpandedLength;
fIndexOfLongestLine := i;
end;
Inc(PRec);
end;
end;
end;
if (fIndexOfLongestLine >= 0) and (fIndexOfLongestLine < fCount) then
Result := fList^[fIndexOfLongestLine].fExpandedLength
else
Result := 0;
end;
{end} //mh 2000-10-19
function TSynEditStringList.GetObject(Index: integer): TObject;
begin
if (Index >= 0) and (Index < fCount) then
Result := fList^[Index].fObject
else
Result := nil;
end;
function TSynEditStringList.GetRange(Index: integer): TSynEditRange;
begin
if (Index >= 0) and (Index < fCount) then
Result := fList^[Index].fRange
else
Result := nil;
end;
procedure TSynEditStringList.Grow;
var
Delta: Integer;
begin
if fCapacity > 64 then
Delta := fCapacity div 4
else
Delta := 16;
SetCapacity(fCapacity + Delta);
end;
procedure TSynEditStringList.Insert(Index: integer; const S: string);
begin
if (Index < 0) or (Index > fCount) then
ListIndexOutOfBounds(Index);
BeginUpdate;
InsertItem(Index, S);
if Assigned(fOnInserted) then
fOnInserted(Index, S);
EndUpdate;
end;
procedure TSynEditStringList.InsertItem(Index: integer; const S: string);
var //Fiala 2001-12-17
s1: string; //Fiala 2001-12-17
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -