mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-06-07 03:58:26 +02:00
IDE: Replace in files: show replaced lines in result. Issue #0007687
git-svn-id: trunk@39554 -
This commit is contained in:
parent
20025055f3
commit
1c66f2a2dd
@ -239,6 +239,7 @@ var
|
|||||||
LastReplaceColOffset: integer;// bytes added/deleted by replace in last line
|
LastReplaceColOffset: integer;// bytes added/deleted by replace in last line
|
||||||
TempSearch: string; // Temp Storage for the search string.
|
TempSearch: string; // Temp Storage for the search string.
|
||||||
RE: TRegExpr;
|
RE: TRegExpr;
|
||||||
|
Lines: String;
|
||||||
|
|
||||||
SrcEditValid: Boolean;// true if SrcEdit is valid
|
SrcEditValid: Boolean;// true if SrcEdit is valid
|
||||||
SrcEdit: TSourceEditorInterface;
|
SrcEdit: TSourceEditorInterface;
|
||||||
@ -328,6 +329,7 @@ var
|
|||||||
SrcEditStartPos, SrcEditEndPos: TPoint;
|
SrcEditStartPos, SrcEditEndPos: TPoint;
|
||||||
aLastLineLength: integer;
|
aLastLineLength: integer;
|
||||||
aLineCount: integer;
|
aLineCount: integer;
|
||||||
|
i: integer;
|
||||||
|
|
||||||
procedure GetSrcEditPos;
|
procedure GetSrcEditPos;
|
||||||
begin
|
begin
|
||||||
@ -398,6 +400,7 @@ var
|
|||||||
SrcEdit.SelectText(SrcEditStartPos.Y,SrcEditStartPos.X,
|
SrcEdit.SelectText(SrcEditStartPos.Y,SrcEditStartPos.X,
|
||||||
SrcEditEndPos.Y,SrcEditEndPos.X);
|
SrcEditEndPos.Y,SrcEditEndPos.X);
|
||||||
SrcEdit.Selection:=AReplace;
|
SrcEdit.Selection:=AReplace;
|
||||||
|
|
||||||
// count total replacements and adjust offsets
|
// count total replacements and adjust offsets
|
||||||
aLineCount:=LineEndCount(AReplace,aLastLineLength);
|
aLineCount:=LineEndCount(AReplace,aLastLineLength);
|
||||||
//debugln(['DoReplaceLine Replace="',dbgstr(AReplace),'" aLineCount=',aLineCount,' aLastLineLength=',aLastLineLength]);
|
//debugln(['DoReplaceLine Replace="',dbgstr(AReplace),'" aLineCount=',aLineCount,' aLastLineLength=',aLastLineLength]);
|
||||||
@ -418,8 +421,16 @@ var
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
LastReplaceLine:=FoundEndPos.Y;
|
LastReplaceLine:=FoundEndPos.Y;
|
||||||
inc(ReplaceLineOffset,aLineCount-(FoundEndPos.Y-FoundStartPos.Y));
|
|
||||||
|
|
||||||
|
Lines := '';
|
||||||
|
for i := SrcEditStartPos.Y to SrcEditStartPos.Y + aLineCount do
|
||||||
|
Lines := Lines + SrcEdit.Lines[i-1] + LineEnding;
|
||||||
|
Lines:=ChompOneLineEndAtEnd(Lines);
|
||||||
|
Progress.OnAddMatch(TheFileName,
|
||||||
|
Point(FoundStartPos.x, FoundStartPos.y + ReplaceLineOffset),
|
||||||
|
SrcEdit.CursorTextXY,Lines);
|
||||||
|
|
||||||
|
inc(ReplaceLineOffset,aLineCount-(FoundEndPos.Y-FoundStartPos.Y));
|
||||||
//DebugLn(['DoReplaceLine FoundStartPos=',dbgs(FoundStartPos),' FoundEndPos=',dbgs(FoundEndPos),' aLastLineLength=',aLastLineLength,' LastReplaceLine=',LastReplaceLine,' LastReplaceColOffset=',LastReplaceColOffset,' ReplaceLineOffset=',ReplaceLineOffset]);
|
//DebugLn(['DoReplaceLine FoundStartPos=',dbgs(FoundStartPos),' FoundEndPos=',dbgs(FoundEndPos),' aLastLineLength=',aLastLineLength,' LastReplaceLine=',LastReplaceLine,' LastReplaceColOffset=',LastReplaceColOffset,' ReplaceLineOffset=',ReplaceLineOffset]);
|
||||||
end else begin
|
end else begin
|
||||||
// change text in memory/disk
|
// change text in memory/disk
|
||||||
@ -442,6 +453,19 @@ var
|
|||||||
// save original position behind found position
|
// save original position behind found position
|
||||||
OriginalFile.LineColToPosition(FoundEndPos.Y,FoundEndPos.X,
|
OriginalFile.LineColToPosition(FoundEndPos.Y,FoundEndPos.X,
|
||||||
ReplacedTextOriginalPos);
|
ReplacedTextOriginalPos);
|
||||||
|
|
||||||
|
Lines:=copy(OriginalFile.GetLines(FoundStartPos.Y,FoundStartPos.Y), 1, FoundStartPos.X - 1) +
|
||||||
|
AReplace +
|
||||||
|
copy(OriginalFile.GetLines(FoundEndPos.Y,FoundEndPos.Y), FoundEndPos.x, MaxInt);
|
||||||
|
Lines:=ChompOneLineEndAtEnd(Lines);
|
||||||
|
aLineCount:=LineEndCount(AReplace,aLastLineLength);
|
||||||
|
if aLineCount = 0 then aLastLineLength := aLastLineLength + FoundStartPos.X;
|
||||||
|
Progress.OnAddMatch(TheFileName,
|
||||||
|
Point(FoundStartPos.x, FoundStartPos.y + ReplaceLineOffset),
|
||||||
|
Point(aLastLineLength, FoundStartPos.Y + aLineCount + ReplaceLineOffset),
|
||||||
|
Lines);
|
||||||
|
|
||||||
|
inc(ReplaceLineOffset,aLineCount-(FoundEndPos.Y-FoundStartPos.Y));
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -488,7 +512,6 @@ var
|
|||||||
Src: String;
|
Src: String;
|
||||||
NewMatchStartPos: PtrInt;
|
NewMatchStartPos: PtrInt;
|
||||||
NewMatchEndPos: PtrInt;
|
NewMatchEndPos: PtrInt;
|
||||||
Lines: String;
|
|
||||||
begin
|
begin
|
||||||
//debugln(['SearchInText TheFileName=',TheFileName,' SearchFor=',SearchFor,'" ReplaceText=',ReplaceText,'"']);
|
//debugln(['SearchInText TheFileName=',TheFileName,' SearchFor=',SearchFor,'" ReplaceText=',ReplaceText,'"']);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user