Yes its a bug.
While I was looking to fix this bug, I found that JCF leaks memory when it finds errors in the code to be formatted.
I have a patch almost ready that I will send to the issue tracker when it is ready and then I will send another one fixing this problem.
In the meantime if anyone wants to fix this bug here are the changes to fix it (patch copied from TortoiseSVN not sure if it can be applied directly). The final patch will probably not be identical, I will move the StrTrimLastEof function to jcfStringUtils.
Regards
Domingo
diff --git a/components/jcf2/IdePlugin/lazarus/jcfidemain.pas b/components/jcf2/IdePlugin/lazarus/jcfidemain.pas
index 3c151210ff..e79940a621 100644
--- a/components/jcf2/IdePlugin/lazarus/jcfidemain.pas
+++ b/components/jcf2/IdePlugin/lazarus/jcfidemain.pas
@@ -230,6 +230,26 @@ begin
LazarusIDE.DoOpenIDEOptions(TfFiles);
end;
+function StrTrimLastEndOfLine(const aStr:string):string;
+var
+ len:integer;
+ c:char;
+begin
+ len:=length(aStr);
+ // TRIM right spaces
+ // while (len>0) and (aStr[len]=' ') do
+ // dec(len);
+ if (len>0) and (aStr[len]=#10) then
+ begin
+ dec(len);
+ if (len>0) and (aStr[len]=#13) then
+ dec(len);
+ result:=Copy(aStr,1,len);
+ end
+ else
+ result:=aStr;
+end;
+
procedure TJcfIdeMain.DoFormatSelection(Sender: TObject);
var
srcEditor: TSourceEditorInterface;
@@ -252,7 +272,7 @@ var
BlockBegin, BlockEnd: TPoint;
fcConverter: TConverter;
lineStartOffset,lineEndOffset: integer;
- wi: integer;
+ wi,EndY: integer;
outputstr: string;
begin
if (SourceEditorManagerIntf = nil) or (SourceEditorManagerIntf.ActiveEditor = nil) then
@@ -278,6 +298,7 @@ begin
while (wI > 1) and (fcConverter.OutputCode[wI] in [#10, #13, ' ']) do
Dec(wI);
outputstr := Copy(fcConverter.OutputCode, 1, wI);
+//ShowMessage('['+outputstr+']'+IntToStr(BlockBegin.Y)+' '+IntToStr(BlockEnd.Y));
DiffMergeEditor(srcEditor,outputstr,BlockBegin.Y,BlockEnd.Y);
end
else
@@ -286,15 +307,25 @@ begin
BlockBegin := srcEditor.BlockBegin;
BlockBegin.X := 1; // full lines.
BlockEnd := srcEditor.BlockEnd;
+ EndY:=BlockEnd.Y;
if BlockEnd.X > 1 then
- BlockEnd.Y := BlockEnd.Y + 1;
+ BlockEnd.Y := BlockEnd.Y + 1
+ else
+ begin
+ if EndY>1 then
+ EndY:=EndY-1;
+ end;
BlockEnd.X := 1;
srcEditor.SelectText(BlockBegin, BlockEnd); //extend selection to full lines.
fcConverter.InputCode := srcEditor.GetText(True); // only selected text.
fcConverter.GuiMessages := true;
fcConverter.ConvertUsingFakeUnit;
if not fcConverter.ConvertError then
- DiffMergeEditor(srcEditor,fcConverter.OutputCode,BlockBegin.Y,BlockEnd.Y);
+ begin
+ outputstr:=StrTrimLastEndOfLine(fcConverter.OutputCode);
+//ShowMessage('['+outputstr+']'+IntToStr(BlockBegin.Y)+' '+IntToStr(EndY));
+ DiffMergeEditor(srcEditor,outputstr,BlockBegin.Y,EndY);
+ end;
end;
finally
fcConverter.Free;