Recent

Author Topic: Invite to Colorizing TSynEdit ! {Improving Editor for Editing Complex Codes}  (Read 111369 times)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5699
    • wiki
Re: Invite to Colorizing TSynEdit ! {Improving Editor for Editing Complex Codes}
« Reply #255 on: September 16, 2016, 02:47:17 pm »
please report as a new bug.

Pascal

  • Hero Member
  • *****
  • Posts: 832
laz trunk - fpc trunk 32bit - Windows 10 Pro x64 (1803)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5699
    • wiki
Re: Invite to Colorizing TSynEdit ! {Improving Editor for Editing Complex Codes}
« Reply #257 on: September 16, 2016, 08:35:42 pm »
Applied.

still getting range checks.
- Disable global outline
- Edit the line from your patch in SynEdit
Code: Pascal  [Select]
  1. fMarkupManager.TextChanged(1 [<< edit/backspace here] , FTheLinesView.Count, 0);

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5699
    • wiki
Re: Invite to Colorizing TSynEdit ! {Improving Editor for Editing Complex Codes}
« Reply #258 on: September 17, 2016, 01:23:30 am »
OK, I found one reason for the crashes.

If I have one unit open in more than one window.
In the 2nd window (SynEdit.ShareTextBufferFrom) the FEndLine array (and other) a zero length.

Because this changes the internal textbuffer (not its content), it does not sent the usual signals.
But it also does not trigger SetLines, because the Markup uses a wrapper version of the textbuffer, and that does not change.

It probably should send lines changed. But I need to see, if that has side effects.
(It needs some more refactor....)

-----------------------
Why does FEndLine has the same length as SynEdit.Lines (If I read that correct)?

You only need to know about current displayed lines. (then the above problem would not exist).

If I am correct you keep an array with length of 10000 (for some units) where you may need only 50 (on screen).

(Well that will become a problem, if we do an overview-panel, showing the whole unit, with font-size = 1, but then not sure if the markup should be applied there.)

Pascal

  • Hero Member
  • *****
  • Posts: 832
Re: Invite to Colorizing TSynEdit ! {Improving Editor for Editing Complex Codes}
« Reply #259 on: September 17, 2016, 06:05:19 am »
Why does FEndLine has the same length as SynEdit.Lines (If I read that correct)?

You only need to know about current displayed lines. (then the above problem would not exist).

If I am correct you keep an array with length of 10000 (for some units) where you may need only 50 (on screen).
Yes the array is as long as the SynEdit.Lines. It's a chache for the endline for that line. The same with FFirstCharacterColumn as cache for the
column of the first character in the line (this is the position of the vertical line).

I can not limit this to the lines in the window as i have to at least keep track of FFirstCharacterColumn as i have to draw vertical lines for nodes
that where opened before Topline or i have to refind the positions for every invalidation but we would like to save cpu/energy if i got you right.

I also found an other bugs: Disable outling, select a complete class definition and apply a conditional define (shift + alt + d) ->
Code: [Select]
TApplication.HandleException Arithmetic overflow
  Stack trace:
  $00B2DAE3  TLAZSYNTEXTAREA__INVALIDATELINES,  line 1299 of lazsyntextarea.pp
  $00B2CF3E  TLAZSYNSURFACEMANAGER__INVALIDATETEXTLINES,  line 1117 of lazsyntextarea.pp
  $00C3609C  TSOURCELAZSYNSURFACEMANAGER__INVALIDATETEXTLINES,  line 1366 of sourcesyneditor.pas
  $007325F2  TCUSTOMSYNEDIT__INVALIDATELINES,  line 2819 of synedit.pp
  $00AE346C  TSYNEDITMARKUP__INVALIDATESYNLINES,  line 337 of syneditmarkup.pp
  $00BD1E03  TSYNEDITMARKUPFOLDCOLORS__DOTEXTCHANGED,  line 706 of syneditmarkupfoldcoloring.pas
  $00AE3B1E  TSYNEDITMARKUP__TEXTCHANGED,  line 442 of syneditmarkup.pp
  $00AE46D9  TSYNEDITMARKUPMANAGER__TEXTCHANGED,  line 614 of syneditmarkup.pp
  $00739F11  TCUSTOMSYNEDIT__SCANRANGES,  line 5080 of synedit.pp
  $007311DD  TCUSTOMSYNEDIT__DODECPAINTLOCK,  line 2381 of synedit.pp
  $004D606D  TMETHODLIST__CALLNOTIFYEVENTS,  line 307 of lazmethodlist.pas
  $00AFE97D  TSYNEDITSTRINGLIST__SENDNOTIFICATION,  line 1545 of synedittextbuffer.pp
  $00AFCAAF  TSYNEDITSTRINGLIST__SETUPDATESTATE,  line 1248 of synedittextbuffer.pp
  $00AF64BE  TSYNEDITSTRINGS__ENDUPDATE,  line 973 of lazsynedittext.pas
  $00730CF7  TCUSTOMSYNEDIT__DECPAINTLOCK,  line 2305 of synedit.pp
  $00742213  TCUSTOMSYNEDIT__INTERNALENDUNDOBLOCK,  line 7148 of synedit.pp
  $00738577  TCUSTOMSYNEDIT__SETSELTEXTEXTERNAL,  line 4586 of synedit.pp
