I tried in Lazarus 2.2.2 (rev lazarus_2_2_2) FPC 3.2.2 x86_64-win64-win32/win64.Same thing in version 2.2.4.
Line 18 is deleted, this one:
Or am I missing some from the original post on this topic?Yes: "...with Ctrl+D on selected lines 15 to 17".
Or am I missing some from the original post on this topic?Yes: "...with Ctrl+D on selected lines 15 to 17".
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;
JCF? only if you use the Lazarus IDE.
JCF? only if you use the Lazarus IDE.