From 5c215cd5244cc844399e0fab09cd04f8f1f774a9 Mon Sep 17 00:00:00 2001 From: Margers Date: Wed, 9 Oct 2024 13:22:39 +0000 Subject: [PATCH] Long long code editor lines --- packages/ide/fpmopts.inc | 18 +- packages/ide/fpviews.pas | 26 +-- packages/ide/wcedit.pas | 193 +++++++++--------- packages/ide/weditor.pas | 412 +++++++++++++++++++++++--------------- packages/ide/whlpview.pas | 17 +- packages/ide/wutils.pas | 205 +++++++++++++++++-- 6 files changed, 569 insertions(+), 302 deletions(-) diff --git a/packages/ide/fpmopts.inc b/packages/ide/fpmopts.inc index 8d36143d8b..bbeaed53e3 100644 --- a/packages/ide/fpmopts.inc +++ b/packages/ide/fpmopts.inc @@ -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; diff --git a/packages/ide/fpviews.pas b/packages/ide/fpviews.pas index 9b9d3fb205..1613fca63f 100644 --- a/packages/ide/fpviews.pas +++ b/packages/ide/fpviews.pas @@ -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 diff --git a/packages/ide/wcedit.pas b/packages/ide/wcedit.pas index 2104ff6c56..2f4bfae1d7 100644 --- a/packages/ide/wcedit.pas +++ b/packages/ide/wcedit.pas @@ -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'' 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)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; diff --git a/packages/ide/weditor.pas b/packages/ide/weditor.pas index f6d3ed2b60..62efe76d9d 100644 --- a/packages/ide/weditor.pas +++ b/packages/ide/weditor.pas @@ -67,7 +67,11 @@ const cmScrollOneDown = 51271; EditorTextBufSize = 32768; - MaxLineLength = 255; +{$if sizeof(sw_astring)>8} + MaxLineLength = 255; {Shortstring line length} +{$else} + MaxLineLength = 9997; {AnsiString max visible line} +{$endif} MaxLineCount = 2000000; CodeTemplateCursorChar = '|'; { AnsiChar to signal cursor pos in templates } @@ -249,7 +253,11 @@ type TEditorLineInfo = object(TObject) Editor: PCustomCodeEditor; +{$if sizeof(sw_astring)>8} Format : PString; +{$else} + Format : Sw_AString; +{$endif} BeginsWithAsm, EndsWithAsm : boolean; BeginsWithComment, @@ -261,8 +269,8 @@ type Fold: PFold; constructor Init(AEditor: PCustomCodeEditor); destructor Done; virtual; - function GetFormat: string; - procedure SetFormat(const AFormat: string); + function GetFormat: sw_astring; + procedure SetFormat(const AFormat: sw_astring); procedure SetFold(AFold: PFold); { Syntax information is now generated separately for each editor instance. This is not neccessary for a one-language IDE, but this unit contains @@ -279,9 +287,9 @@ type PCustomLine = ^TCustomLine; TCustomLine = object(TObject) - constructor Init(const AText: string; AFlags: longint); - {a}function GetText: string; virtual; - {a}procedure SetText(const AText: string); virtual; + constructor Init(const AText: sw_AString; AFlags: longint); + {a}function GetText: sw_AString; virtual; + {a}procedure SetText(const AText: sw_AString); virtual; {a}function GetEditorInfo(Editor: PCustomCodeEditor): PEditorLineInfo; virtual; {a}function GetFlags: longint; virtual; {a}procedure SetFlags(AFlags: longint); virtual; @@ -302,7 +310,11 @@ type TEditorAction = object(TObject) StartPos : TPoint; EndPos : TPoint; +{$if sizeof(sw_astring)>8} Text : PString; +{$else} + Text : Sw_AString; +{$endif} ActionCount : longint; Flags : longint; Action : byte; @@ -316,9 +328,11 @@ type the (probably) changed line & position information, so, we can still jump to the right position in the editor even when it is heavily modified - Gabor } - constructor init(act:byte; StartP,EndP:TPoint;Txt:String;AFlags : longint); + constructor init(act:byte; StartP,EndP:TPoint;Txt:Sw_AString;AFlags : longint); constructor init_group(act:byte); function is_grouped_action : boolean; + function GetText : sw_astring; + procedure SetText(AText : sw_astring); destructor done; virtual; end; @@ -414,26 +428,26 @@ type protected { Text & info storage abstraction } {a}procedure ISetLineFlagState(Binding: PEditorBinding; LineNo: sw_integer; Flag: longint; ASet: boolean); virtual; - {a}procedure IGetDisplayTextFormat(Binding: PEditorBinding; LineNo: sw_integer;var DT,DF:string); virtual; - {a}function IGetLineFormat(Binding: PEditorBinding; LineNo: sw_integer): string; virtual; - {a}procedure ISetLineFormat(Binding: PEditorBinding; LineNo: sw_integer;const S: string); virtual; + {a}procedure IGetDisplayTextFormat(Binding: PEditorBinding; LineNo: sw_integer;var DT,DF:sw_astring); virtual; + {a}function IGetLineFormat(Binding: PEditorBinding; LineNo: sw_integer): sw_astring; virtual; + {a}procedure ISetLineFormat(Binding: PEditorBinding; LineNo: sw_integer;const S: sw_astring); virtual; public { Text & info storage abstraction } function CharIdxToLinePos(Line,CharIdx: sw_integer): sw_integer; function LinePosToCharIdx(Line,X: sw_integer): sw_integer; {a}function GetLineCount: sw_integer; virtual; {a}function GetLine(LineNo: sw_integer): PCustomLine; virtual; - {a}function GetLineText(LineNo: sw_integer): string; virtual; - {a}procedure SetDisplayText(I: sw_integer;const S: string); virtual; - {a}function GetDisplayText(I: sw_integer): string; virtual; - {a}procedure SetLineText(I: sw_integer;const S: string); virtual; - procedure GetDisplayTextFormat(Editor: PCustomCodeEditor; I: sw_integer;var DT,DF:string); virtual; - function GetLineFormat(Editor: PCustomCodeEditor; I: sw_integer): string; virtual; - procedure SetLineFormat(Editor: PCustomCodeEditor; I: sw_integer;const S: string); virtual; + {a}function GetLineText(LineNo: sw_integer): sw_AString; virtual; + {a}procedure SetDisplayText(I: sw_integer;const S: sw_astring); virtual; + {a}function GetDisplayText(I: sw_integer): sw_astring; virtual; + {a}procedure SetLineText(I: sw_integer;const S: sw_AString); virtual; + procedure GetDisplayTextFormat(Editor: PCustomCodeEditor; I: sw_integer;var DT,DF:sw_astring); virtual; + function GetLineFormat(Editor: PCustomCodeEditor; I: sw_integer): sw_astring; virtual; + procedure SetLineFormat(Editor: PCustomCodeEditor; I: sw_integer;const S: sw_astring); virtual; {a}procedure DeleteAllLines; virtual; {a}procedure DeleteLine(I: sw_integer); virtual; - {a}function InsertLine(LineNo: sw_integer; const S: string): PCustomLine; virtual; - {a}procedure AddLine(const S: string); virtual; + {a}function InsertLine(LineNo: sw_integer; const S: sw_AString): PCustomLine; virtual; + {a}procedure AddLine(const S: sw_AString); virtual; {a}procedure GetContent(ALines: PUnsortedStringCollection); virtual; {a}procedure SetContent(ALines: PUnsortedStringCollection); virtual; public @@ -449,7 +463,7 @@ type Attrs: byte): sw_integer; virtual; public { Undo info storage } - {a}procedure AddAction(AAction: byte; AStartPos, AEndPos: TPoint; AText: string;AFlags : longint); virtual; + {a}procedure AddAction(AAction: byte; AStartPos, AEndPos: TPoint; AText: sw_astring;AFlags : longint); virtual; {a}procedure AddGroupedAction(AAction : byte); virtual; {a}procedure CloseGroupedAction(AAction : byte); virtual; {a}function GetUndoActionCount: sw_integer; virtual; @@ -527,17 +541,17 @@ type {a}function GetLine(LineNo: sw_integer): PCustomLine; virtual; {a}function CharIdxToLinePos(Line,CharIdx: sw_integer): sw_integer; virtual; {a}function LinePosToCharIdx(Line,X: sw_integer): sw_integer; virtual; - {a}function GetLineText(I: sw_integer): string; virtual; - {a}procedure SetDisplayText(I: sw_integer;const S: string); virtual; - {a}function GetDisplayText(I: sw_integer): string; virtual; - {a}procedure SetLineText(I: sw_integer;const S: string); virtual; - {a}procedure GetDisplayTextFormat(I: sw_integer;var DT,DF:string); virtual; - {a}function GetLineFormat(I: sw_integer): string; virtual; - {a}procedure SetLineFormat(I: sw_integer;const S: string); virtual; + {a}function GetLineText(I: sw_integer): sw_astring; virtual; + {a}procedure SetDisplayText(I: sw_integer;const S: sw_astring); virtual; + {a}function GetDisplayText(I: sw_integer): sw_astring; virtual; + {a}procedure SetLineText(I: sw_integer;const S: sw_AString); virtual; + {a}procedure GetDisplayTextFormat(I: sw_integer;var DT,DF:sw_astring); virtual; + {a}function GetLineFormat(I: sw_integer): sw_astring; virtual; + {a}procedure SetLineFormat(I: sw_integer;const S: sw_astring); virtual; {a}procedure DeleteAllLines; virtual; {a}procedure DeleteLine(I: sw_integer); virtual; - {a}function InsertLine(LineNo: sw_integer; const S: string): PCustomLine; virtual; - {a}procedure AddLine(const S: string); virtual; + {a}function InsertLine(LineNo: sw_integer; const S: sw_astring): PCustomLine; virtual; + {a}procedure AddLine(const S: sw_astring); virtual; {a}function GetErrorMessage: string; virtual; {a}procedure SetErrorMessage(const S: string); virtual; {a}procedure AdjustSelection(DeltaX, DeltaY: sw_integer); @@ -551,7 +565,7 @@ type function LoadFromFile(const AFileName: string): boolean; virtual; function SaveToFile(const AFileName: string): boolean; virtual; public - {a}function InsertFrom(Editor: PCustomCodeEditor): Boolean; virtual; + function InsertFrom(Editor: PCustomCodeEditor): Boolean; virtual; {a}function InsertText(const S: string): Boolean; virtual; public procedure FlagsChanged(OldFlags: longint); virtual; @@ -607,7 +621,7 @@ type {a}function UpdateAttrsRange(FromLine, ToLine: sw_integer; Attrs: byte): sw_integer; virtual; public { Undo info storage } - {a}procedure AddAction(AAction: byte; AStartPos, AEndPos: TPoint; AText: string;AFlags : longint); virtual; + {a}procedure AddAction(AAction: byte; AStartPos, AEndPos: TPoint; AText: sw_astring;AFlags : longint); virtual; {a}procedure AddGroupedAction(AAction : byte); virtual; {a}procedure CloseGroupedAction(AAction : byte); virtual; {a}function GetUndoActionCount: sw_integer; virtual; @@ -753,6 +767,7 @@ const RedoCmd : TCommandSet = ([cmRedo]); function ExtractTabs(S: string; TabSize: Sw_integer): string; +function ExtractTabs(S: AnsiString; TabSize: Sw_integer): AnsiString; function StdEditorDialog(Dialog: Integer; Info: Pointer): word; @@ -957,6 +972,28 @@ begin Trim:=RTrim(LTrim(S),true); end; +function LTrim(S: AnsiString): AnsiString; +begin + while (length(S)>0) and (S[1] in [#0,TAB,#32]) do + Delete(S,1,1); + LTrim:=S; +end; + +{ TAB are not same as spaces if UseTabs is set PM } +function RTrim(S: AnsiString;cut_tabs : boolean): AnsiString; +begin + while (length(S)>0) and + ((S[length(S)] in [#0,#32]) or + ((S[Length(S)]=TAB) and cut_tabs)) do + Delete(S,length(S),1); + RTrim:=S; +end; + +function Trim(S: AnsiString): AnsiString; +begin + Trim:=RTrim(LTrim(S),true); +end; + function EatIO: integer; begin EatIO:=IOResult; @@ -987,27 +1024,6 @@ begin StrToInt:=L; end; -function RExpand(const S: string; MinLen: byte): string; -begin - if length(S)8} GetFormat:=GetStr(Format); +{$else} + GetFormat:=Format; +{$endif} end; -procedure TEditorLineInfo.SetFormat(const AFormat: string); +procedure TEditorLineInfo.SetFormat(const AFormat: sw_astring); begin +{$if sizeof(sw_astring)>8} SetStr(Format,AFormat); +{$else} + Format:=AFormat; +{$endif} end; procedure TEditorLineInfo.SetFold(AFold: PFold); @@ -1510,9 +1553,13 @@ end; destructor TEditorLineInfo.Done; begin +{$if sizeof(sw_astring)>8} if Format<>nil then DisposeStr(Format); Format:=nil; +{$else} + Format:=''; +{$endif} SetFold(nil); inherited Done; end; @@ -1839,24 +1886,24 @@ begin Abstract; end; -procedure TCustomCodeEditorCore.IGetDisplayTextFormat(Binding: PEditorBinding; LineNo: sw_integer;var DT,DF:string); +procedure TCustomCodeEditorCore.IGetDisplayTextFormat(Binding: PEditorBinding; LineNo: sw_integer;var DT,DF:sw_astring); begin Abstract; end; -function TCustomCodeEditorCore.IGetLineFormat(Binding: PEditorBinding; LineNo: sw_integer): string; +function TCustomCodeEditorCore.IGetLineFormat(Binding: PEditorBinding; LineNo: sw_integer): sw_astring; begin Abstract; IGetLineFormat:=''; end; -procedure TCustomCodeEditorCore.ISetLineFormat(Binding: PEditorBinding; LineNo: sw_integer;const S: string); +procedure TCustomCodeEditorCore.ISetLineFormat(Binding: PEditorBinding; LineNo: sw_integer;const S: sw_astring); begin Abstract; end; function TCustomCodeEditorCore.CharIdxToLinePos(Line,CharIdx: sw_integer): sw_integer; -var S: string; +var S: sw_astring; TabSize,CP,RX,NextInc: sw_integer; begin S:=GetLineText(Line); @@ -1890,7 +1937,7 @@ begin end; function TCustomCodeEditorCore.LinePosToCharIdx(Line,X: sw_integer): sw_integer; -var S: string; +var S: sw_astring; TabSize,CP,RX: sw_integer; begin TabSize:=GetTabSize; @@ -1936,39 +1983,39 @@ begin GetLine:=nil; end; -function TCustomCodeEditorCore.GetLineText(LineNo: sw_integer): string; +function TCustomCodeEditorCore.GetLineText(LineNo: sw_integer): sw_astring; begin Abstract; GetLineText:=''; end; -procedure TCustomCodeEditorCore.SetDisplayText(I: sw_integer;const S: string); +procedure TCustomCodeEditorCore.SetDisplayText(I: sw_integer;const S: sw_astring); begin Abstract; end; -function TCustomCodeEditorCore.GetDisplayText(I: sw_integer): string; +function TCustomCodeEditorCore.GetDisplayText(I: sw_integer): sw_astring; begin Abstract; GetDisplayText:=''; end; -procedure TCustomCodeEditorCore.SetLineText(I: sw_integer;const S: string); +procedure TCustomCodeEditorCore.SetLineText(I: sw_integer;const S: sw_AString); begin Abstract; end; -procedure TCustomCodeEditorCore.GetDisplayTextFormat(Editor: PCustomCodeEditor; I: sw_integer;var DT,DF:string); +procedure TCustomCodeEditorCore.GetDisplayTextFormat(Editor: PCustomCodeEditor; I: sw_integer;var DT,DF:sw_astring); begin IGetDisplayTextFormat(SearchBinding(Editor),I,DT,DF); end; -function TCustomCodeEditorCore.GetLineFormat(Editor: PCustomCodeEditor; I: sw_integer): string; +function TCustomCodeEditorCore.GetLineFormat(Editor: PCustomCodeEditor; I: sw_integer): sw_astring; begin GetLineFormat:=IGetLineFormat(SearchBinding(Editor),I); end; -procedure TCustomCodeEditorCore.SetLineFormat(Editor: PCustomCodeEditor; I: sw_integer; const S: string); +procedure TCustomCodeEditorCore.SetLineFormat(Editor: PCustomCodeEditor; I: sw_integer; const S: sw_astring); begin ISetLineFormat(SearchBinding(Editor),I,S); end; @@ -1983,13 +2030,13 @@ begin Abstract; end; -function TCustomCodeEditorCore.InsertLine(LineNo: sw_integer; const S: string): PCustomLine; +function TCustomCodeEditorCore.InsertLine(LineNo: sw_integer; const S: sw_AString): PCustomLine; begin Abstract; InsertLine:=nil; { eliminate compiler warning } end; -procedure TCustomCodeEditorCore.AddLine(const S: string); +procedure TCustomCodeEditorCore.AddLine(const S: sw_AString); begin Abstract; end; @@ -2096,10 +2143,10 @@ var FirstCC,LastCC: TCharClass; InAsm,InComment,InSingleLineComment,InDirective,InString: boolean; X,ClassStart: Sw_integer; - SymbolConcat: string; - LineText,Format: string; + SymbolConcat: string; {this can be shortstring after all} + LineText,Format: sw_astring; - function MatchSymbol(const What, S: string): boolean; + function MatchSymbol(const What, S: sw_astring): boolean; var Match: boolean; begin Match:=false; @@ -2110,7 +2157,7 @@ var end; var MatchedSymbol: boolean; - MatchingSymbol: string; + MatchingSymbol: sw_astring; type TPartialType = (pmNone,pmLeft,pmRight,pmAny); function MatchesAnySpecSymbol(SClass: TSpecSymbolClass; PartialMatch: TPartialType): boolean; @@ -2287,7 +2334,7 @@ var procedure FormatWord(SClass: TCharClass; StartX:Sw_integer;EndX: Sw_integer); var C: byte; - WordS: string; + WordS: string; {Note: leave for now as ShortString} begin C:=0; WordS:=copy(LineText,StartX,EndX-StartX+1); @@ -2530,7 +2577,7 @@ begin (NextLI^.BeginsWithComment=LI^.EndsWithComment) and (NextLI^.BeginsWithDirective=LI^.EndsWithDirective) and (NextLI^.BeginCommentType=LI^.EndCommentType) and - (NextLI^.Format<>nil) then + (Length(NextLI^.GetFormat)>0) then Break; {$ifdef TEST_PARTIAL_SYNTAX} if (CurLineNr0) and (VerticalBlock=false) then begin InsertLine(DestPos.Y,''); @@ -3012,17 +3060,18 @@ begin if (LineDelta=LineCount-1) or VerticalBlock then LineEndX:=Editor^.SelEnd.X-1 else - LineEndX:=High(S); + LineEndX:=Length(S); CharIdxStart:=Editor^.LinePosToCharIdx(Editor^.SelStart.Y+LineDelta,LineStartX); CharIdxEnd:=Editor^.LinePosToCharIdx(Editor^.SelStart.Y+LineDelta,LineEndX); if LineEndX' ') do Inc(Shift); end; - SetLineText(CurPos.Y,RExpand(copy(S,1,CurPos.X+1),CurPos.X+1)+CharStr(' ',Shift)+copy(S,CurPos.X+2,High(S))); + SetLineText(CurPos.Y,RExpand(copy(S,1,CurPos.X+1),CurPos.X+1)+CharStr(' ',Shift)+copy(S,CurPos.X+2,Length(S))); SetCurPtr(CurPos.X+Shift,CurPos.Y); UpdateAttrs(CurPos.Y,attrAll); DrawLines(CurPos.Y); @@ -4129,7 +4178,7 @@ end; procedure TCustomCodeEditor.WordLeft; var X, Y: sw_integer; - Line: string; + Line: sw_astring; GotIt,FoundNonSeparator: boolean; begin X:=CurPos.X; @@ -4191,7 +4240,7 @@ end; procedure TCustomCodeEditor.WordRight; var X, Y: sw_integer; - Line: string; + Line: sw_astring; GotIt: boolean; begin X:=CurPos.X; Y:=CurPos.Y; GotIt:=false; @@ -4245,7 +4294,7 @@ end; procedure TCustomCodeEditor.LineEnd; var - s : string; + s : sw_astring; i : longint; begin if CurPos.Y0) and (s[i]=' ') do dec(i); + i:=Min(i,MaxLineLength); SetCurPtr(i,CurPos.Y); end else @@ -4355,13 +4405,14 @@ begin end; procedure TCustomCodeEditor.TextEnd; -var s : string; +var s : sw_astring; i : longint; begin s:=GetDisplayText(GetLineCount-1); i:=length(s); while (i>0) and (s[i]=' ') do dec(i); + i:=Min(i,MaxLineLength); SetCurPtr(i,GetLineCount-1); end; @@ -4515,7 +4566,7 @@ end; procedure TCustomCodeEditor.ChangeCaseArea(StartP,EndP: TPoint; CaseAction: TCaseAction); var Y,X: sw_integer; X1,X2: sw_integer; - S: string; + S: sw_astring; C: AnsiChar; StartPos : TPoint; HoldUndo : boolean; @@ -4680,7 +4731,7 @@ procedure TCustomCodeEditor.FindMatchingDelimiter(ScanForward: boolean); const OpenSymbols : string[6] = '[{(<''"'; CloseSymbols : string[6] = ']})>''"'; var SymIdx: integer; - LineText,LineAttr: string; + LineText,LineAttr: sw_astring; CurChar: AnsiChar; X,Y: sw_integer; LineCount: sw_integer; @@ -4757,7 +4808,7 @@ end; function TCustomCodeEditor.InsertNewLine: Sw_integer; var i,Ind: Sw_integer; - S,IndentStr: string; + S,IndentStr: Sw_astring; procedure CalcIndent(LineOver: Sw_integer); begin if (LineOver<0) or (LineOver>GetLineCount) or ((GetFlags and efNoIndent)<>0) then @@ -4808,7 +4859,7 @@ begin end; SetLineText(CurPos.Y,copy(S,1,CI-1)); CalcIndent(CurPos.Y); - S:=copy(S,CI,High(S)); + S:=copy(S,CI,Length(S)); i:=1; while (i<=length(s)) and (i<=length(IndentStr)) and (s[i]=' ') do inc(i); @@ -4874,7 +4925,7 @@ begin end; procedure TCustomCodeEditor.BackSpace; -var S,PreS: string; +var S,PreS: sw_astring; OI,CI,CP,Y,TX: Sw_integer; SCP,SC1 : TPoint; HoldUndo : Boolean; @@ -4930,7 +4981,7 @@ begin S:=GetLineText(CurPos.Y); OI:=LinePosToCharIdx(CurPos.Y,CurPos.X); CI:=LinePosToCharIdx(CurPos.Y,CP); - SetLineText(CurPos.Y,copy(S,1,CI-1)+copy(S,OI,High(S))); + SetLineText(CurPos.Y,copy(S,1,CI-1)+copy(S,OI,Length(S))); SetCurPtr(CP,CurPos.Y); SetStoreUndo(HoldUndo); Addaction(eaDeleteText,SCP,CurPos,Copy(S,CI,OI-CI),GetFlags); @@ -4945,7 +4996,7 @@ begin end; procedure TCustomCodeEditor.DelChar; -var S: string; +var S: sw_astring; SDX,SDY,CI : sw_integer; HoldUndo : boolean; SCP : TPoint; @@ -4991,7 +5042,7 @@ begin if CharIdxToLinePos(Curpos.y,ci-1)=Curpos.x-1 then Delete(S,Ci,1) else - S:=Copy(S,1,CI-1)+CharStr(' ',GetTabSize-1)+Copy(S,CI+1,High(S)); + S:=Copy(S,1,CI-1)+CharStr(' ',GetTabSize-1)+Copy(S,CI+1,Length(S)); SetStoreUndo(HoldUndo); Addaction(eaDeleteText,CurPos,CurPos,#9,GetFlags); SDX:=-1; @@ -5079,7 +5130,7 @@ begin end; procedure TCustomCodeEditor.DelStart; -var S: string; +var S: sw_astring; OI: Sw_integer; HoldUndo : Boolean; SCP : TPoint; @@ -5093,7 +5144,7 @@ begin if (S<>'') and (CurPos.X<>0) then begin OI:=LinePosToCharIdx(CurPos.Y,CurPos.X); - SetLineText(CurPos.Y,copy(S,OI,High(S))); + SetLineText(CurPos.Y,copy(S,OI,Length(S))); SetCurPtr(0,CurPos.Y); SetStoreUndo(HoldUndo); Addaction(eaDeleteText,SCP,CurPos,copy(S,1,OI-1),GetFlags); @@ -5108,7 +5159,7 @@ begin end; procedure TCustomCodeEditor.DelEnd; -var S: string; +var S: sw_astring; OI: Sw_integer; HoldUndo : Boolean; SCP : TPoint; @@ -5125,9 +5176,9 @@ begin SetLineText(CurPos.Y,copy(S,1,OI-1)); SetCurPtr(CurPos.X,CurPos.Y); SetStoreUndo(HoldUndo); - Addaction(eaDeleteText,SCP,CurPos,copy(S,OI,High(S)),GetFlags); + Addaction(eaDeleteText,SCP,CurPos,copy(S,OI,Length(S)),GetFlags); SetStoreUndo(false); - AdjustSelectionPos(CurPos.X+1,CurPos.Y,-length(copy(S,OI,High(S)))+1,0); + AdjustSelectionPos(CurPos.X+1,CurPos.Y,-length(copy(S,OI,Length(S)))+1,0); UpdateAttrs(CurPos.Y,attrAll); DrawLines(CurPos.Y); SetModified(true); @@ -5140,7 +5191,7 @@ procedure TCustomCodeEditor.DelLine; var HoldUndo : boolean; SP : TPoint; - S : String; + S : Sw_AString; begin if IsReadOnly then Exit; Lock; @@ -5171,15 +5222,17 @@ end; function TCustomCodeEditor.GetCurrentWordArea(var StartP,EndP: TPoint): boolean; const WordChars = ['A'..'Z','a'..'z','0'..'9','_']; var P : TPoint; - S : String; - StartPos,EndPos : byte; + S : Sw_AString; + StartPos,EndPos : sw_integer; OK: boolean; begin P:=CurPos; S:=GetLineText(P.Y); StartPos:=P.X+1; EndPos:=StartPos; - OK:=(S[StartPos] in WordChars); + Ok:=false; + if Length(S)>=StartPos then + OK:=(S[StartPos] in WordChars); if OK then begin While (StartPos>1) and (S[StartPos-1] in WordChars) do @@ -5193,7 +5246,7 @@ begin end; function TCustomCodeEditor.GetCurrentWord : string; -var S: string; +var S: sw_astring; StartP,EndP: TPoint; begin if GetCurrentWordArea(StartP,EndP)=false then @@ -5203,7 +5256,7 @@ begin S:=GetLineText(StartP.Y); S:=copy(S,StartP.X+1,EndP.X-StartP.X+1); end; - GetCurrentWord:=S; + GetCurrentWord:=S; {Note: AnsiString to ShortString convertion} end; procedure TCustomCodeEditor.StartSelect; @@ -5239,7 +5292,7 @@ end; procedure TCustomCodeEditor.DelSelect; var LineDelta, LineCount, CurLine: Sw_integer; StartX,EndX,LastX: Sw_integer; - S: string; + S,Z: sw_astring; SPos : TPoint; begin if IsReadOnly or (ValidBlock=false) then Exit; @@ -5256,7 +5309,7 @@ begin StartX:=SelStart.X; EndX:=SelEnd.X; SetDisplayText(CurLine,RExpand(copy(S,1,StartX),StartX) - +copy(S,EndX+1,High(S))); + +copy(S,EndX+1,Length(S))); if GetStoreUndo then begin SPos.X:=StartX; @@ -5272,13 +5325,14 @@ begin S:=GetDisplayText(CurLine); StartX:=SelStart.X; EndX:=SelEnd.X; + Z:=GetDisplayText(CurLine+LineCount-1); SetDisplayText(CurLine,RExpand(copy(S,1,StartX),StartX) - +copy(GetDisplayText(CurLine+LineCount-1),EndX+1,High(S))); + +copy(Z,EndX+1,Length(Z))); if GetStoreUndo then begin SPos.X:=StartX; SPos.Y:=CurLine; - AddAction(eaDeleteText,SPos,SPos,Copy(S,StartX+1,High(S)),GetFlags); + AddAction(eaDeleteText,SPos,SPos,Copy(S,StartX+1,Length(S)),GetFlags); S:=GetDisplayText(CurLine+LineCount-1); end; Inc(CurLine); @@ -5292,7 +5346,7 @@ begin end; if GetStoreUndo then begin - AddAction(eaInsertText,SPos,SPos,Copy(S,EndX+1,High(S)),GetFlags); + AddAction(eaInsertText,SPos,SPos,Copy(S,EndX+1,Length(S)),GetFlags); end; end; HideSelect; @@ -5360,7 +5414,7 @@ end; procedure TCustomCodeEditor.IndentBlock; var ey,i,Indlen : Sw_Integer; - S,Ind : String; + S,Ind : Sw_AString; Pos : Tpoint; WasPersistentBlocks : boolean; begin @@ -5434,7 +5488,7 @@ end; procedure TCustomCodeEditor.UnindentBlock; var ey,i,j,k,indlen : Sw_integer; - S : String; + S : Sw_AString; Pos : TPoint; WasPersistentBlocks : boolean; begin @@ -5621,7 +5675,8 @@ begin end; procedure TCustomCodeEditor.ExpandCodeTemplate; -var Line,ShortCutInEditor,ShortCut: string; +var Line : sw_astring; + ShortCutInEditor,ShortCut: string; X,Y,I,LineIndent: sw_integer; CodeLines: PUnsortedStringCollection; CanJump: boolean; @@ -5715,7 +5770,7 @@ end; procedure TCustomCodeEditor.AddChar(C: AnsiChar); const OpenBrackets : string[10] = '[({'; CloseBrackets : string[10] = '])}'; -var S,SC,TabS: string; +var S,SC,TabS: sw_astring; BI: byte; CI,TabStart,LocTabSize : Sw_integer; SP: TPoint; @@ -5754,11 +5809,13 @@ begin SetLineText(CurPos.Y,S); end; CI:=LinePosToCharIdx(CurPos.Y,CurPos.X); +{$if sizeof(sw_astring)>8 only if ShortString} if CI>High(S) then begin Unlock; exit; end; +{$endif} if (CI>0) and (S[CI]=TAB) and not IsFlagSet(efUseTabCharacters) then begin if CI=1 then @@ -5767,17 +5824,17 @@ begin TabStart:=CharIdxToLinePos(CurPos.Y,CI-1)+1; if SC=Tab then TabS:=Tab else TabS:=CharStr(' ',CurPos.X-TabStart); - SetLineText(CurPos.Y,copy(S,1,CI-1)+TabS+SC+copy(S,CI+1,High(S))); + SetLineText(CurPos.Y,copy(S,1,CI-1)+TabS+SC+copy(S,CI+1,Length(S))); SetCurPtr(CharIdxToLinePos(CurPos.Y,CI+length(TabS)+length(SC)),CurPos.Y); end else begin if Overwrite and (CI<=length(S)) then begin - SetLineText(CurPos.Y,copy(S,1,CI-1)+SC+copy(S,CI+length(SC),High(S))); + SetLineText(CurPos.Y,copy(S,1,CI-1)+SC+copy(S,CI+length(SC),Length(S))); end else - SetLineText(CurPos.Y,copy(S,1,CI-1)+SC+copy(S,CI,High(S))); + SetLineText(CurPos.Y,copy(S,1,CI-1)+SC+copy(S,CI,Length(S))); SetCurPtr(CharIdxToLinePos(CurPos.Y,CI+length(SC)),CurPos.Y); end; { must be before CloseBrackets !! } @@ -5918,7 +5975,7 @@ end; function TCustomCodeEditor.ClipCopyWin: Boolean; var OK,ShowInfo: boolean; p,p2 : PAnsiChar; - s : string; + s : sw_astring; i,str_begin,str_end,NumLines,PcLength : longint; begin NumLines:=SelEnd.Y-SelStart.Y; @@ -5942,7 +5999,7 @@ begin s:=GetLineText(i); str_begin:=LinePosToCharIdx(i,SelStart.X); if SelEnd.Y>SelStart.Y then - str_end:=High(S) + str_end:=Length(S) else str_end:=LinePosToCharIdx(i,SelEnd.X)-1; s:=copy(s,str_begin,str_end-str_begin+1); @@ -6087,12 +6144,14 @@ procedure TCustomCodeEditor.Find; var FindRec: TFindDialogRec; DoConf: boolean; + CurrentWord : string; begin with FindRec do begin Find := FindStr; - if GetCurrentWord<>'' then - Find:=GetCurrentWord; + CurrentWord:=GetCurrentWord; + if CurrentWord<>'' then + Find:=CurrentWord; {$ifdef TEST_REGEXP} Options := ((FindFlags and ffmOptionsFind) shr ffsOptions) or ((FindFlags and ffUseRegExp) shr ffsUseRegExpFind); @@ -6174,7 +6233,7 @@ begin end; procedure TCustomCodeEditor.DoSearchReplace; -var S: string; +var S: sw_astring; DX,DY,P,Y,X: sw_integer; Count: sw_integer; Found,CanExit: boolean; @@ -6196,7 +6255,7 @@ var S: string; BT : BTable; Overwriting : boolean; - function ContainsText(const SubS:string;var S: string; Start: Sw_integer): Sw_integer; + function ContainsText(const SubS:string;var S: sw_astring; Start: Sw_integer): Sw_integer; var P: Sw_Integer; begin @@ -6345,8 +6404,8 @@ begin {$ifdef TEST_REGEXP} if UseRegExp then begin - getmem(findstrpchar,length(Copy(S,X+1,high(S)))+1); - strpcopy(findstrpchar,Copy(S,X+1,high(S))); + getmem(findstrpchar,length(Copy(S,X+1,Length(S)))+1); + strpcopy(findstrpchar,Copy(S,X+1,Length(S))); { If start of line is required do check other positions PM } if (FindStr[1]='^') and (X<>0) then Found:=false @@ -6865,7 +6924,7 @@ begin end; function TCustomCodeEditorCore.LoadFromStream(Editor: PCustomCodeEditor; Stream: PFastBufStream): boolean; -var S: string; +var S: sw_AString; AllLinesComplete,LineComplete,hasCR,OK: boolean; begin DeleteAllLines; @@ -6901,7 +6960,7 @@ begin end; function TCustomCodeEditorCore.SaveAreaToStream(Editor: PCustomCodeEditor; Stream: PStream; StartP,EndP: TPoint): boolean; -var S: string; +var S: sw_astring; OK: boolean; Line: Sw_integer; begin @@ -6927,7 +6986,7 @@ begin S:=CompressUsingTabs(S,TabSize); } if Line=EndP.Y then S:=copy(S,1,LinePosToCharIdx(Line,EndP.X)); - if Line=StartP.Y then S:=copy(S,LinePosToCharIdx(Line,StartP.X),High(S)); + if Line=StartP.Y then S:=copy(S,LinePosToCharIdx(Line,StartP.X),Length(S)); Stream^.Write(S[1],length(S)); if Line8} + GetText:=GetStr(Text); +{$else} + GetText:=Text; +{$endif} +end; + +procedure TEditorAction.SetText(AText : sw_astring); +var st : string; +begin +{$if sizeof(sw_astring)>8} + SetStr(Text,AText); +{$else} + Text:=AText; +{$endif} +end; + destructor TEditorAction.done; begin - DisposeStr(Text); +{$if sizeof(sw_astring)>8} + if assigned(Text) then + DisposeStr(Text); + Text:=nil; +{$else} + Text:=''; +{$endif} inherited done; end; @@ -6977,7 +7062,8 @@ end; procedure TEditorInputLine.HandleEvent(var Event : TEvent); var - s,s2 : string; + s : sw_astring; + st : string; {need to be shortstring for InputLine} i : longint; begin If (Event.What=evKeyDown) then @@ -6987,7 +7073,7 @@ begin Assigned(FindReplaceEditor) then Begin s:=FindReplaceEditor^.GetDisplayText(FindReplaceEditor^.CurPos.Y); - i:=FindReplaceEditor^.CurPos.X; + i:=Min(FindReplaceEditor^.CurPos.X+1,length(s)); {finds beginning of word} if i>0 then while s[i] in ['a'..'z','A'..'Z','0'..'9','_'] do @@ -6997,23 +7083,24 @@ begin end; inc(i); {step out of white space} + if i0) and (length(s)>=i+length(Data^)) then + i:=pos(Data^,st); + if (i>0) and (length(st)>=i+length(Data^)) then begin - s:=Data^+s[i+length(Data^)]; + st:=Data^+st[i+length(Data^)]; If not assigned(validator) or - Validator^.IsValidInput(s,False) then + Validator^.IsValidInput(st,False) then Begin - Event.CharCode:=s[length(s)]; + Event.CharCode:=st[length(st)]; Event.Scancode:=0; Inherited HandleEvent(Event); End; @@ -7028,7 +7115,7 @@ begin s:=Clipboard^.GetDisplayText(i); i:=Clipboard^.SelStart.X; if i>0 then - s:=copy(s,i+1,high(s)); + s:=copy(s,i+1,length(s)); if (Clipboard^.SelStart.Y=Clipboard^.SelEnd.Y) then begin i:=Clipboard^.SelEnd.X-i; @@ -7036,9 +7123,9 @@ begin end; for i:=1 to length(s) do begin - s2:=Data^+s[i]; + st:=Data^+s[i]; If not assigned(validator) or - Validator^.IsValidInput(s2,False) then + Validator^.IsValidInput(st,False) then Begin Event.What:=evKeyDown; Event.CharCode:=s[i]; @@ -7068,7 +7155,6 @@ begin Clipboard^.SelStart:=Clipboard^.CurPos; Clipboard^.InsertText(s); Clipboard^.SelEnd:=Clipboard^.CurPos; - s2:=GetStr(Data); { now remove the selected part } Event.keyCode:=kbDel; inherited HandleEvent(Event); @@ -7079,8 +7165,8 @@ begin End else Inherited HandleEvent(Event); - s:=getstr(data); - Message(Owner,evBroadCast,cminputlinelen,pointer(length(s))); + st:=getstr(data); + Message(Owner,evBroadCast,cmInputLineLen,pointer(Length(st))); end; procedure TSearchHelperDialog.HandleEvent(var Event : TEvent); diff --git a/packages/ide/whlpview.pas b/packages/ide/whlpview.pas index 8c20530f6c..3fc2b4e771 100644 --- a/packages/ide/whlpview.pas +++ b/packages/ide/whlpview.pas @@ -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=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#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 A8 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)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 (i0) 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)) 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;