Forum > SynEdit
Deprecated function
Kaller:
SynEdit.RowColToCharIndex(Pt) says it is deprecated. It works Ok but should I use an alternative?
KodeZwerg:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---var i, charIndex: Integer;begin charIndex := 0; for i := 0 to SynEdit1.CaretXY.Y - 2 do charIndex := charIndex + Length(SynEdit1.Lines[i]) + Length(LineEnding); charIndex := charIndex + SynEdit1.CaretXY.X;charIndex will got same value as RowColToCharIndex was given.
Martin_fr:
There is no alternative with the same functionality.
The idea is to use a different concept, and use x/y.
The way SynEdit operates, using "char index" can be very slow.
It will be fine for files with a 1000 chars. Though even then, if you use lots of calls, it may be slow.
"RowColToCharIndex" has to run over all lines each times it is invoked. Like the example by KodeZwerg.
The question is what are you trying to do?
In most cases it can be done without RowColToCharIndex.
Do you want to store the current caret or selection, and then insert new text?
Use SynEdit.TextBetweenPoint[p1,p1] :=
This will automatically adjust the caret and selection.
Also note, that in **most cases** you don't want to operate on SynEdit.Lines. SynEdit.Lines is to load the initial text (and only that).
Operating an the lines removes all undo/redo info.
Again TextBetweenPoint is the solution.
Kaller:
Actually I have a custom script language I wrote and as I run it from the editor I display the next line to run highlighted as it runs. So fast is good and flaky is not. textbetweenpoints sounds like it may do it. I see there is a selection mode called smLine.
Martin_fr:
--- Quote from: Kaller on August 26, 2023, 11:51:47 am ---I display the next line to run highlighted as it runs.
--- End quote ---
Have you seen "OnSpecialLineColors" ?
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure(Sender: TObject; Line: integer; var Special: boolean; var FG, BG: TColor) of object;
Will be called for each line, and you can give it a fore/background color (clNone for "not changed", if you want to change only one.
"OnSpecialLineMarkup" for more complex colors (border, blend/fade color ...)
-----
Mind those are called in the paint event:
- they must be fast.
- the must NOT call "invalidate" or other paint related code
"must be fast" => calculate which line to color in other code (e.g. KeyDown / StateChanged / ....). Store the line and color.
Then in OnSpecialLineColors, just check if the call is for the stored line, and return the stored color.
I am not sure if that needs a highlighter assigned.
If it does, and if you don't have one, use a dummy like TSynPosSyn
Navigation
[0] Message Index
[#] Next page