Long long code editor lines

This commit is contained in:
Margers 2024-10-09 13:22:39 +00:00 committed by Michael Van Canneyt
parent ca0dad1ce1
commit 5c215cd524
6 changed files with 569 additions and 302 deletions

View File

@ -820,7 +820,7 @@ begin
else
messagebox('Internal error: Unknown switch.',nil,mfOkButton);
end;
e^.setcontent(directorySwitches^.getMultiStringItem(i));
e^.SetContent(directorySwitches^.getMultiStringItem(i));
e^.addline(''); {Empty line so user can scroll below existing dirs.}
IL[i]:=nil;
end
@ -904,14 +904,10 @@ begin
end;
c:=directorySwitches^.getMultiStringItem(i);
c^.freeall;
for j:=0 to e^.getlinecount-1 do
for j:=0 to e^.GetLineCount-1 do
begin
s:=e^.getlinetext(j);
{Strip string.}
while (length(s)>0) and (s[length(s)]=' ') do
dec(s[0]);
while (length(s)>0) and (s[1]=' ') do
system.delete(s,1,1);
s:=e^.GetLineText(j); { Note: AnsiString to ShortString convertino}
s:=Trim(s);
if s<>'' then
c^.insert(newstr(s));
end;
@ -919,11 +915,7 @@ begin
else
begin
s:=IL[i]^.data^;
{Strip string.}
while (length(s)>0) and (s[length(s)]=' ') do
dec(s[0]);
while (length(s)>0) and (s[1]=' ') do
system.delete(s,1,1);
s:=Trim(s);
DirectorySwitches^.SetStringItem(i,s);
end;
end;

View File

@ -173,8 +173,8 @@ type
procedure DelChar; virtual;
procedure DelSelect; virtual;
function InsertNewLine : Sw_integer;virtual;
function InsertLine(LineNo: sw_integer; const S: string): PCustomLine; virtual;
procedure AddLine(const S: string); virtual;
function InsertLine(LineNo: sw_integer; const S: sw_astring): PCustomLine; virtual;
procedure AddLine(const S: sw_astring); virtual;
end;
PSourceWindow = ^TSourceWindow;
@ -203,7 +203,7 @@ type
TGDBSourceEditor = object(TSourceEditor)
function InsertNewLine : Sw_integer;virtual;
function Valid(Command: Word): Boolean; virtual;
procedure AddLine(const S: string); virtual;
procedure AddLine(const S: sw_astring); virtual;
procedure AddErrorLine(const S: string); virtual;
{ Syntax highlight }
function IsReservedWord(const S: string): boolean; virtual;
@ -1387,7 +1387,7 @@ end;
procedure TSourceEditor.FindMatchingDelimiter(ScanForward: boolean);
var
St,nextResWord : String;
LineText,LineAttr: string;
LineText,LineAttr: sw_astring;
Res,found,addit : boolean;
JumpPos: TPoint;
X,Y,lexchange,curlevel,linecount : sw_integer;
@ -1698,7 +1698,7 @@ end;
procedure TSourceEditor.DelChar;
var
S: string;
S: sw_astring;
I,CI : sw_integer;
{$ifndef NODEBUG}
PBStart,PBEnd : PBreakpoint;
@ -1802,7 +1802,7 @@ begin
end;
function TSourceEditor.InsertLine(LineNo: sw_integer; const S: string): PCustomLine;
function TSourceEditor.InsertLine(LineNo: sw_integer; const S: sw_astring): PCustomLine;
begin
InsertLine := inherited InsertLine(LineNo,S);
{$ifndef NODEBUG}
@ -1811,7 +1811,7 @@ begin
{$endif NODEBUG}
end;
procedure TSourceEditor.AddLine(const S: string);
procedure TSourceEditor.AddLine(const S: sw_astring);
begin
inherited AddLine(S);
{$ifndef NODEBUG}
@ -1870,7 +1870,7 @@ begin
AddToolMessage('','Group '+ActionString[action]+' '+IntToStr(ActionCount)+' elementary actions',0,0)
else
AddToolMessage('',ActionString[action]+' '+IntToStr(StartPos.Y+1)+':'+IntToStr(StartPos.X+1)+
' '+IntToStr(EndPos.Y+1)+':'+IntToStr(EndPos.X+1)+' "'+GetStr(Text)+'"',0,0);
' '+IntToStr(EndPos.Y+1)+':'+IntToStr(EndPos.X+1)+' "'+GetText()+'"',0,0);
end;
if Core^.RedoList^.count>0 then
AddToolCommand('RedoList Dump');
@ -1881,7 +1881,7 @@ begin
AddToolMessage('','Group '+ActionString[action]+' '+IntToStr(ActionCount)+' elementary actions',0,0)
else
AddToolMessage('',ActionString[action]+' '+IntToStr(StartPos.Y+1)+':'+IntToStr(StartPos.X+1)+
' '+IntToStr(EndPos.Y+1)+':'+IntToStr(EndPos.X+1)+' "'+GetStr(Text)+'"',0,0);
' '+IntToStr(EndPos.Y+1)+':'+IntToStr(EndPos.X+1)+' "'+GetText()+'"',0,0);
end;
UpdateToolMessages;
if Assigned(MessagesWindow) then
@ -2213,11 +2213,11 @@ begin
inherited Init(Bounds,AFileName,{SearchFreeWindowNo}0);
AutoNumber:=true;
Options:=Options or ofTileAble;
GetExtent(R); R.A.Y:=R.B.Y-1; R.Grow(-1,0); R.A.X:=14;
GetExtent(R); R.A.Y:=R.B.Y-1; R.Grow(-1,0); R.A.X:=15;
New(HSB, Init(R)); HSB^.GrowMode:=gfGrowLoY+gfGrowHiX+gfGrowHiY; Insert(HSB);
GetExtent(R); R.A.X:=R.B.X-1; R.Grow(0,-1);
New(VSB, Init(R)); VSB^.GrowMode:=gfGrowLoX+gfGrowHiX+gfGrowHiY; Insert(VSB);
GetExtent(R); R.A.X:=3; R.B.X:=14; R.A.Y:=R.B.Y-1;
GetExtent(R); R.A.X:=3; R.B.X:=15; R.A.Y:=R.B.Y-1;
New(Indicator, Init(R));
Indicator^.GrowMode:=gfGrowLoY+gfGrowHiY;
Insert(Indicator);
@ -2419,7 +2419,7 @@ begin
Valid:=OK;
end;
procedure TGDBSourceEditor.AddLine(const S: string);
procedure TGDBSourceEditor.AddLine(const S: sw_astring);
begin
if Silent or (IgnoreStringAtEnd and (S=LastCommand)) then exit;
inherited AddLine(S);
@ -2696,7 +2696,7 @@ end;
procedure TDisassemblyEditor.AddSourceLine(const AFileName: string;line : longint);
var
S : String;
S : sw_astring;
begin
if AFileName<>CurrentSource then
begin