I will investigate this later.
laz trunk - fpc trunk 32bit - Windows 10 Pro x64 (1803)

Pascal

  • Hero Member
  • *****
  • Posts: 832
Re: Invite to Colorizing TSynEdit ! {Improving Editor for Editing Complex Codes}
« Reply #260 on: September 17, 2016, 07:42:21 am »
Fixed! Added new patch wich also uses NestList.NodeEndLine.
laz trunk - fpc trunk 32bit - Windows 10 Pro x64 (1803)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5699
    • wiki
Re: Invite to Colorizing TSynEdit ! {Improving Editor for Editing Complex Codes}
« Reply #261 on: September 17, 2016, 11:31:03 am »
Yes the array is as long as the SynEdit.Lines. It's a chache for the endline for that line. The same with FFirstCharacterColumn as cache for the
column of the first character in the line (this is the position of the vertical line).

I can not limit this to the lines in the window as i have to at least keep track of FFirstCharacterColumn as i have to draw vertical lines for nodes
that where opened before Topline or i have to refind the positions for every invalidation but we would like to save cpu/energy if i got you right.

All you need is a 2nd array (for each of the two), that contains all the node-infos opened before topline.

Code: Pascal  [Select]
  1. procedure Foo();
  2. begin
  3.   if Message.WParam = WParam(FGroupIndex) then
  4.   begin
  5.     Sender := TCustomSpeedButton(Message.LParam);
  6.     if Sender <> Self then
  7.     begin
  8.  
  9. ------------------- Topline
  10.       if Sender.Down and FDown then
  11.       begin
  12.         FDown := False;
  13.  

