Recent

Author Topic: synedit  (Read 677 times)

scasparz

  • Jr. Member
  • **
  • Posts: 73
synedit
« on: November 05, 2025, 01:26:23 am »
Hi guys,

am Linux Mint 22.1, with the latest lazarus for debian downloaded from sourceforge. Am trying to add a new bookmark on FEtSynEdit, a tsynedit descendant using this:

Code: Pascal  [Select][+][-]
  1.   IF FEtSynEdit.IsBookmark(zindex)
  2.     THEN FEtSynEdit.ClearBookMark(zindex);
  3.  
  4.   FBookMarksArray[zindex] := tSynEditMark.Create(FETSynEdit);
  5.   FBookMarksArray[zindex].ImageList := FBookMarksImageList;
  6.   FBookMarksArray[zindex].ImageIndex := zindex;
  7.   FBookMarksArray[zindex].BookmarkNumber := zindex;
  8.   FBookMarksArray[zindex].Column:= FETSynEdit.CaretX;
  9.   FBookMarksArray[zindex].Line := FETSynEdit.CaretY;
  10.   FBookMarksArray[zindex].Visible := True;
  11.   FETSynEdit.Marks.Add(FBookMarksArray[zindex]); //point(1)
  12.  
  13.   if FEtSynEdit.IsBookmark(zindex) then information('ok') else information('not ok'); //point(2)
  14.  
Following the addition of the new bookmark as on point(1) , point(2) returns ‘not ok’. Looks like the new bookmark was not inserted. To make it work, reluctantly I had to downgrade to Lazarus 3.0 as provided by Debian (rather than sourceforge).

Any ideas please?
s
« Last Edit: November 05, 2025, 01:33:32 am by scasparz »

paweld

  • Hero Member
  • *****
  • Posts: 1484
Re: synedit
« Reply #1 on: November 05, 2025, 06:38:23 am »
It stopped working after commit: https://gitlab.com/freepascal.org/lazarus/lazarus/-/commit/77c4b7ceaecbdd14f43665d265a65e3990f05da2#1e0b7352ad5a0ae20b96b260ddfe37ec08a672d1_363_395
To achieve the same effect as before the changes in syneditmarks, change the code as follows:
Code: Pascal  [Select][+][-]
  1. IF FEtSynEdit.IsBookmark(zindex)
  2.     THEN FEtSynEdit.ClearBookMark(zindex);
  3.  
  4.   FBookMarksArray[zindex] := tSynEditMark.Create(FETSynEdit);
  5.   FBookMarksArray[zindex].ImageList := FBookMarksImageList;
  6.   FBookMarksArray[zindex].ImageIndex := zindex;
  7.   FBookMarksArray[zindex].BookmarkNumber := zindex;
  8.   FBookMarksArray[zindex].Column:= FETSynEdit.CaretX;
  9.   FBookMarksArray[zindex].Line := FETSynEdit.CaretY;
  10.   FBookMarksArray[zindex].Visible := True;
  11.   FETSynEdit.Marks.Add(FBookMarksArray[zindex]); //point(1)
  12.  
  13.   if (zindex < FEtSynEdit.Marks.Count) and (FEtSynEdit.Marks[zindex].BookmarkNumber >= 0) then
  14.     information('ok') else information('not ok'); //point(2)
You can also report undesirable behavior thios function under the specified commit.
Best regards / Pozdrawiam
paweld

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11792
  • Debugger - SynEdit - and more
    • wiki
Re: synedit
« Reply #2 on: November 05, 2025, 08:48:32 am »
It looks as if you now need to create a TSynEditBookMark instead.
Not sure if the old way is going to be restored... (though I need to see what to do about "BookmarkNumber")

Why don't you use SynEdit.SetBookmark ?

scasparz

  • Jr. Member
  • **
  • Posts: 73
Re: synedit
« Reply #3 on: November 05, 2025, 10:31:54 am »
To begin with thanks both paweld and martin_fr for your quick replies.
For the record, my app was initially written years ago on Laz v_0.9.x, but I keep maintaining it by adding new stuff. Originally this part of the code was written under Laz v_2.x and AFAIK it used to work well. Was surprised to find it does not under Laz 4 when I attempted to have it recompiled.

@paweld indeed FETSynEdit.Marks.Count works in the sense that it gets increased by one after insert. Yet for some reason it looks that although the new bookmark gets into the Marks list (from what I can see on the debugger) still it cannot be intercepted resulting in all shorts of trouble at later stages of my application, rendering it completely useless. To put it simple, I depend upon IsBookmark.

@martin_fr am glad to realise SynEdit is been reworked as indeed this is needed, under Linux I have a number of issues with the component for years. IMO perhaps the best approach would have been for us to be provided with the IDE version of the SynEdit that seemed to work very well instead of the tSynEdit we are given which am afraid leaves something to be desired. I understand this is not going to be easy.