View File

@ -47,7 +47,11 @@ type
PLine = ^TLine;
TLine = object(TCustomLine)
public { internal use only! }
Text : PString;
{$if sizeof(sw_astring)>8}
Text : PString; { ShortString version }
{$else}
Text : sw_AString; { AnsiString version }
{$endif}
DefaultEditorInfo : PEditorLineInfo;
EditorInfos : PEditorLineInfoCollection;
Flags : longint;
@ -55,9 +59,9 @@ type
procedure AddEditorInfo(Index: sw_integer; AEditor: PCustomCodeEditor); virtual;
procedure RemoveEditorInfo(AEditor: PCustomCodeEditor); virtual;
public
constructor Init(AOwner: PCustomCodeEditorCore; const AText: string; AFlags: longint);
function GetText: string; virtual;
procedure SetText(const AText: string); virtual;
constructor Init(AOwner: PCustomCodeEditorCore; const AText: sw_AString; AFlags: longint);
function GetText: sw_AString; virtual;
procedure SetText(const AText: sw_AString); virtual;
function GetEditorInfo(Editor: PCustomCodeEditor): PEditorLineInfo; virtual;
function GetFlags: longint; virtual;
procedure SetFlags(AFlags: longint); virtual;
@ -98,26 +102,26 @@ type
protected
{ Text & info storage abstraction }
procedure ISetLineFlagState(Binding: PEditorBinding; LineNo: sw_integer; Flag: longint; ASet: boolean); virtual;
procedure IGetDisplayTextFormat(Binding: PEditorBinding; LineNo: sw_integer;var DT,DF:string); virtual;
function IGetLineFormat(Binding: PEditorBinding; LineNo: sw_integer): string; virtual;
procedure ISetLineFormat(Binding: PEditorBinding; LineNo: sw_integer;const S: string); virtual;
procedure IGetDisplayTextFormat(Binding: PEditorBinding; LineNo: sw_integer;var DT,DF:sw_astring); virtual;
function IGetLineFormat(Binding: PEditorBinding; LineNo: sw_integer): sw_astring; virtual;
procedure ISetLineFormat(Binding: PEditorBinding; LineNo: sw_integer;const S: sw_astring); virtual;
public
{ Text & info storage abstraction }
function GetLineCount: sw_integer; virtual;
function GetLine(LineNo: sw_integer): PCustomLine; virtual;
function GetLineText(LineNo: sw_integer): string; virtual;
procedure SetDisplayText(I: sw_integer;const S: string); virtual;
function GetDisplayText(I: sw_integer): string; virtual;
procedure SetLineText(I: sw_integer;const S: string); virtual;
function GetLineText(LineNo: sw_integer): sw_AString; virtual;
procedure SetDisplayText(I: sw_integer;const S: sw_astring); virtual;
function GetDisplayText(I: sw_integer): sw_astring; virtual;
procedure SetLineText(I: sw_integer;const S: sw_AString); virtual;
procedure DeleteAllLines; virtual;
procedure DeleteLine(I: sw_integer); virtual;
function InsertLine(LineNo: sw_integer; const S: string): PCustomLine; virtual;
procedure AddLine(const S: string); virtual;
function InsertLine(LineNo: sw_integer; const S: sw_AString): PCustomLine; virtual;
procedure AddLine(const S: sw_AString); virtual;
procedure GetContent(ALines: PUnsortedStringCollection); virtual;
procedure SetContent(ALines: PUnsortedStringCollection); virtual;
public
{ Undo info storage }
procedure AddAction(AAction: byte; AStartPos, AEndPos: TPoint; AText: string;AFlags : longint); virtual;
procedure AddAction(AAction: byte; AStartPos, AEndPos: TPoint; AText: sw_astring;AFlags : longint); virtual;
procedure AddGroupedAction(AAction : byte); virtual;
procedure CloseGroupedAction(AAction : byte); virtual;
function GetUndoActionCount: sw_integer; virtual;
@ -180,17 +184,17 @@ type
function GetLine(LineNo: sw_integer): PCustomLine; virtual;
function CharIdxToLinePos(Line,CharIdx: sw_integer): sw_integer; virtual;
function LinePosToCharIdx(Line,X: sw_integer): sw_integer; virtual;
function GetLineText(I: sw_integer): string; virtual;
procedure SetDisplayText(I: sw_integer;const S: string); virtual;
function GetDisplayText(I: sw_integer): string; virtual;
procedure SetLineText(I: sw_integer;const S: string); virtual;
procedure GetDisplayTextFormat(I: sw_integer;var DT,DF:string); virtual;
function GetLineFormat(I: sw_integer): string; virtual;
procedure SetLineFormat(I: sw_integer;const S: string); virtual;
function GetLineText(I: sw_integer): sw_AString; virtual;
procedure SetDisplayText(I: sw_integer;const S: sw_astring); virtual;
function GetDisplayText(I: sw_integer): sw_astring; virtual;
procedure SetLineText(I: sw_integer;const S: sw_AString); virtual;
procedure GetDisplayTextFormat(I: sw_integer;var DT,DF:sw_astring); virtual;
function GetLineFormat(I: sw_integer): sw_astring; virtual;
procedure SetLineFormat(I: sw_integer;const S: sw_astring); virtual;
procedure DeleteAllLines; virtual;
procedure DeleteLine(I: sw_integer); virtual;
function InsertLine(LineNo: sw_integer; const S: string): PCustomLine; virtual;
procedure AddLine(const S: string); virtual;
function InsertLine(LineNo: sw_integer; const S: sw_astring): PCustomLine; virtual;
procedure AddLine(const S: sw_astring); virtual;
function GetErrorMessage: string; virtual;
procedure SetErrorMessage(const S: string); virtual;
procedure GetContent(ALines: PUnsortedStringCollection); virtual;
@ -211,7 +215,7 @@ type
{a}function UpdateAttrsRange(FromLine, ToLine: sw_integer; Attrs: byte): sw_integer; virtual;
public
{ Undo info storage }
procedure AddAction(AAction: byte; AStartPos, AEndPos: TPoint; AText: string;AFlags : longint); virtual;
procedure AddAction(AAction: byte; AStartPos, AEndPos: TPoint; AText: sw_astring;AFlags : longint); virtual;
procedure AddGroupedAction(AAction : byte); virtual;
procedure CloseGroupedAction(AAction : byte); virtual;
function GetUndoActionCount: sw_integer; virtual;
@ -290,7 +294,7 @@ const
);
{$endif}
constructor TLine.Init(AOwner: PCustomCodeEditorCore; const AText: string; AFlags: longint);
constructor TLine.Init(AOwner: PCustomCodeEditorCore; const AText: sw_AString; AFlags: longint);
begin
inherited Init(AText,AFlags);
// New(EditorInfos, Init(10,10));
@ -321,14 +325,22 @@ begin
EditorInfos^.Free(E);
end;
function TLine.GetText: string;
function TLine.GetText: sw_AString;
begin
{$if sizeof(sw_astring)>8}
GetText:=GetStr(Text);
{$else}
GetText:=Text;
{$endif}
end;
procedure TLine.SetText(const AText: string);
procedure TLine.SetText(const AText: sw_AString);
begin
{$if sizeof(sw_astring)>8}
SetStr(Text,AText);
{$else}
Text:=AText;
{$endif}
end;
function TLine.GetEditorInfo(Editor: PCustomCodeEditor): PEditorLineInfo;
@ -357,9 +369,14 @@ end;
destructor TLine.Done;
begin
{$if sizeof(sw_astring)>8}
{ ShortString version }
if Assigned(Text) then
DisposeStr(Text);
Text:=nil;
{$else}
Text:=''; { AnsiString version }
{$endif}
if Assigned(EditorInfos) then
Dispose(EditorInfos, Done);
EditorInfos:=nil;
@ -477,7 +494,7 @@ procedure TCodeEditorCore.GetContent(ALines: PUnsortedStringCollection);
procedure AddIt(P: PCustomLine);
begin
if Assigned(P) then
ALines^.Insert(NewStr(P^.GetText));
ALines^.Insert(NewStr(P^.GetText)); { Note: AnsiString to ShortString convertion }
end;
begin
if Assigned(Lines) then
@ -487,7 +504,7 @@ end;
procedure TCodeEditorCore.SetContent(ALines: PUnsortedStringCollection);
procedure AddIt(P: PString);
begin
AddLine(GetStr(P));
AddLine(GetStr(P)); { Note: ShortString to AnsiString convertion }
end;
begin
DeleteAllLines;
@ -523,7 +540,7 @@ begin
end;
end;
function TCodeEditorCore.GetLineText(LineNo: sw_integer): string;
function TCodeEditorCore.GetLineText(LineNo: sw_integer): sw_AString;
var
L : PCustomLine;
begin
@ -549,7 +566,7 @@ begin
Lines^.AtInsert(Idx,Line);
end;
procedure TCodeEditorCore.SetLineText(I: sw_integer;const S: string);
procedure TCodeEditorCore.SetLineText(I: sw_integer;const S: sw_AString);
var
L : PCustomLine;
AddCount : Sw_Integer;
@ -567,12 +584,12 @@ begin
ContentsChanged;
end;
function TCodeEditorCore.GetDisplayText(I: sw_integer): string;
function TCodeEditorCore.GetDisplayText(I: sw_integer): sw_astring;
begin
GetDisplayText:=ExtractTabs(GetLineText(I),GetTabSize);
end;
procedure TCodeEditorCore.SetDisplayText(I: sw_integer;const S: string);
procedure TCodeEditorCore.SetDisplayText(I: sw_integer;const S: sw_astring);
begin
{ I disagree here
I don't want the editor to change the position of the tabs
@ -584,7 +601,7 @@ begin
SetLineText(I,S);
end;
procedure TCodeEditorCore.IGetDisplayTextFormat(Binding: PEditorBinding; LineNo: sw_integer;var DT,DF:string);
procedure TCodeEditorCore.IGetDisplayTextFormat(Binding: PEditorBinding; LineNo: sw_integer;var DT,DF:sw_astring);
var
L : PCustomLine;
P,PAdd : SW_Integer;
@ -606,18 +623,18 @@ begin
begin
PAdd:=TabSize-((p-1) mod TabSize);
if DF<>'' then
DF:=copy(DF,1,P-1)+CharStr(DF[p],PAdd)+copy(DF,P+1,High(DF));
DT:=copy(DT,1,P-1)+CharStr(' ',PAdd)+copy(DT,P+1,High(DF));
DF:=copy(DF,1,P-1)+CharStr(DF[p],PAdd)+copy(DF,P+1,Length(DF));
DT:=copy(DT,1,P-1)+CharStr(' ',PAdd)+copy(DT,P+1,Length(DT));
inc(P,PAdd-1);
end;
end;
end;
end;
function TCodeEditorCore.IGetLineFormat(Binding: PEditorBinding; LineNo: sw_integer): string;
function TCodeEditorCore.IGetLineFormat(Binding: PEditorBinding; LineNo: sw_integer): sw_astring;
var P: PCustomLine;
LI: PEditorLineInfo;
S: string;
S: sw_astring;
begin
if (0<=LineNo) and (LineNo<GetLineCount) then
P:=GetLine(LineNo)
@ -629,7 +646,7 @@ begin
IGetLineFormat:=S;
end;
procedure TCodeEditorCore.ISetLineFormat(Binding: PEditorBinding; LineNo: sw_integer;const S: string);
procedure TCodeEditorCore.ISetLineFormat(Binding: PEditorBinding; LineNo: sw_integer;const S: sw_astring);
var P: PCustomLine;
LI: PEditorLineInfo;
begin
@ -662,7 +679,7 @@ begin
end;
end;
function TCodeEditorCore.InsertLine(LineNo: sw_integer; const S: string): PCustomLine;
function TCodeEditorCore.InsertLine(LineNo: sw_integer; const S: sw_AString): PCustomLine;
var L: PLine;
begin
L:=New(PLine, Init(@Self,S,0));
@ -670,16 +687,16 @@ begin
InsertLine:=L;
end;
procedure TCodeEditorCore.AddLine(const S: string);
procedure TCodeEditorCore.AddLine(const S: sw_AString);
begin
LinesInsert(-1,New(PLine, Init(@Self,S,0)));
end;
procedure TCodeEditorCore.AddAction(AAction: byte; AStartPos, AEndPos: TPoint; AText: string;AFlags : longint);
procedure TCodeEditorCore.AddAction(AAction: byte; AStartPos, AEndPos: TPoint; AText: sw_astring;AFlags : longint);
var
ActionIntegrated : boolean;
pa : PEditorAction;
S : String;
S : Sw_AString;
begin
if (UndoList=nil) or (not StoreUndo) then Exit;
ActionIntegrated:=false;
@ -700,14 +717,12 @@ begin
then
begin
pa^.EndPos:=AEndPos;
S:=GetStr(pa^.text);
if S<>'' then
DisposeStr(pa^.text);
S:=pa^.GetText;
if (AAction=eaDeleteText) and
(AStartPos.X>AEndPos.X) then
pa^.text:=NewStr(AText+S)
pa^.SetText(AText+S)
else
pa^.text:=NewStr(S+AText);
pa^.SetText(S+AText);
ActionIntegrated:=true;
end;
end;
@ -1008,37 +1023,37 @@ begin
LinePosToCharIdx:=Core^.LinePosToCharIdx(Line,X);
end;
function TCodeEditor.GetLineText(I: sw_integer): string;
function TCodeEditor.GetLineText(I: sw_integer): sw_astring;
begin
GetLineText:=Core^.GetLineText(I);
end;
procedure TCodeEditor.SetDisplayText(I: sw_integer;const S: string);
procedure TCodeEditor.SetDisplayText(I: sw_integer;const S: sw_astring);
begin
Core^.SetDisplayText(I,S);
end;
function TCodeEditor.GetDisplayText(I: sw_integer): string;
function TCodeEditor.GetDisplayText(I: sw_integer): sw_astring;
begin
GetDisplayText:=Core^.GetDisplayText(I);
end;
procedure TCodeEditor.SetLineText(I: sw_integer;const S: string);
procedure TCodeEditor.SetLineText(I: sw_integer;const S: sw_AString);
begin
Core^.SetLineText(I,S);
end;
procedure TCodeEditor.GetDisplayTextFormat(I: sw_integer;var DT,DF:string);
procedure TCodeEditor.GetDisplayTextFormat(I: sw_integer;var DT,DF:sw_astring);
begin
Core^.GetDisplayTextFormat(@Self,I,DT,DF);
end;
function TCodeEditor.GetLineFormat(I: sw_integer): string;
function TCodeEditor.GetLineFormat(I: sw_integer): sw_astring;
begin
GetLineFormat:=Core^.GetLineFormat(@Self,I);
end;
procedure TCodeEditor.SetLineFormat(I: sw_integer;const S: string);
procedure TCodeEditor.SetLineFormat(I: sw_integer;const S: sw_astring);
begin
Core^.SetLineFormat(@Self,I,S);
end;
@ -1053,12 +1068,12 @@ begin
Core^.DeleteLine(I);
end;
function TCodeEditor.InsertLine(LineNo: sw_integer; const S: string): PCustomLine;
function TCodeEditor.InsertLine(LineNo: sw_integer; const S: sw_astring): PCustomLine;
begin
InsertLine:=Core^.InsertLine(LineNo,S);
end;
procedure TCodeEditor.AddLine(const S: string);
procedure TCodeEditor.AddLine(const S: sw_astring);
begin
Core^.AddLine(S);
end;
@ -1283,7 +1298,7 @@ var
UndoTime : longint;
WasInserting,WasAutoBrackets,IsGrouped,HadefNoIndent : boolean;
MaxY,MinY : sw_integer;
Line : String;
Line, uText : Sw_AString;
procedure SetMinMax(y : sw_integer);
begin
@ -1321,6 +1336,7 @@ begin
begin
if not IsGrouped then
UndoTime:=TimeStamp;
uText:=GetText;
case action of
eaMoveCursor :
begin
@ -1330,9 +1346,8 @@ begin
eaInsertText :
begin
SetCurPtr(StartPos.X,StartPos.Y);
if assigned(text) then
for Temp := 1 to length(Text^) do
DelChar;
for Temp := 1 to length(uText) do
DelChar;
SetMinMax(StartPos.Y);
end;
eaDeleteText :
@ -1343,9 +1358,8 @@ begin
SetInsertMode(true);
WasAutoBrackets:=GetAutoBrackets;
SetAutoBrackets(false);
if assigned(text) then
for Temp := 1 to length(Text^) do
AddChar(Text^[Temp]);
for Temp := 1 to length(uText) do
AddChar(uText[Temp]);
SetAutoBrackets(WasAutoBrackets);
SetInsertMode(WasInserting);
SetMinMax(EndPos.Y);
@ -1359,15 +1373,14 @@ begin
SetInsertMode(false);
WasAutoBrackets:=GetAutoBrackets;
SetAutoBrackets(false);
if assigned(text) then
for Temp := 1 to length(Text^) do
begin
AddChar(Text^[Temp]);
if StartPos.X+Temp>Length(Line) then
Text^[Temp]:=' '
else
Text^[Temp]:=Line[StartPos.X+Temp];
end;
for Temp := 1 to length(uText) do
begin
AddChar(uText[Temp]);
if StartPos.X+Temp>Length(Line) then
uText[Temp]:=' '
else
uText[Temp]:=Line[StartPos.X+Temp];
end;
SetAutoBrackets(WasAutoBrackets);
SetInsertMode(WasInserting);
SetMinMax(EndPos.Y);
@ -1378,7 +1391,7 @@ begin
SetCurPtr(EndPos.X,EndPos.Y);
Line:=Copy(GetDisplayText(StartPos.Y),1,StartPos.X);
If Length(Line)<StartPos.X then
Line:=Line+CharStr(' ',StartPos.X-length(Line))+GetStr(Text);
Line:=Line+CharStr(' ',StartPos.X-length(Line))+uText;
SetDisplayText(StartPos.Y,Line+Copy(GetDisplayText(EndPos.Y),EndPos.X+1,255));
SetMinMax(EndPos.Y);
SetCurPtr(0,EndPos.Y);
@ -1392,7 +1405,7 @@ begin
WasInserting:=GetInsertMode;
SetInsertMode(true);
SetFlags(GetFlags or efNoIndent);
InsertLine(StartPos.Y,GetStr(Text));
InsertLine(StartPos.Y,uText);
SetInsertMode(WasInserting);
if not HadefNoIndent then
SetFlags(GetFlags and not efNoIndent);
@ -1455,7 +1468,7 @@ var
Temp,Idx,i,Last,Count : Longint;
StoredFlags : longint;
WasInserting,WasAutoBrackets,IsGrouped,ShouldInsertText : boolean;
Line : String;
Line,uText : sw_aString;
MaxY,MinY : sw_integer;
procedure SetMinMax(y : sw_integer);
begin
@ -1490,6 +1503,7 @@ begin
for Idx:=Last downto Last-Count+1 do
with Core^.RedoList^.At(Idx)^ do
begin
uText:=GetText;
case action of
eaMoveCursor :
begin
@ -1499,13 +1513,13 @@ begin
eaInsertText :
begin
SetCurPtr(startpos.x,startpos.y);
InsertText(GetStr(Text));
InsertText(uText);
SetMinMax(StartPos.Y);
end;
eaDeleteText :
begin
SetCurPtr(EndPos.X,EndPos.Y);
for Temp := 1 to length(GetStr(Text)) do
for Temp := 1 to length(uText) do
DelChar;
SetMinMax(EndPos.Y);
end;
@ -1517,15 +1531,14 @@ begin
SetInsertMode(false);
WasAutoBrackets:=GetAutoBrackets;
SetAutoBrackets(false);
if assigned(text) then
for Temp := 1 to length(Text^) do
begin
AddChar(Text^[Temp]);
if StartPos.X+Temp>Length(Line) then
Text^[Temp]:=' '
else
Text^[Temp]:=Line[StartPos.X+Temp];
end;
for Temp := 1 to length(uText) do
begin
AddChar(uText[Temp]);
if StartPos.X+Temp>Length(Line) then
uText[Temp]:=' '
else
uText[Temp]:=Line[StartPos.X+Temp];
end;
SetAutoBrackets(WasAutoBrackets);
SetInsertMode(WasInserting);
SetCurPtr(EndPos.X,EndPos.Y);
@ -1538,7 +1551,7 @@ begin
SetFlags(Flags);
InsertNewLine;
SetCurPtr(0,EndPos.Y);
Line:=GetStr(Text);
Line:=uText;
ShouldInsertText:=false;
for I:=1 to Length(Line) do
if Line[I]<>' ' then
@ -1557,7 +1570,7 @@ begin
if EndPos.Y=StartPos.Y-1 then
SetDisplayText(EndPos.Y,RExpand(
copy(GetDisplayText(EndPos.Y),1,EndPos.X),EndPos.X)
+GetStr(Text));
+uText);
SetCurPtr(EndPos.X,EndPos.Y);
SetMinMax(StartPos.Y);
SetMinMax(EndPos.Y);
@ -1722,7 +1735,7 @@ begin
UpdateAttrsRange:=Core^.UpdateAttrsRange(FromLine,ToLine,Attrs);
end;
procedure TCodeEditor.AddAction(AAction: byte; AStartPos, AEndPos: TPoint; AText: string;AFlags : longint);
procedure TCodeEditor.AddAction(AAction: byte; AStartPos, AEndPos: TPoint; AText: sw_astring;AFlags : longint);
begin
Core^.AddAction(AAction,AStartPos,AEndPos,AText,AFlags);
end;