FIrstBeforeTopline = (1, 3, 5); // does not matter on which line they are, just that they exist
First = (0 {visible line 1, nothing new opening // or is it 5 repeated?}, 7, 0 ....  ); 

Of course you need to adapt things on scroll.... you need to know which line topline was before.

---------------------
If you must keep full length, then use the managed ranges. (one class can hold both: first and len)

See FTabDAta in TSynEditStringTabExpander.TextBufferChanged

This well automatically be kept always the same length as Lines, and if insert/delete happens this is automatically done in the right place (you only need to zero/initialize it.



Pascal

  • Hero Member
  • *****
  • Posts: 832
Re: Invite to Colorizing TSynEdit ! {Improving Editor for Editing Complex Codes}
« Reply #262 on: September 19, 2016, 12:17:38 pm »
Martin,

i added a new patch http://bugs.freepascal.org/file_download.php?file_id=25046&type=bug.

This solved the issue with cloned TextBuffers.
I do a check of not initialized arrays and init them.
laz trunk - fpc trunk 32bit - Windows 10 Pro x64 (1803)

Pascal

  • Hero Member
  • *****
  • Posts: 832
Re: Invite to Colorizing TSynEdit ! {Improving Editor for Editing Complex Codes}
« Reply #263 on: September 19, 2016, 10:14:23 pm »
By the way: If i disable "Outline (global)" i can not set "Outline" for the individual keyword as it is disabled.
Why is it disabled?
laz trunk - fpc trunk 32bit - Windows 10 Pro x64 (1803)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5699
    • wiki
Re: Invite to Colorizing TSynEdit ! {Improving Editor for Editing Complex Codes}
« Reply #264 on: September 19, 2016, 11:28:54 pm »
if outlining is disabled, then there is no point in being able to change its config.

It would not change anything.

Pascal

  • Hero Member
  • *****
  • Posts: 832
Re: Invite to Colorizing TSynEdit ! {Improving Editor for Editing Complex Codes}
« Reply #265 on: September 20, 2016, 05:49:12 am »
if outlining is disabled, then there is no point in being able to change its config.

It would not change anything.
Ah, i see. So you enable outlining with "Outline (global)" and then disable individual folds.
I thought it behaves more like enable/disable all folds.
laz trunk - fpc trunk 32bit - Windows 10 Pro x64 (1803)

Pascal

  • Hero Member
  • *****
  • Posts: 832
Re: Invite to Colorizing TSynEdit ! {Improving Editor for Editing Complex Codes}
« Reply #266 on: September 23, 2016, 11:08:58 pm »
Martin,

did you review the latest patch already?
 
laz trunk - fpc trunk 32bit - Windows 10 Pro x64 (1803)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5699
    • wiki
Re: Invite to Colorizing TSynEdit ! {Improving Editor for Editing Complex Codes}
« Reply #267 on: September 23, 2016, 11:46:10 pm »
not yet, been on your other patch

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5699
    • wiki
Re: Invite to Colorizing TSynEdit ! {Improving Editor for Editing Complex Codes}
« Reply #268 on: September 24, 2016, 01:50:10 pm »
I get a range check, when I change Editor opts in the IDE.

Code: Pascal  [Select]
  1. #0 HANDLEERRORADDRFRAME(201, 0xc218e2, 0x102af864) at ..\inc\system.inc:1104
  2. #1 HANDLEERRORADDRFRAMEIND(201, 0xc218e2, 0x102af864) at ..\inc\system.inc:1123
  3. #2 fpc_dynarray_rangecheck(0x0, 0) at ..\inc\dynarr.inc:41
  4. #3 DOTEXTCHANGED(0x13e48e28, 1, 2589, 0) at syneditmarkupfoldcoloring.pas:737
  5. #4 TEXTCHANGED(0x13e48e28, 1, 2590, 0) at syneditmarkup.pp:442
  6. #5 TEXTCHANGED(0x140e6208, 1, 2590, 0) at syneditmarkup.pp:614
  7. #6 HIGHLIGHTERATTRCHANGED(0x1413e8a0, 0x13934108) at synedit.pp:8123
  8. #7 CALLNOTIFYEVENTS(0x139f45f8, 0x13934108) at lazmethodlist.pas:307
  9. #8 DEFHIGHLIGHTCHANGE(0x13934108, 0x13934108) at synedithighlighter.pp:1453
  10. #9 ENDUPDATE(0x13934108) at synedithighlighter.pp:1297
  11. #10 UPDATEHIGHLIGHTERS(0x118665d8, true) at mainbase.pas:1939
  12. #11 DOEDITOROPTIONSAFTERWRITE(0x118665d8, 0x1683d0, false) at main.pp:4863
  13.  

Code: Pascal  [Select]
  1.   // invalidate cache
  2.   for i := ToIdx(StartLine) to ToIdx(EndLine) do begin
  3.     FFirstCharacterColumn[i] := 0;
  4.     FEndLine[i] := 0;
  5.   end;
  6.  
FFirstCharacterColumn is empty (length - 0)

Startline = 1 and endline = linecount.

--------------------
Btw there is lots of commented out code. Still needed?


--------------------
Quote
Fixed! Added new patch which also uses NestList.NodeEndLine.
There are still various FHighlighter.FoldEndLine ?

------------------
And then there seems to be a bug outside your code. The paint code hits an assert, when I type Japanese Hiragana (double width chars)


Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5699
    • wiki
Re: Invite to Colorizing TSynEdit ! {Improving Editor for Editing Complex Codes}
« Reply #269 on: September 24, 2016, 03:17:21 pm »
Code: Pascal  [Select]
  1. procedure TSynEditMarkupFoldColors.InitArrays;
  2. ....
  3.   Lines.AddChangeHandler(senrLineCount, @LinesChanged);
  4.   Lines.AddChangeHandler(senrHighlightChanged, @HighlightChanged);
  5.  

This is called from TSynEditMarkupFoldColors.SetLines (where it is matched by remove calls.)
But also from other locations. (Afaik duplicates are ignored, but still....)

Also
Code: Pascal  [Select]
  1. constructor TSynEditMarkupFoldColors.Create(ASynEdit: TSynEditBase);
  2. begin
  3.   inherited Create(ASynEdit);
  4.  
  5.   if Assigned(Lines) then begin
  6.     Lines.AddChangeHandler(senrLineCount, @LinesChanged);
  7. ....
  8.  
It can never be assigned.

This code should only be in SetLines and Destroy (a remove call is ignored, if the handler wasn't added.