[Lazarus] LineRange [Re: Auto indentation]
Martin
lazarus at mfriebe.de
Tue Nov 3 21:43:02 CET 2009
BTW: what line rang should be reported if a line was deleted?
Martin wrote:
> Mattias Gaertner wrote:
>> On Tue, 03 Nov 2009 17:46:48 +0000
>> Martin <lazarus at mfriebe.de> wrote:
>>
>>> Mattias Gärtner wrote:
>>>
>>>> Zitat von Martin <lazarus at mfriebe.de>
>>>>> have you looked at using
>>>>> StartLine := Min(Old:ogCaret.Y, LogCaret.Y);
>>>>> EndLine := Max(Old:ogCaret.Y, LogCaret.Y);
>>>>>
>>>> Sometimes synedit gives me too many lines, sometimes not enough. I
>>>> need the real insert range.
>>>>
>>> Even if you use the info from the caret?
>>>
>>
>> For example:
>> inserting one line:
>> OldCaret=(x=1,y=47) NewCaret=(x=1,y=48) FirstLinePos=47 LastLinePos=48
>>
> You mean inserting a full line using paste? so you have a complet new
> line 47, and the old line 47 is now 48? But then the info from the
> caret is correct, with one addition
>
> Text changed between 47/1 and 48/1 Since there is nothing before line
> 48/1 That means the line has not changed (ending on the next line with
> pos=1 means that the last modified think is the linefeed)
>
>> replacing one line with one line
>> OldCaret=(x=1,y=48) NewCaret=(x=1,y=48) FirstLinePos=46 LastLinePos=48
>>
> Good point, if you had a selection before, then the caret is *not*
> sufficient
>
> But in this situation, even if the line range was correct, this would
> bring back the problem of detecting how much of line 47 was changed.
> => it could be that only the last few chars where selected, in this
> case the insert (according to you) should not re-indent line 47
> => or line 47 was fully selected, and should be re-indented
>
> So this case is a good example, even the combination of correct
> line-range and both carets are not enough. You must additionally take
> in account the selection that was present before the edit took place.
> (and you must take in account if the selection is persistent, or
> will/will-not be overwritten)
>
>> replacing one line with one line
>> OldCaret=(x=1,y=47) NewCaret=(x=1,y=48) FirstLinePos=46 LastLinePos=48
>>
>>
>>
>>> Yes, I looked at the FirstLinePos, LastLinePos range => it is wrong
>>> sometimes. But the caret seems to be ok for all I have seen.
>>>
>>> Also, as I wrote before: FirstLinePos, LastLinePos is not usable for
>>> you, because in syncro-mode it will report more lines than you need
>>> (and that is by design).
>>>
>>
>> Yes.
>> How to find out if synedit is in syncro mode?
>>
> Currently not available. The syncroEditModule is created in
> sourceditor line 2565 => So a reference could be kept. Same would
> have to be done for TemplateEdits
> And then each time any similar module is added, check will need to be
> added.
>
> There is no central point, Synedit doesn't know. It was one of the
> important design goals that the syncro module can extend synedit,
> without synedit having to know about it.
> Which is why (even if fixed) the FirstLinePos, LastLinePos range will
> always include such kind of edits.
>
> Similar, it will be with persistent blocks, the can be moved to a new
> location, which will edit both places (delete them at the old place /
> insert them at the new place). Changed lines will be including all of
> this.
>
>>
>>
>>> In syncro mode, you can press enter inside a cell, and the cell
>>> willbecome multi-line => indenting in this case must be limited to
>>> the cell which was active,
>>> -FirstLinePos, LastLinePos will include the range for *all* cells =>
>>> if you indent every line in that range, the syncro module, will keep
>>> copying every change you make accross all cells => total chaos.
>>> - the caret will give you the correct range
>>>
>>
>> How?
>>
>
> After the example with the overwriting of a selection. The correct
> answer is:
> The caret and observing the selection (hooking synedit to know what it
> was before the edit action).
>
>
> The end of story is, it seems there is no simple way to do this.
> If I have time I will fix the line-range. But as far as I am concerned
> it is of little value. Using this (even now) the auto indent will
> cause big trouble if used during synro or template mode (if someone
> does paste into a cell)
>
> The combination of monitoring block and caret (and maybe even more)
> would solve it. (as already noted above => replacing a selected line
> OR replacing a partly selected line, including the linefeed)
>
> However instead of filling he generic beautifier with more and more
> IDE specific code, I would suggest to have a subclass of the
> Beautifier residing in source-editor. Every synedit that is created in
> the IDE will be assigned the special IDEBeautifier. the ide beautifier
> can then sort out what happened.
> It basically has to know how synedit will react, and calculate the
> required data.
>
>
> Martin
>
>
>
> --
> _______________________________________________
> Lazarus mailing list
> Lazarus at lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
More information about the Lazarus
mailing list