Browse Source

Fix for undo if chars are add in tab space

Margers 9 months ago
parent
commit
d0c33bfa5d
1 changed files with 7 additions and 2 deletions
  1. 7 2
      packages/ide/weditor.pas

+ 7 - 2
packages/ide/weditor.pas

@@ -3227,7 +3227,7 @@ end;
 
 
 function TCustomCodeEditor.InsertFrom(Editor: PCustomCodeEditor): Boolean;
 function TCustomCodeEditor.InsertFrom(Editor: PCustomCodeEditor): Boolean;
 var OK: boolean;
 var OK: boolean;
-    CP,RX,RSX,LineDelta,LineCount: Sw_integer;
+    CP,CI,RX,RSX,LineDelta,LineCount: Sw_integer;
     StartPos,DestPos,BPos,EPos: TPoint;
     StartPos,DestPos,BPos,EPos: TPoint;
     LineStartX,LineEndX: Sw_integer;
     LineStartX,LineEndX: Sw_integer;
     TabSize,CharIdxStart,CharIdxEnd: Sw_integer;
     TabSize,CharIdxStart,CharIdxEnd: Sw_integer;
@@ -3251,6 +3251,8 @@ begin
   begin
   begin
     if not (Clipboard=@Self) and IsFlagSet(efOverwriteBlocks) and InSelectionArea then
     if not (Clipboard=@Self) and IsFlagSet(efOverwriteBlocks) and InSelectionArea then
       DelSelect; {delete selection before paste}
       DelSelect; {delete selection before paste}
+    CI:=LinePosToCharIdx(CurPos.Y,CurPos.X);
+    CurPos.X:=CharIdxToLinePos(CurPos.Y,CI); {tab space adjustment}
     StartPos:=CurPos; DestPos:=CurPos;
     StartPos:=CurPos; DestPos:=CurPos;
     EPos:=CurPos;
     EPos:=CurPos;
     VerticalBlock:=Editor^.IsFlagSet(efVerticalBlocks);
     VerticalBlock:=Editor^.IsFlagSet(efVerticalBlocks);
@@ -3377,12 +3379,14 @@ begin
 end;
 end;
 
 
 function TCustomCodeEditor.InsertText(const S: sw_astring): Boolean;
 function TCustomCodeEditor.InsertText(const S: sw_astring): Boolean;
-var I: sw_integer;
+var I,CI: sw_integer;
     OldPos: TPoint;
     OldPos: TPoint;
     HoldUndo : boolean;
     HoldUndo : boolean;
     WasAutoBrackets : boolean;
     WasAutoBrackets : boolean;
 begin
 begin
   Lock;
   Lock;
+  CI:=LinePosToCharIdx(CurPos.Y,CurPos.X);
+  CurPos.X:=CharIdxToLinePos(CurPos.Y,CI); {tab space adjustment}
   OldPos:=CurPos;
   OldPos:=CurPos;
   HoldUndo:=GetStoreUndo;
   HoldUndo:=GetStoreUndo;
   WasAutoBrackets:=GetAutoBrackets;
   WasAutoBrackets:=GetAutoBrackets;
@@ -6150,6 +6154,7 @@ begin
       exit;
       exit;
     end;
     end;
 {$endif}
 {$endif}
+  SP.X:=CharIdxToLinePos(CurPos.Y,CI); {actual changes are going to be here (tab space adjustment)}
   if (CI>0) and (S[CI]=TAB) and not IsFlagSet(efUseTabCharacters) then
   if (CI>0) and (S[CI]=TAB) and not IsFlagSet(efUseTabCharacters) then
     begin
     begin
       if CI=1 then
       if CI=1 then