Lazarus
Programming => General => Topic started by: BubikolRamios on December 19, 2014, 08:52:18 pm
-
Ok Edit pad pro has that, but I want to do it myself.
Any words of wisdom on recomended components (mybe SynEdit), sample code, ...
-
Sorry. I don't understand very well, what you need.
Maybe if you explain it better, we can suggest something.
-
Img is from EditPadPro.
Consider "a" in seach field to be regex.
As you type more (or change) regex into search field
text gets yellowish accordingly.
Want (for start) to do same with lazarus. Recomended components, mybe some sample code on highlighting ?
-
In lazarus you have "Incremental find" (ctrl-e).
It is not a regex, but text highlights as you search.
look in ide/sourceditor.pp for the code (and then follow the code into synedit)
-
Definitely the best option is to use SynEdit.
In SynEdit, for to highlight a text, you can do:
uses ..., SynEditTypes;
...
SynEdit1.HighlightAllColor.Background := clGreen;
SynEdit1.SetHighlightSearch('Hello:', [ssoSelectedOnly]) ;
This is some kind of "markup", but this is not Regex.
Another option is to write your own Highlighter for SynEdit and then you can add support for Regex.
-
Any idea how this works ? (or how to make '3' painted right away)
Note that the text cursor is after last '3' in text and '3' is not painted.
Gets painted emidieatly after I type in next character.
If I insert regex compatible text anywhere inside existing text it gets painted prompt.
-
your code looks correct.
so propably a bug.
You can report it, but it might be a long time before I can look at it.
Have a look at TSynEditMarkupHighlightAll.FindMatches
add "debugln" (write to console or logfile) for the results of the find.
Maybe find returns incorrect. Then check in line 850
FoundEndPos:=
Point(RegExprEngine.MatchPos[0]+RegExprEngine.MatchLen[0],y+1);
See if the regex engine returns correct.
Then it depends where to look next.
-
Actually probably forget my last post.
Might be that you call it in key up. Try OnStatusChange.
Also note that "[^a-z]" does match a huge list of 1 char matches.
-
Behaviour does not depend on type of event that triggers it, nor regex itself. Could be any regex.
procedure TForm1.FormCreate(Sender: TObject);
begin
SynEdit1.SetHighlightSearch('ab',[ssoRegExpr]);
end;
Inside SynEditSearch.pas
ln. 903
if fRegExpr then begin // IF SOMETHING OR MORE OF IT WITHIN ENTIRE TEXT MATCHES GIVEN REGEX
// regular expression
if SearchRegExprInLine(Max(1,x+1),LineStr) then begin
//DebugLn(['TSynEditSearch.FindNextOne Found RegExpr']);
FoundStartPos:=Point(RegExprEngine.MatchPos[0],y+1);
FoundEndPos:=
Point(RegExprEngine.MatchPos[0]+RegExprEngine.MatchLen[0],y+1);
Result:=(CompareCarets(FoundEndPos,EndPos)>=0)
and (CompareCarets(FoundStartPos,StartPos)<=0);
if Result then
fRegExprReplace:=RegExprEngine.Substitute(Replacement);
exit;
end;
end else
Realy guessing here, seems Result indicates that stuff will be painted.
At 'ab' regex:
On empty synedit:
1. 'abcab' Result gets true once and only first 'ab' gets painted
2. 'abcabc' Result gets true twice and both 'ab' gets painted
BTW:
If I put SynEdit on form , run prog, hit CTRL + A & DEL
It does not seem logical that clicking into 'first line - further to right, not 1,1 position' puts caret anywhere I clicked in 'first line'.
Should 'force' it to be on 1,1 position ? That is the way it is in all text editors.
Telling that coz FoundEndPos is realy big sometimes, and that could be original prob. mybe.
Same goes for all lines.
Hit enter at end of line, type one char, and that new line is not 1 char long regarding clicking further to the right in that line.
-
BTW:
If I put SynEdit on form , run prog, hit CTRL + A & DEL
It does not seem logical that clicking into 'first line - further to right, not 1,1 position' puts caret anywhere I clicked in 'first line'.
Should 'force' it to be on 1,1 position ? That is the way it is in all text editors.
Check the Options. there is one that allows / disables "caret past end of line"
The highlight I will have to take a deeper look. So probably best to report as a bug.
-
I just tried the highlight in trunk (1.3) (OnStatusChance)
SynEdit1.SetHighlightSearch('ab',[ssoRegExpr]);
and then typed
abeab
Worked correct. Please try with trunk
-
Thanks.
Right, upgraded lazarus to 2.6.4 and it works.
Last question in this thread:
Any easy way to invert highlight & know what is selected by that inversion ?
Or, is there already a list,array,... of positions that are highlighted by regex highlight, like [[1,2],[4,5]] for string 'abcab' and regex 'ab' ?
purpose:
It is easy to replace all that is highlighted by regex:
SynEdit1.SearchReplaceEx('ab','',[ssoRegExpr,ssoReplaceAll],pt);
But I want,at some poit, to replace, all that regex highlight leaves not highlighted.
-
The list is not public
The private variable fMarkupHighAll : TSynEditMarkupHighlightAll
has a protected property
TSynEditMarkupHighlightMatches.Matches
So if you need access you need to inherhit from TSynEditMarkupHighlightAll.
And you need to inherhit from TSynEdit
TSynEdit has a protected property MarkupMgr. Add your instance of TSynEditMarkupHighlightAll to that.
Look at TSynEdit.Create and how the original is done
---------------------------------------
the easier way is just to use TSynEdits SearchReplace with the same pattern, as that will match and replace the same bits of text.
-
Thanks.