As for the SetBookMark method, I did not know of its existence and of course it’s syntax, that is before you had it mentioned, thank you for this. Unfortunately it is not unusual for open source to be provided with scarce documentation, sometimes I can live without it, others not. Following downgrade from Laz 4 to Laz 3, I cannot even find unit SynEdit using Ctrl-(left click) on the source window (Unable to find file "synedit.pp". If it belongs to your project, check search path in Project -> Compiler Options -> Search Paths -> Other Unit Files. etc). Perhaps something has gone wrong, I may have to try a clean installation of Laz 3 before I try again. All this despite that app can be compiled and run sans issues.

thanks again guys
s

paweld

  • Hero Member
  • *****
  • Posts: 1484
Re: synedit
« Reply #4 on: November 05, 2025, 10:59:25 am »
Quote from: scasparz
Yet for some reason it looks that although the new bookmark gets into the Marks list (from what I can see on the debugger) still it cannot be intercepted resulting in all shorts of trouble at later stages of my application, rendering it completely useless. To put it simple, I depend upon IsBookmark.
As @Martin_fr said - use TSynEditBookMark:
Code: Pascal  [Select][+][-]
  1. {var
  2.   FBookMarksArray: Array of TSynEditBookMark;
  3. begin}
  4.   IF FEtSynEdit.IsBookmark(zindex)
  5.     THEN FEtSynEdit.ClearBookMark(zindex);
  6.  
  7.   FBookMarksArray[zindex] := TSynEditBookMark.Create(FETSynEdit);  //change array definition too
  8.   FBookMarksArray[zindex].ImageList := FBookMarksImageList;
  9.   FBookMarksArray[zindex].ImageIndex := zindex;
  10.   FBookMarksArray[zindex].BookmarkNumber := zindex;
  11.   FBookMarksArray[zindex].Column:= FETSynEdit.CaretX;
  12.   FBookMarksArray[zindex].Line := FETSynEdit.CaretY;
  13.   FBookMarksArray[zindex].Visible := True;
  14.   FETSynEdit.Marks.Add(FBookMarksArray[zindex]); //point(1)
  15.  
  16.   if FEtSynEdit.IsBookmark(zindex) then information('ok') else information('not ok'); //point(2)
Best regards / Pozdrawiam
paweld

scasparz

  • Jr. Member
  • **
  • Posts: 73
Re: synedit
« Reply #5 on: November 05, 2025, 06:42:56 pm »
Problem with Laz 4 is the

Code: Pascal  [Select][+][-]
  1. IF FEtSynEdit.IsBookmark(zindex)
  2.     THEN FEtSynEdit.ClearBookMark(zindex);
  3.  

returns false, independent of whether the bookmark has been set or not. Me thinks this is a bug with Laz4.


best regards
c

paweld

  • Hero Member
  • *****
  • Posts: 1484
Re: synedit
« Reply #6 on: November 05, 2025, 06:54:00 pm »
Sow more code.
I checked it on simple code, and if you add it as TSynEditBookMark (not TSynEditMark), then the IsBookmark function returns True.
Best regards / Pozdrawiam
paweld

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11792
  • Debugger - SynEdit - and more
    • wiki
Re: synedit
« Reply #7 on: November 06, 2025, 09:14:48 am »
@martin_fr am glad to realise SynEdit is been reworked as indeed this is needed, under Linux I have a number of issues with the component for years. IMO perhaps the best approach would have been for us to be provided with the IDE version of the SynEdit that seemed to work very well instead of the tSynEdit we are given which am afraid leaves something to be desired. I understand this is not going to be easy.
I don't know which version/fork of SynEdit you have. But there are a few of them out there.

The one shipped with the IDE was forked around the year 2000. And has since (or at least from 2008 onwards) received massive changes. It's internal structure is now much different from the original.

If you do still have any of the issues, when using the SynEdit that comes with the IDE, then please let me know.

One known (Linux) issue is display of Arabic text (and some other languages). This is due to how the Windows API is emulated by the LCL. Letters are printed on their own, but in Arabic scripts their look depends on the surrounding letters (which then are not considered).


Quote
As for the SetBookMark method, I did not know of its existence and of course it’s syntax, that is before you had it mentioned, thank you for this. Unfortunately it is not unusual for open source to be provided with scarce documentation, sometimes I can live without it, others not. Following downgrade from Laz 4 to Laz 3, I cannot even find unit SynEdit using Ctrl-(left click) on the source window (Unable to find file "synedit.pp". If it belongs to your project, check search path in Project -> Compiler Options -> Search Paths -> Other Unit Files. etc). Perhaps something has gone wrong, I may have to try a clean installation of Laz 3 before I try again. All this despite that app can be compiled and run sans issues.

IIRC, I probably assumed "SynEdit.Marks" to be an internal details, at least for bookmarks. Of course, in the end its public, so....
Hence it isn't even listed as incompatible change. :(

