From e5afeb668f45e2067471d11d85b183ac3e91168e Mon Sep 17 00:00:00 2001 From: pierre Date: Wed, 29 Jan 2003 00:29:14 +0000 Subject: [PATCH] * attempt to fix webbugs 2346-2348 --- ide/weditor.pas | 65 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 21 deletions(-) diff --git a/ide/weditor.pas b/ide/weditor.pas index 83241867ad..fa8e3aacfa 100644 --- a/ide/weditor.pas +++ b/ide/weditor.pas @@ -535,7 +535,8 @@ type {a}function GetErrorMessage: string; virtual; {a}procedure SetErrorMessage(const S: string); virtual; {a}procedure AdjustSelection(DeltaX, DeltaY: sw_integer); - {a}procedure AdjustSelectionPos(CurPosX, CurPosY: sw_integer; DeltaX, DeltaY: sw_integer); + {a}procedure AdjustSelectionBefore(DeltaX, DeltaY: sw_integer); + {a}procedure AdjustSelectionPos(OldCurPosX, OldCurPosY: sw_integer; DeltaX, DeltaY: sw_integer); {a}procedure GetContent(ALines: PUnsortedStringCollection); virtual; {a}procedure SetContent(ALines: PUnsortedStringCollection); virtual; {a}function LoadFromStream(Stream: PFastBufStream): boolean; virtual; @@ -2631,26 +2632,30 @@ begin { Abstract } end; -procedure TCustomCodeEditor.AdjustSelectionPos(CurPosX, CurPosY: sw_integer; DeltaX, DeltaY: sw_integer); +procedure TCustomCodeEditor.AdjustSelectionPos(OldCurPosX, OldCurPosY: sw_integer; DeltaX, DeltaY: sw_integer); var CP: TPoint; begin if ValidBlock=false then Exit; - CP.X:=CurPosX; CP.Y:=CurPosY; + CP.X:=OldCurPosX; CP.Y:=OldCurPosY; if (PosToOfsP(SelStart)<=PosToOfsP(CP)) and (PosToOfsP(CP)SelEnd.Y) or (SelStart.X<=CP.X)) and + (CP.X<=SelEnd.X) then + Inc(SelEnd.X,DeltaX); + end + else if (CP.Y=SelEnd.Y+DeltaY) then + Inc(SelEnd.X,DeltaX); Inc(SelEnd.Y,DeltaY); - if (CP.Y=SelEnd.Y) and - ((SelStart.Y<>SelEnd.Y) or (SelStart.X<=CP.X)) and - (CP.X<=SelEnd.X) then - Inc(SelEnd.X,DeltaX); SelectionChanged; end else if (PosToOfsP(CP)<=PosToOfsP(SelStart)) then begin - { CurPos is BEFORE selection } + { OldCurPos is BEFORE selection } if (CP.Y=SelStart.Y) and (CP.Y=SelEnd.Y) and (DeltaY<0) then begin SelStart:=CurPos; SelEnd:=CurPos; @@ -2671,7 +2676,7 @@ begin end else begin - { CurPos is AFTER selection } + { OldCurPos is AFTER selection } { actually we don't have to do anything here } end; end; @@ -3235,7 +3240,16 @@ begin DrawView; end; +{ to be called if CurPos has already been changed } + procedure TCustomCodeEditor.AdjustSelection(DeltaX, DeltaY: sw_integer); +begin + AdjustSelectionPos(CurPos.X-DeltaX,CurPos.Y-DeltaY,DeltaX,DeltaY); +end; + +{ to be called if CurPos has not yet been changed } + +procedure TCustomCodeEditor.AdjustSelectionBefore(DeltaX, DeltaY: sw_integer); begin AdjustSelectionPos(CurPos.X,CurPos.Y,DeltaX,DeltaY); end; @@ -4829,14 +4843,14 @@ begin { obsolete IndentStr is taken care of by the Flags PM } Addaction(eaInsertLine,SCP,CurPos,CharStr(' ',i-1){IndentStr},GetFlags); SetStoreUndo(false); - AdjustSelection(CurPos.X-SCP.X,CurPos.Y-SCP.Y); + AdjustSelectionPos(SCP.X,SCP.Y,CurPos.X-SCP.X,CurPos.Y-SCP.Y); end else begin CalcIndent(CurPos.Y); if CurPos.Y=GetLineCount-1 then begin AddLine(IndentStr); - AdjustSelection(0,1); + AdjustSelectionBefore(0,1); LimitsChanged; SetStoreUndo(HoldUndo); UpdateAttrs(CurPos.Y,attrAll); @@ -4890,6 +4904,7 @@ begin DeleteLine(CurPos.Y); LimitsChanged; SetCurPtr(CI,CurPos.Y-1); + AdjustSelectionPos(Ci,CurPos.Y,CurPos.X-SCP.X,CurPos.Y-SCP.Y); end; end else @@ -4926,9 +4941,9 @@ begin SetStoreUndo(HoldUndo); Addaction(eaDeleteText,SCP,CurPos,Copy(S,CI,OI-CI),GetFlags); SetStoreUndo(false); + AdjustSelection(CurPos.X-SCP.X,CurPos.Y-SCP.Y); end; UpdateAttrs(CurPos.Y,attrAll); - AdjustSelection(CurPos.X-SCP.X,CurPos.Y-SCP.Y); DrawLines(CurPos.Y); SetStoreUndo(HoldUndo); SetModified(true); @@ -4952,17 +4967,22 @@ begin if CurPos.Y