File diff suppressed because it is too large Load Diff

View File

@ -154,8 +154,8 @@ type
procedure SetCurPtr(X,Y: sw_integer); virtual;
function GetLineCount: sw_integer; virtual;
function GetLine(LineNo: sw_integer): PCustomLine; virtual;
function GetLineText(Line: sw_integer): string; virtual;
function GetDisplayText(I: sw_integer): string; virtual;
function GetLineText(Line: sw_integer): sw_astring; virtual;
function GetDisplayText(I: sw_integer): sw_astring; virtual;
function GetLinkCount: sw_integer; virtual;
procedure GetLinkBounds(Index: sw_integer; var R: TRect); virtual;
function GetLinkFileID(Index: sw_integer): word; virtual;
@ -828,13 +828,13 @@ begin
{Abstract; used in wcedit unit ! }
GetLine:=nil;
end;
function THelpViewer.GetDisplayText(I: sw_integer): string;
function THelpViewer.GetDisplayText(I: sw_integer): sw_astring;
begin
GetDisplayText:=ExtractTabs(GetLineText(I),DefaultTabSize);
end;
function THelpViewer.GetLineText(Line: sw_integer): string;
var S: string;
function THelpViewer.GetLineText(Line: sw_integer): sw_astring;
var S: sw_astring;
begin
if HelpTopic=nil then S:='' else S:=HelpTopic^.GetLineText(Line);
GetLineText:=S;
@ -887,7 +887,7 @@ begin
begin
if Y=R.A.Y then StartX:=R.A.X else StartX:=Margin;
if Y=R.B.Y then EndX:=R.B.X else EndX:=High(S);
S:=S+copy(GetLineText(Y),StartX+1,EndX-StartX+1);
S:=S+copy(GetLineText(Y),StartX+1,EndX-StartX+1); { Note: AnsiString to ShortString convertino}
Inc(Y);
end;
GetLinkText:=S;
@ -1219,7 +1219,7 @@ var NormalColor, LinkColor,
B: TDrawBuffer;
DX,DY,X,Y,I,MinX,MaxX,ScreenX: sw_integer;
LastLinkDrawn,LastColorAreaDrawn: sw_integer;
S: string;
S: sw_astring;
R: TRect;
SelR : TRect;
C,Mask: word;
@ -1244,7 +1244,8 @@ begin
MoveChar(B,' ',NormalColor,Size.X);
if Y<GetLineCount then
begin
S:=copy(GetLineText(Y),Delta.X+1,High(S));
S:=GetLineText(Y);
S:=copy(S,Delta.X+1,Length(S));
S:=copy(S,1,MaxViewWidth);
MoveStr(B,S,NormalColor);

