Recent

Author Topic: Tabs in Source Editor  (Read 4911 times)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9754
  • Debugger - SynEdit - and more
    • wiki
Re: Tabs in Source Editor
« Reply #15 on: April 17, 2021, 04:13:49 pm »
OK, so if anyone wants to run this in a debugger...

synedit.pp  line 8670 in
procedure TCustomSynEdit.DoTabKey;
Code: Pascal  [Select][+][-]
  1.     if SelAvail and (not FBlockSelection.Persistent) and (eoOverwriteBlock in fOptions2) then begin
  2.       SetSelTextExternal(Spaces);
  3.     end
  4.     else begin
  5.       FCaret.IncAutoMoveOnEdit;
  6.       FTheLinesView.EditInsert(FCaret.BytePos, FCaret.LinePos, Spaces);
  7.       FCaret.DecAutoMoveOnEdit;
  8.       Include(fStateFlags, sfEnsureCursorPosForEditRight);
  9.     end;
  10.  
This is the code that actually inserts the text.

You may want to step into
    IncAutoMoveOnEdit
and while in class "TSynEditCaret" watch the value of "FLinePos"
And maybe also...
Code: Pascal  [Select][+][-]
  1.     FLinePos: Integer;     // 1 based
  2.     FCharPos: Integer;     // 1 based
  3.     FBytePos, FBytePosOffset: Integer;     // 1 based
  4.     FViewedLineCharPos: TPoint;
  5.     FOldLinePos: Integer; // 1 based
  6.     FOldCharPos: Integer; // 1 based
  7.  

You could set a watchpoint at  "FLinePos" => that would give you the exact pos where it will be changed.


If the watchpoint does not work, you want breakpoints at the entry of the following functions:
syneditpointclasses.pas  line 1180   TSynEditCaret.DoLinesEdited
syneditpointclasses.pas  line 1360   TSynEditCaret.InternalSetLineByterPos

You should enter DoLinesEdited first.
It should calculate the new X pos and call InternalSetLineByterPos with the existing Y and the new X.

Step through InternalSetLineByterPos, and see where the Y gets changed.


The watchpoint will have one major advantage.
If Y is not changed by the code setting the caret pos, but if some other code writes to the wrong memory, and hits the Y pos, then only a watchpoint will get us there.



trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 10.2 user
Re: Tabs in Source Editor
« Reply #16 on: April 18, 2021, 04:34:40 am »
Can you none the less try with  -O-1 or even -O-2 or -O2

Issue occurs with each of those. Logs attached named for each opt level.

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 10.2 user
Re: Tabs in Source Editor
« Reply #17 on: April 18, 2021, 04:46:40 am »
OK, so if anyone wants to run this in a debugger...

Sure... I'm guessing this needs some preparatory steps (compiling Lazarus with debug flags, running Lazarus from lldb), so if you tell me what they are, I'll be happy to follow.

(Old C programmers tend to use WriteLn()/NSLog() for debugging Pascal ;))

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9754
  • Debugger - SynEdit - and more
    • wiki
Re: Tabs in Source Editor
« Reply #18 on: April 18, 2021, 01:14:31 pm »
Oh dear, yes M1....
I don't do much lldb myself. So I would have to look up each and every command myself.

But...

Compiling the IDE for debugging
-gw -godwarfsets

Also install the package "LazDebuggerLldb" => The one *without* any "FP" in the name.
Then after rebuild in menu Tools > Option > debugger > backend: Choose the lldb debugger.
- No watchpoints.
- no pascal expression/operators in watches. But should do plain variable names
- "self" needs to be "this"
In other worlds, welcome to c++

Open the project ide/lazarus.lpi
Set your breakpoints
Run with F9

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: Tabs in Source Editor
« Reply #19 on: April 19, 2021, 07:31:20 am »
The patch is attached to the bug report.
I hope someone will take the ownership to test all available FPC versions before reporting it as FPC bug.

It is interesting that AdjustPoint() at TSynEditSelection.DoLinesEdited() has "inline" commented out
« Last Edit: April 19, 2021, 07:34:22 am by skalogryz »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9754
  • Debugger - SynEdit - and more
    • wiki
Re: Tabs in Source Editor
« Reply #20 on: April 19, 2021, 08:01:23 pm »
I moved the issue to the FPC project.


I applied the workaround.
« Last Edit: April 19, 2021, 08:05:57 pm by Martin_fr »

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: Tabs in Source Editor
« Reply #21 on: April 19, 2021, 08:05:49 pm »
if the bug is confirmed with the latest FPC release, would it make sense to actually apply the patch (adding the FPC version check, with the assumption the issue is fixed with the next FPC release)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9754
  • Debugger - SynEdit - and more
    • wiki
Re: Tabs in Source Editor
« Reply #22 on: April 19, 2021, 08:07:03 pm »
You answered to fast. I was still busy....

Edited the previous reply of mine

ChrisR

  • Full Member
  • ***
  • Posts: 247
Re: Tabs in Source Editor
« Reply #23 on: April 19, 2021, 11:39:07 pm »
Jonas has fixed this with the latest SVN. Thanks to all for the rapid fix!
  https://bugs.freepascal.org/view.php?id=38766

 

TinyPortal © 2005-2018