I will have to work on it, since now the old marks (which no longer can be bookmarks) have still a bookmarknumber.
Not sure yet, how I will resolve it.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11792
  • Debugger - SynEdit - and more
    • wiki
Re: synedit
« Reply #8 on: November 06, 2025, 11:15:49 am »
OK, this should restore the old behaviour (hopefully) https://gitlab.com/freepascal.org/lazarus/lazarus/-/commit/cfb8e043815b3e02666b01cf3f63c070a1532799

Could you please test it?

scasparz

  • Jr. Member
  • **
  • Posts: 73
Re: synedit
« Reply #9 on: November 06, 2025, 11:22:06 pm »
@Martin_fr

Quote
OK, this should restore the old behaviour (hopefully) https://gitlab.com/freepascal.org/lazarus/lazarus/-/commit/cfb8e043815b3e02666b01cf3f63c070a1532799
Will definitely try this, but will have to uninstall Laz3 I use at the moment and reinstall Laz4 once more. At this time I actively develop my app under Laz3, cannot switch to Laz4 easily. Please give me some time. I plan to use a virtual machine for the purpose, install Laz4 on it, modify both units, rebuild Laz, transfer my app and try. But I will come back, promise. Please keep the link up.

Quote
If you do still have any of the issues, when using the SynEdit that comes with the IDE, then please let me know.
One annoying issue I have since the beginning of time with tSynEdit under Linux has been that occasionally (unfortunately I cannot replicate the issue - I know it is embarrassing) when I enter a keystroke, it fails to alter the text on screen. Keystroke can be either a normal text letter, or a control character say <del>. By conducting PgUp and PgDown the text appears this time as desired, nothing has been lost, it is just that the screen seems to not have been updated following the keyboard entry, of course clearly keyboard has not misfired. Thanks God this is not a frequent issue and if memory serves by undoing and repeating the keystroke again it works well this time. Have used Laz4 only briefly, cannot comment whether the issue is still present there.

Quote
The one shipped with the IDE was forked around the year 2000. And has since (or at least from 2008 onwards) received massive changes. It's internal structure is now much different from the original.
If you were to give me the IDE version of the SynEdit as a number of units that I could use with my app, it would be a dream come true. Would be very glad to rewrite app from the scratch and buy you a beer.:)

Just kidding, of course you deserve much more, thanks mate.

kind regards
s

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11792
  • Debugger - SynEdit - and more
    • wiki
Re: synedit
« Reply #10 on: Today at 09:05:56 am »
You can either

- patch your current installation
- make a 2ndary install

Under Windows the installer offers to set the 2ndary install up. Under Linux, you can use fpcupdeluxe.

scasparz

  • Jr. Member
  • **
  • Posts: 73
Re: synedit
« Reply #11 on: Today at 09:10:03 am »
Martin_fr, I could not compile Laz4 with the new versions of synedit.pp and syneditmarks.pp as I am missing unit LazEditTextAttributes and perhaps more (LazEditTextGridPainter).
Where can I get them from?

regards
s

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11792
  • Debugger - SynEdit - and more
    • wiki
Re: synedit
« Reply #12 on: Today at 09:13:54 am »
Quote
when I enter a keystroke, it fails to alter the text on screen.

That I don't know. Some people have issues with getting the key twice. Which is todo with some IMM manager under Linux. (Can be bypassed by using some env var IIRC, but I don't know the exact details. Its actually an LCL issue, and affects any custom written component that receives keystrokes (there should be an issue on the bug tracker).

It is quite possible the issue you have is LCL too.
- For TEdit and co, keys aren't handled by the LCL, as those are provided by the WS(gtk/qt) directly
- For custom controls, keys are handled by the LCL

Quote
If you were to give me the IDE version of the SynEdit as a number of units that I could use with my app

That is the version that is in lazarus/components/synedit. The same as you get when you use SynEdit from the component palette.

The IDE also add the units /ide/sourcesyneditor and ide/sourceeditor. But the only add some functionality.


Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11792
  • Debugger - SynEdit - and more
    • wiki
Re: synedit
« Reply #13 on: Today at 09:17:58 am »
Martin_fr, I could not compile Laz4 with the new versions of synedit.pp and syneditmarks.pp as I am missing unit LazEditTextAttributes and perhaps more (LazEditTextGridPainter).
Where can I get them from?

components/lazedit
https://gitlab.com/freepascal.org/lazarus/lazarus/-/tree/cfb8e043815b3e02666b01cf3f63c070a1532799/components/lazedit

If you are replacing the entire SynEdit, rather than just applying the change as a patch, then you may need more changes from outside of SynEdit. Especially if you go git "main" branch.

(The fix for bookmarks will be in upcoming Lazarus 4.4)

 

TinyPortal © 2005-2018