Recent

Author Topic: All Things SynEdit/Highlighter - Lyrics Editor  (Read 7064 times)

pixelink

  • Hero Member
  • *****
  • Posts: 1260
All Things SynEdit/Highlighter - Lyrics Editor
« on: May 07, 2019, 09:08:25 pm »
I am working on converting a .NET app (see screen below) over to Lazarus (free pascal)

I am using the SynEdit and I am at the beginning stages of creating the Highlighter.
I am using the example in the LAZ example folder

I have hooked up the sample (SimHL) Higlighter to my editor.
On first run I get all my spaces with squares.

I looked at my code an I am lost as where to look for the "Space"
I think it's here, but not sure.

Code: Pascal  [Select][+][-]
  1.  
  2. l := length(FLineText);
  3.   If FTokenPos > l then
  4.     // At line end
  5.     exit
  6.   else
  7.   if FLineText[FTokenEnd] in [#9, ' '] then
  8.     // At Space? Find end of spaces
  9.     while (FTokenEnd <= l) and (FLineText[FTokenEnd] in [#0..#32]) do inc (FTokenEnd)
  10.   else
  11.     // At None-Space? Find end of None-spaces
  12.     while (FTokenEnd <= l) and not(FLineText[FTokenEnd] in [#9, ' ']) do inc (FTokenEnd)
  13.  
  14.  

How do i get rid of that line where there is spacing... It's in the example too.

Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: All Things SynEdit/Highlighter - Lyrics Editor
« Reply #1 on: May 07, 2019, 09:39:22 pm »
Okay... first hurdle fixed...

This line handles the space

Changed...
fSpaceAttri.FrameColor := clSilver;

TO
fSpaceAttri.FrameColor := clNone;
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: All Things SynEdit/Highlighter - Lyrics Editor
« Reply #2 on: May 08, 2019, 02:39:43 am »
Okay... a little frustrated. Worked on this one problem for 4 hours
Documentation for SynEdit stinks!!!

The WIKI is to vague, the examples do NOT provide essential solutions to most needed features.

Example... All I want to do is highlight the text that is between "[]"

I would like it to look like this...

[Dm]
FYI... there is no gray color on forum editor, so the Teal would be Gray too.

I can get gray brackets ([]) but it changes all the chords to Gray.

I can't seem to figure out how to separate the colors.

Also, one thing I noticed... colors or styles only work when all the character are together.
So, doing "[  Dm  ]" won't work.

BTW... "Dm" is a D minor chord in music.


SEE SCREEN
« Last Edit: May 08, 2019, 02:49:08 am by pixelink »
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: All Things SynEdit/Highlighter - Lyrics Editor
« Reply #3 on: May 08, 2019, 02:42:14 am »
Download the sample project (with all code) here....
« Last Edit: May 08, 2019, 02:47:02 am by pixelink »
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

Edson

  • Hero Member
  • *****
  • Posts: 1324
Re: All Things SynEdit/Highlighter - Lyrics Editor
« Reply #4 on: May 08, 2019, 06:38:35 am »
There is book I wrote for SynEdit: "The Bible of SynEdit": https://github.com/t-edson/SynFacilSyn/blob/1.21/Docs/La%20Biblia%20del%20SynEdit%20-%20Rev7.pdf
 
Sadly it's only in spanish. Maybe you can translate.
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

af0815

  • Hero Member
  • *****
  • Posts: 1387
Re: All Things SynEdit/Highlighter - Lyrics Editor
« Reply #5 on: May 08, 2019, 07:51:45 am »
Sadly it's only in spanish. Maybe you can translate.
Is the source available for translation (maybe goole translator is my friend), i found only the created pdf on github. Other Doc are  odf, so no problem for translation
regards
Andreas

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11164
  • Debugger - SynEdit - and more
    • wiki
Re: All Things SynEdit/Highlighter - Lyrics Editor
« Reply #6 on: May 08, 2019, 01:17:11 pm »
Look at the unit "ContextHL"
What you need is the range. It is passed along, as you go through the line. Even to the next line.

Actually, if you only recognize the token on a single line, then you can just use 
  FAfterOpenSquareBracket, FAfterSquareBracketTEXT: Boolean
in your highlighter.

IF you go across lines, then you use the range. In the example the range is an integer, but it can be a set to (up to 32 enums). Or you look at the unit "FoldHl" where range is handled by the parent class and is an object.

In "Next" (or where ever you moved your checks):

Not tested, just drafted the concept...
Code: Pascal  [Select][+][-]
  1.   if FAfterSquareBracketTEXT then begin
  2.     // must be at ]
  3.      FAfterSquareBracketTEXT := false;
  4.   end;
  5.  
  6.   If FAfterOpenSquareBracket then begin
  7.      while (FTokenEnd <= length(FLineText)) and (FLineText[FTokenEND] <> ']' do inc(FTokenEnd)
  8.         // check for lineend
  9.         FAfterSquareBracketTEXT := true;
  10.         FAfterOpenSquareBracket := false;
  11.         //return token
  12.   end
  13.   else begin
  14.     FAfterSquareBracketTEXT := false;
  15.     If FLineText[FTokenPos] = '[' then
  16.       FAfterOpenSquareBracket := true
  17.     else
  18.        FAfterOpenSquareBracket := false;
  19.   end;
  20.  

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: All Things SynEdit/Highlighter - Lyrics Editor
« Reply #7 on: May 08, 2019, 02:04:22 pm »
Okay... I got this code to compile.
However, when i run it... it only does "[Dm"   no... "]" closing bracket

Also, I don't have a token to run, because I don't have one setup for the chord "Dm"

If I setup "fChordSttri" to bolden the "Dm" it boldens all D's & m's in the editor

I only want to stylize the Chord between the "[]"'s and not any other text in the Editor

Also, I got errors on these two lines, I assume these were to be declared Boolean's, right??

FAfterOpenSquareBracket: Boolean = True;
FAfterSquareBracketTEXT: Boolean;


Here is compile safe code:

Also,
Code: Pascal  [Select][+][-]
  1.  
  2. var
  3.    FAfterOpenSquareBracket: Boolean = True;
  4.    FAfterSquareBracketTEXT: Boolean;
  5.  
  6. If FAfterOpenSquareBracket then
  7.      begin
  8.        while (FTokenEnd <= length(FLineText)) and (FLineText[FTokenEND] <> ']') do inc(FTokenEnd);
  9.           begin
  10.             // check for lineend
  11.             FAfterSquareBracketTEXT := true;
  12.             FAfterOpenSquareBracket := false;
  13.             //return token
  14.           end
  15.      end
  16.   else
  17.       begin
  18.         FAfterSquareBracketTEXT := false;
  19.         If FLineText[FTokenPos] = '[' then
  20.           FAfterOpenSquareBracket := true
  21.         else
  22.            FAfterOpenSquareBracket := false;
  23.       end;
  24.  
  25.  

« Last Edit: May 08, 2019, 02:25:34 pm by pixelink »
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: All Things SynEdit/Highlighter - Lyrics Editor
« Reply #8 on: May 08, 2019, 02:21:05 pm »
Forgot to mention.

When the ContextHL is applied, it makes "[Dm" and any other chords next to the  "[" bold.
There is NO "]" closing bracket that is effected.

Any text that was made bold using the attributes in the "SimpleHL" and is outside the "[]" loses the Bold.
Can't have that either, so it seems that the ContextHL isn't working right if it effects text outside of the []'s
« Last Edit: May 08, 2019, 02:27:57 pm by pixelink »
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: All Things SynEdit/Highlighter - Lyrics Editor
« Reply #9 on: May 08, 2019, 02:24:36 pm »
There is book I wrote for SynEdit: "The Bible of SynEdit": https://github.com/t-edson/SynFacilSyn/blob/1.21/Docs/La%20Biblia%20del%20SynEdit%20-%20Rev7.pdf
 
Sadly it's only in spanish. Maybe you can translate.

No criticism of your work intended (that is great!), but you do realize that most people on this forum Speak English.
It's no good to me.
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: All Things SynEdit/Highlighter - Lyrics Editor
« Reply #10 on: May 08, 2019, 02:30:22 pm »
Just for fun trying to get down to the root of the problem...

I removed the below code, and it doesn't effect the ContextHL in any way

Code: Pascal  [Select][+][-]
  1.  
  2. begin
  3.         FAfterSquareBracketTEXT := false;
  4.         If FLineText[FTokenPos] = '[' then
  5.           FAfterOpenSquareBracket := true
  6.         else
  7.            FAfterOpenSquareBracket := false;
  8.       end;
  9.  
  10.  
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: All Things SynEdit/Highlighter - Lyrics Editor
« Reply #11 on: May 08, 2019, 02:33:37 pm »
Just for fun trying to get down to the root of the problem...

I removed the below code, and it doesn't effect the ContextHL in any way

Code: Pascal  [Select][+][-]
  1.  
  2. begin
  3.         FAfterSquareBracketTEXT := false;
  4.         If FLineText[FTokenPos] = '[' then
  5.           FAfterOpenSquareBracket := true
  6.         else
  7.            FAfterOpenSquareBracket := false;
  8.       end;
  9.  
  10.  

Duh (on myself)... of course it won't work either way because it returns "False" so, really it is just there to set the flag for the NEXT reading.

so, what I have to figure out as far as the last "]" not working is why its not working in the top half of the code.
« Last Edit: May 08, 2019, 02:35:15 pm by pixelink »
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: All Things SynEdit/Highlighter - Lyrics Editor
« Reply #12 on: May 08, 2019, 02:49:36 pm »
What do I use for a token, here??

Code: Pascal  [Select][+][-]
  1.  
  2. begin
  3.    // check for lineend
  4.    FAfterSquareBracketTEXT := true;
  5.    FAfterOpenSquareBracket := false;
  6.    //return token
  7.    // ????? What goes here??
  8. end
  9.  
  10.  
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: All Things SynEdit/Highlighter - Lyrics Editor
« Reply #13 on: May 08, 2019, 03:45:23 pm »
Playing with the attributes and the ContextHL, when the ContextHL is applied, the wrong things are disabled (removes the bold & red)


See screen...
Notice the line "Key: [F]" that the "[F" has lost the red/bold attribute, so the ContextHL is not working right.

Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11164
  • Debugger - SynEdit - and more
    • wiki
Re: All Things SynEdit/Highlighter - Lyrics Editor
« Reply #14 on: May 08, 2019, 04:12:29 pm »
Code: Pascal  [Select][+][-]
  1. FAfterOpenSquareBracket: Boolean;
  2. FAfterSquareBracketTEXT: Boolean;

Those 2 variables must be fields of the object. So there state is kept, across several calls to "Next".

You have to see the "Next" method (and the entire parsing) as a "state" driven parser.

"Next" is called over and over again. Each time, it only sees a small bit of the text. In order to know, how to treat this small bit, it needs to know what state it is in.

- So if it is in "normal" state, and it encounters a "[", then it changes to "after [" state (FAfterOpenSquareBracket:=True)

- If it is in "after [" state, then it needs to find the "]" and the text inbetween is a chord token.
  Or better yet, it should test, if that text inbetween is any of the know chords (e.g. DM)
  ** Important: Since Next advances to the end of the token, it must also change the state, it is no longer "after [".
       It goes to "after [ text"  (changing the 2 fields)

- if state = "after [ text" then the "]" is to be highlighted

The last state ensures that if you encounter a "]" that is not the end of a chord, then it is not highlighted.


- The state must be kept in a field of the object, so it can be used across several calls to Next.
- You may want to clear it, in SetLine, or Get/SetRange
  ((( If you need it across lines, then you must store it as part of the "range". Lines can be scanned out of order, but the range will be restored correctly. )))
- It is your choice how to store it: 2 booleans, an enum, a set .....

 

TinyPortal © 2005-2018