View File

@ -46,11 +46,14 @@ const
TempExt = '.tmp';
TempNameLen = 8;
{ Get DirSep and EOL from System unit, instead of redefining
{ Get DirSep and EOL from System unit, instead of redefining
here with tons of $ifdefs (KB) }
DirSep : AnsiChar = System.DirectorySeparator;
EOL : String[2] = System.LineEnding;
type
Sw_AString = AnsiString; { long lines in editor }
{Sw_AString = ShortString;} { 255 char lines in editor }
type
PByteArray = ^TByteArray;
@ -99,7 +102,8 @@ type
TFastBufStream = object(TBufStream)
constructor Init (FileName: FNameStr; Mode, Size: Word);
procedure Seek(Pos: Longint); virtual;
procedure Readline(var s:string;var linecomplete,hasCR : boolean);
procedure Readline(var S:ShortString;var linecomplete,hasCR : boolean);
procedure Readline(var S:AnsiString;var linecomplete,hasCR : boolean);
private
BasePos: longint;
end;
@ -119,7 +123,8 @@ type
function AtInt(Index: sw_integer): ptrint;
end;
procedure ReadlnFromStream(Stream: PStream; var s:string;var linecomplete,hasCR : boolean);
procedure ReadlnFromStream(Stream: PStream; var s:ShortString;var linecomplete,hasCR : boolean);
procedure ReadlnFromStream(Stream: PStream; var s:AnsiString;var linecomplete,hasCR : boolean);
function eofstream(s: pstream): boolean;
procedure ReadlnFromFile(var f : file; var S:string;
var linecomplete,hasCR : boolean;
@ -128,15 +133,20 @@ procedure ReadlnFromFile(var f : file; var S:string;
function Min(A,B: longint): longint;
function Max(A,B: longint): longint;
function CharStr(C: AnsiChar; Count: integer): string;
function CharStr(C: AnsiChar; Count: sw_integer): Sw_AString;
function UpcaseStr(const S: string): string;
function UpcaseStr(const S: AnsiString): AnsiString;
function LowCase(C: AnsiChar): AnsiChar;
function LowcaseStr(S: string): string;
function RExpand(const S: string; MinLen: byte): string;
function LowcaseStr(S: AnsiString): AnsiString;
function RExpand(const S: Sw_AString; MinLen: sw_integer): Sw_AString;
function LExpand(const S: string; MinLen: byte): string;
function LTrim(const S: string): string;
function LTrim(const S: AnsiString): AnsiString;
function RTrim(const S: string): string;
function RTrim(const S: AnsiString): AnsiString;
function Trim(const S: string): string;
function Trim(const S: AnsiString): AnsiString;
function IntToStr(L: longint): string;
function IntToStrL(L: longint; MinLen: sw_integer): string;
function IntToStrZ(L: longint; MinLen: sw_integer): string;
@ -232,10 +242,11 @@ begin
eofstream:=(s^.getpos>=s^.getsize);
end;
procedure ReadlnFromStream(Stream: PStream; var S:string;var linecomplete,hasCR : boolean);
procedure ReadlnFromStream(Stream: PStream; var S:ShortString;var linecomplete,hasCR : boolean);
var
c : AnsiChar;
i,pos : longint;
CurLen : longword;
begin
linecomplete:=false;
c:=#0;
@ -269,12 +280,54 @@ procedure ReadlnFromStream(Stream: PStream; var S:string;var linecomplete,hasCR
if c<>#10 then
stream^.seek(pos);
end;
if (c=#10) or eofstream(stream) then
linecomplete:=true;
if (c=#10) then
hasCR:=true;
setlength(s,i);
setlength(s,i);
end;
procedure ReadlnFromStream(Stream: PStream; var S:AnsiString;var linecomplete,hasCR : boolean);
var
c : AnsiChar;
i,pos : longint;
CurLen : longword;
begin
linecomplete:=false;
c:=#0;
i:=0;
CurLen:=256;
SetLength(S,CurLen);
{ this created problems for lines longer than 255 characters
now those lines are cutted into pieces without warning PM }
{ changed implicit 255 to High(S), so it will be automatically extended
when longstrings eventually become default - Gabor }
while (not eofstream(stream)) and (c<>#10) {and (i<High(S))} do
begin
stream^.read(c,sizeof(c));
if c<>#10 then
begin
inc(i);
s[i]:=c;
if (i mod 256)=0 then
begin
CurLen:=CurLen+256;
SetLength(S,CurLen);
end;
end;
end;
{ if there was a CR LF then remove the CR Dos newline style }
if (i>0) and (s[i]=#13) then
begin
dec(i);
end;
if (c=#13) and (not eofstream(stream)) then
stream^.read(c,sizeof(c));
if (c=#10) or eofstream(stream) then
linecomplete:=true;
if (c=#10) then
hasCR:=true;
setlength(s,i);
end;
procedure ReadlnFromFile(var f : file; var S:string;
@ -329,7 +382,7 @@ procedure ReadlnFromFile(var f : file; var S:string;
(LastSpacePos>1) then
begin
{$ifdef DEBUG}
setlength(s,i);
setlength(s,i);
filename:=strpas(@(filerec(f).Name));
DebugMessage(filename,'s='+s,1,1);
{$endif DEBUG}
@ -372,16 +425,18 @@ begin
if A<B then Min:=A else Min:=B;
end;
function CharStr(C: AnsiChar; Count: integer): string;
function CharStr(C: AnsiChar; Count: sw_integer): Sw_AString;
begin
if Count<=0 then
begin
CharStr:='';
exit;
end
{$if sizeof(sw_astring)>8 only if ShortString}
else if Count>255 then
Count:=255;
setlength(CharStr,Count);
{$endif};
SetLength(CharStr,Count);
FillChar(CharStr[1],Count,C);
end;
@ -397,7 +452,19 @@ begin
Setlength(UpcaseStr,length(s));
end;
function RExpand(const S: string; MinLen: byte): string;
function UpcaseStr(const S: AnsiString): AnsiString;
var
I: Longint;
begin
Setlength(UpcaseStr,length(s));
for I:=1 to length(S) do
if S[I] in ['a'..'z'] then
UpCaseStr[I]:=chr(ord(S[I])-32)
else
UpCaseStr[I]:=S[I];
end;
function RExpand(const S: Sw_AString; MinLen: sw_integer): Sw_AString;
begin
if length(S)<MinLen then
RExpand:=S+CharStr(' ',MinLen-length(S))
@ -446,6 +513,39 @@ begin
Trim:=Copy(S,i,j-i+1);
end;
function LTrim(const S: AnsiString): AnsiString;
var
i : longint;
begin
i:=1;
while (i<length(s)) and (s[i]=' ') do
inc(i);
LTrim:=Copy(s,i,length(S));
end;
function RTrim(const S: AnsiString): AnsiString;
var
i : longint;
begin
i:=length(s);
while (i>0) and (s[i]=' ') do
dec(i);
RTrim:=Copy(s,1,i);
end;
function Trim(const S: AnsiString): AnsiString;
var
i,j : longint;
begin
i:=1;
while (i<length(s)) and (s[i]=' ') do
inc(i);
j:=length(s);
while (j>0) and (s[j]=' ') do
dec(j);
Trim:=Copy(S,i,j-i+1);
end;
function IntToStr(L: longint): string;
var S: string;
begin
@ -666,6 +766,14 @@ begin
LowcaseStr:=S;
end;
function LowcaseStr(S: AnsiString): AnsiString;
var I: Longint;
begin
SetLength(LowcaseStr,length(S));
for I:=1 to length(S) do
LowcaseStr[I]:=Lowcase(S[I]);
end;
function BoolToStr(B: boolean; const TrueS, FalseS: string): string;
begin
@ -849,7 +957,7 @@ begin
end;
end;
procedure TFastBufStream.Readline(var s:string;var linecomplete,hasCR : boolean);
procedure TFastBufStream.Readline(var S:ShortString;var linecomplete,hasCR : boolean);
var
c : AnsiChar;
i,pos,StartPos : longint;
@ -914,11 +1022,78 @@ procedure TFastBufStream.Readline(var s:string;var linecomplete,hasCR : boolean)
if (c=#10) or (getpos>=getsize) then
linecomplete:=true;
if (c=#10) then
hasCR:=true;
setlength(s,i);
hasCR:=true;
setlength(s,i);
end;
procedure TFastBufStream.Readline(var S:AnsiString;var linecomplete,hasCR : boolean);
var
c : char;
i,pos,StartPos : longint;
charsInS : boolean;
Len,Idx : sw_integer;
begin
linecomplete:=false;
c:=#0;
i:=0;
CharsInS:=false;
Len:=bufend-bufptr;
Idx:=-1;
if Len>0 then
Idx:=IndexByte(buffer^[bufptr],Len, 10)+1; {find end of line}
Len:=Min(Idx,Len);
SetLength(S,Len);
if (Len > 0) and (GetPos+Len<GetSize) then
begin
StartPos:=GetPos;
system.move(buffer^[bufptr],S[1],Len); {get full line}
charsInS:=true;
end;
while (CharsInS or not (getpos>=getsize)) and (c<>#10) do
begin
if CharsInS then
c:=s[i+1]
else
read(c,sizeof(c));
if c<>#10 then
begin
inc(i);
if not CharsInS then
begin
if i > Len then
begin
Len:=Len+256; {constant grow}
SetLength(S,Len);
end;
s[i]:=c;
end;
end;
end;
if CharsInS then
begin
if c=#10 then
Seek(StartPos+i+1)
else
Seek(StartPos+i);
end;
{ if there was a CR LF then remove the CR Dos newline style }
if (i>0) and (s[i]=#13) then
begin
dec(i);
end;
if (c=#13) and (not (getpos>=getsize)) then
begin
read(c,sizeof(c));
end;
if (c=#10) or (getpos>=getsize) then
linecomplete:=true;
if (c=#10) then
hasCR:=true;
setlength(s,i);
end;
function TTextCollection.Compare(Key1, Key2: Pointer): Sw_Integer;
var K1: PString absolute Key1;