[Lazarus] SynEdit.TextBetweenPoints (Martin?)
Martin Frb
lazarus at mfriebe.de
Sun Aug 11 15:00:17 CEST 2019
On 11/08/2019 13:21, Bart via lazarus wrote:
>
>> SetTextBetweenPoints(BB, BB, Pre, [setMoveBlock], scamAdjust,
>> smaMoveUp, smNormal);
>> // scamAdjust => Move the caret with the block.
>> BE := BlockEnd;
>> SetTextBetweenPoints(BE, BE, Post, [setMoveBlock], scamIgnore,
>> smaMoveUp, smNormal);
>> // setMoveBlock for the 2nd call, is to KEEP the selection as it is.
>> So to keep caret => scamIgnore
> Yes, this seems to work OK, even when Lines.Count = 0.
>
> So, now I need to $ifdef my workaround for Lazarus 2.0.
> What ifdef to use?
{$IF LCL_FullVersion < 2010000}
This does not work for smColumn mode. Even if the column only has a
single line. But trying to do a {} around a column selection is of
limited use anyway. It would only add on opening on the very first line,
and a closing on the very last line.
Btw, I have not tested that code for persistent selections.
It relies on that the 2nd SetTextBetweenPoints does not move the caret
(that will be the same with persistent selection)
and that if the block had been moved (in case of on empty selection),
the caret will reset the block.
That is because the selection must end (or begin) at the caret. Which is
not the case after the empty selection did move.
A persistent selection does not need to end at the caret. So I do not
know if it will be reset. (Maybe it does, maybe not)
If it is not, then it will still at first look ok: selection still
empty, and caret at correct location.
But this may affect how ctrl-K,B / ctrl-K,k (IIRC) work. That is, if
you set the block-end, the begin (even though empty) may have been moved.
Hovewer come to think of it:
Unless the selection begin has just been set, the begin of a persistent
selection is not at the caret. So using BlockBegin/End for an empty
persistent selection will not get you what you want.
So if there is no selection (and if persistent selection could be
enabled) then (not tested) something like this may help
If not SelAvail then begin
p := LogicalCaretPos;
f := BlockBegin = p;
SetTextBetweenPoints(p, p, Post, [setMoveBlock],
scamIgnore,smaMoveUp, smNormal);
SetTextBetweenPoints(p, p, Pre, [setMoveBlock],
scamAdjust,smaMoveUp, smNormal);
if f then BlockBegin := p;
end
else
// the other code
Selection will be moved, if it is not at the caret pos.
Otherwise
- insert the end "}" first, but do not move caret.
- insert begin (will insert before end, because caret did not move),
will move the caret (so it is after "{"), and will reset selection
to be empty at caret
- reset empty selection to caret.
>> Also SelEnd / SelStart are really slow (they have to iterate over all
>> lines up to the selection, each time you call them. SynEdit operates
>> with x/y locations.
> I know, see the diff in
> https://sourceforge.net/p/flyingsheep/code/324/tree//trunk/EPlus/editorpagecontrol.pp?diff=4faa6364b9363c207f000850:323
>
> + //Using SetTextBetweenPoints is faster (and according to Martin
> Friebe) more reliable
BlockBegin/BlockEnd are faster than SelStart/SelEnd.
BlockBegin/End and SetTextBetweenPoints are comparable.
But SetTextBetweenPoints should be less work to use.
> That code was by you, so you got me into this mess in the first place :-)
>
In that case sorry.
More information about the lazarus
mailing list