View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0038178 | Lazarus | IDE | public | 2020-12-07 08:05 | 2020-12-08 20:35 |
Reporter | OkobaPatino | Assigned To | Juha Manninen | ||
Priority | normal | Severity | minor | Reproducibility | always |
Status | resolved | Resolution | fixed | ||
Product Version | 2.1 (SVN) | ||||
Summary | 0038178: JCF set the cursor at the file beginning after each format | ||||
Description | With a clean trunk install, after formatting the file, the cursor will be set to first of the unit or project. | ||||
Tags | No tags attached. | ||||
Fixed in Revision | r64185 | ||||
LazTarget | - | ||||
Widgetset | |||||
Attached Files |
|
related to | 0038081 | closed | Juha Manninen | [patch] Jedi code format improvement. Added support for Threadvar in classes and records. |
|
It is working correctly in the recent version of Lazarus, I checked a version from December 1, and it works fine. Perhaps one of the changes in the past month broke it. |
|
December 1 was less than a week ago. There are no commits for JCF since then. The last one is r64166 from November 30 : Jedi Code Format: Fix access violation when parsing not closed IFDEF. Issue 0038146, patch from Domingo Galmés. Please check again. FYI: When looking for a guilty revision from a large number of commits, bisecting helps : https://wiki.freepascal.org/How_do_I_create_a_bug_report#Regression_caused_by_a_certain_revision It is basically a binary search algorithm over the revision history. Git has local history + a "git bisect" command which helps a lot. |
|
Sorry, I meant November. Yes probably @DomingoGP knows about this. I will try to find the exact commit, thanks for the help. |
|
I think I found the guilty one. SVN: trunk@64136 4005530d-fff6-0310-9dd1-cebe43e6787f Git: 4cf95127a17a5dad45fe83f172dbb20da3958f03 |
|
This patch keeps the cursor position ( Same line, same column), not same text, the JCF always can delete or add lines after formating. JCD_keep_cursor_position.patch (1,103 bytes)
From 3d5dd97f6bc50b19e99b5713ca51586401b49bad Mon Sep 17 00:00:00 2001 From: DomingoGP <dgalmesp@gmail.com> Date: Mon, 7 Dec 2020 11:42:22 +0100 Subject: [PATCH] Keeps cursor position when formatting all unit. --- components/jcf2/ReadWrite/EditorConverter.pas | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/components/jcf2/ReadWrite/EditorConverter.pas b/components/jcf2/ReadWrite/EditorConverter.pas index c02dd231a1..cd612aaa1b 100644 --- a/components/jcf2/ReadWrite/EditorConverter.pas +++ b/components/jcf2/ReadWrite/EditorConverter.pas @@ -136,15 +136,19 @@ begin end; procedure TEditorConverter.WriteToIDE(const pcUnit: TSourceEditorInterface; const psText: string); +var + lLogicalCaretXY:TPoint; begin if pcUnit = nil then exit; if psText <> fcConverter.InputCode then begin try + lLogicalCaretXY:=pcUnit.CursorTextXY; pcUnit.BeginUpdate; pcUnit.BeginUndoBlock; pcUnit.Lines.Text := psText; + pcUnit.CursorTextXY:=lLogicalCaretXY; pcUnit.Modified := True; finally pcUnit.EndUndoBlock; -- 2.29.1.windows.1 |
|
@DomingoGP Does this fix the undo issue? I just found out that this issue clears the undo history, so you can not undo after formatting code. |
|
> SVN: trunk@64136 4005530d-fff6-0310-9dd1-cebe43e6787f Thanks. I added the related issue. BTW, I don't even know what the long number with '-' means. It comes from SVN anyway, I also see it. > Git: 4cf95127a17a5dad45fe83f172dbb20da3958f03 The Git SHA1 ID is not useful here because it depends on how you got the revisions into Git. For example I use git-svn link and have different IDs. One change in the history changes all the IDs. FPC and Lazarus may switch to Git master later. Then the SHA1 ID matters. > I just found out that this issue clears the undo history Do you mean 0038081 + r64136 clears the undo history? How could it? It only affects JCF code but the undo history is built in Lazarus IDE+editor. |
|
I've got that ID from Git bisect. Should I share another one in the future? I do not know how that causes undo, but I tried to write code, format, and then hitting Ctrl+Z will not do anything. I reverted that commit, and they work fine, both undo and cursor. |
|
> I've got that ID from Git bisect. Should I share another one in the future? No, SVN revision is enough. Sequential revision numbers are a benefit of Subversion. Projects using Git as a master don't have it. |
|
The problem is in the line pcUnit.Lines.Text := psText; // removes undo history. The workarround is using replacetext instead of Lines.Text. This patch includes the previos that preserves the cursor position. The selection of all text is ugly but I don't know a better way for do it. in ReadWrite/EditorConverter.pas procedure TEditorConverter.WriteToIDE(const pcUnit: TSourceEditorInterface; const psText: string); var lLogicalCaretXY:TPoint; lStart,lEnd:TPoint; begin if pcUnit = nil then exit; if psText <> fcConverter.InputCode then begin try lLogicalCaretXY:=pcUnit.CursorTextXY; pcUnit.BeginUpdate; pcUnit.BeginUndoBlock; lStart.X:=0; //select all text. lStart.Y:=0; lEnd.X:=0; if pcUnit.LineCount>0 then lEnd.X:=length(pcUnit.Lines[pcUnit.LineCount-1])+1; lEnd.Y:=pcUnit.LineCount; //pcUnit.Lines.Text := psText; // removes undo history. pcUnit.ReplaceText(lStart,lEnd,psText); pcUnit.CursorTextXY:=lLogicalCaretXY; pcUnit.Modified := True; finally pcUnit.EndUndoBlock; pcUnit.EndUpdate; end; end; end; JCF_2_preserve_undo_history.patch (2,479 bytes)
From 3d5dd97f6bc50b19e99b5713ca51586401b49bad Mon Sep 17 00:00:00 2001 From: DomingoGP <dgalmesp@gmail.com> Date: Mon, 7 Dec 2020 11:42:22 +0100 Subject: [PATCH 1/2] Keeps cursor position when formatting all unit. --- components/jcf2/ReadWrite/EditorConverter.pas | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/components/jcf2/ReadWrite/EditorConverter.pas b/components/jcf2/ReadWrite/EditorConverter.pas index c02dd231a1..cd612aaa1b 100644 --- a/components/jcf2/ReadWrite/EditorConverter.pas +++ b/components/jcf2/ReadWrite/EditorConverter.pas @@ -136,15 +136,19 @@ begin end; procedure TEditorConverter.WriteToIDE(const pcUnit: TSourceEditorInterface; const psText: string); +var + lLogicalCaretXY:TPoint; begin if pcUnit = nil then exit; if psText <> fcConverter.InputCode then begin try + lLogicalCaretXY:=pcUnit.CursorTextXY; pcUnit.BeginUpdate; pcUnit.BeginUndoBlock; pcUnit.Lines.Text := psText; + pcUnit.CursorTextXY:=lLogicalCaretXY; pcUnit.Modified := True; finally pcUnit.EndUndoBlock; -- 2.29.1.windows.1 From 943151aa6f65fe8d00e9c25f84d7b213e1a0ded3 Mon Sep 17 00:00:00 2001 From: DomingoGP <dgalmesp@gmail.com> Date: Mon, 7 Dec 2020 14:12:46 +0100 Subject: [PATCH 2/2] Preserves undo history --- components/jcf2/ReadWrite/EditorConverter.pas | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/components/jcf2/ReadWrite/EditorConverter.pas b/components/jcf2/ReadWrite/EditorConverter.pas index cd612aaa1b..571ae84595 100644 --- a/components/jcf2/ReadWrite/EditorConverter.pas +++ b/components/jcf2/ReadWrite/EditorConverter.pas @@ -138,6 +138,7 @@ end; procedure TEditorConverter.WriteToIDE(const pcUnit: TSourceEditorInterface; const psText: string); var lLogicalCaretXY:TPoint; + lStart,lEnd:TPoint; begin if pcUnit = nil then exit; @@ -147,7 +148,14 @@ begin lLogicalCaretXY:=pcUnit.CursorTextXY; pcUnit.BeginUpdate; pcUnit.BeginUndoBlock; - pcUnit.Lines.Text := psText; + lStart.X:=0; //select all text. + lStart.Y:=0; + lEnd.X:=0; + if pcUnit.LineCount>0 then + lEnd.X:=length(pcUnit.Lines[pcUnit.LineCount-1])+1; + lEnd.Y:=pcUnit.LineCount; + //pcUnit.Lines.Text := psText; // removes undo history. + pcUnit.ReplaceText(lStart,lEnd,psText); pcUnit.CursorTextXY:=lLogicalCaretXY; pcUnit.Modified := True; finally -- 2.29.1.windows.1 |
|
@DomingoGP Can I ask why that happens? As it seems, you made the ThreadVar patch that removes the undo history. How was it working before that patch? |
|
@OkobaPatino Well as I said in the patch 0038081 "I have encountered a problem formatting the whole document, JCF insert blank lines in random position when tries to synchonize the editor text with the already formatted text. The old code tries to keep the original lines that have not changed, but it is enough for JCF to insert or delete a blank line for the synchronization not to work. I have changed the code and now it replaces all the code in the editor." The patch 0038081 also tries to resolve de formatting of the whole document, I admit that it would have been better to send two separate patches. Sorry. |
|
Thanks for the explanation. So there are three topics if I understood correctly: 1- Threadvar, fixed by your last patch. 2- Inserted blank lines, fixed by your last patch. 3- Cursor positions and Undo, caused by the 0000002. Maybe it is better to revert the 0000002 as it seems to replace the whole code or select all of it, and perhaps it is not a very good idea? |
|
I think the better is apply the JCF_2_preserve_undo_history.patch to the trunk without reverting the patch of threadvar. This solves all the problems with undo and cursor position. |
|
@JuhaManninen, Can you please apply this patch? JCF is broken right now in Trunk. |
|
Applied, thanks. |
Date Modified | Username | Field | Change |
---|---|---|---|
2020-12-07 08:05 | OkobaPatino | New Issue | |
2020-12-07 08:09 | OkobaPatino | Note Added: 0127392 | |
2020-12-07 10:11 | Juha Manninen | Note Added: 0127396 | |
2020-12-07 10:52 | OkobaPatino | Note Added: 0127400 | |
2020-12-07 11:28 | OkobaPatino | Note Added: 0127403 | |
2020-12-07 11:47 | Domingo Galmés | Note Added: 0127405 | |
2020-12-07 11:47 | Domingo Galmés | File Added: JCD_keep_cursor_position.patch | |
2020-12-07 12:21 | OkobaPatino | Note Added: 0127407 | |
2020-12-07 12:22 | OkobaPatino | Note Edited: 0127407 | View Revisions |
2020-12-07 12:30 | Juha Manninen | Relationship added | related to 0038081 |
2020-12-07 12:30 | Juha Manninen | Assigned To | => Juha Manninen |
2020-12-07 12:30 | Juha Manninen | Status | new => assigned |
2020-12-07 12:44 | Juha Manninen | Note Added: 0127409 | |
2020-12-07 12:45 | Juha Manninen | Note Edited: 0127409 | View Revisions |
2020-12-07 12:49 | OkobaPatino | Note Added: 0127412 | |
2020-12-07 13:56 | Juha Manninen | Note Added: 0127415 | |
2020-12-07 14:25 | Domingo Galmés | Note Added: 0127418 | |
2020-12-07 14:25 | Domingo Galmés | File Added: JCF_2_preserve_undo_history.patch | |
2020-12-07 14:59 | OkobaPatino | Note Added: 0127421 | |
2020-12-07 15:13 | Domingo Galmés | Note Added: 0127423 | |
2020-12-07 15:57 | OkobaPatino | Note Added: 0127425 | |
2020-12-07 16:56 | Domingo Galmés | Note Added: 0127426 | |
2020-12-08 15:32 | OkobaPatino | Note Added: 0127459 | |
2020-12-08 20:35 | Juha Manninen | Status | assigned => resolved |
2020-12-08 20:35 | Juha Manninen | Resolution | open => fixed |
2020-12-08 20:35 | Juha Manninen | Fixed in Revision | => r64185 |
2020-12-08 20:35 | Juha Manninen | LazTarget | => - |
2020-12-08 20:35 | Juha Manninen | Note Added: 0127464 |