Re: [code] [textadept] Caret horizontal position jumps after buffer switch -- FIXED

From: Mitchell <m.att.foicica.com>
Date: Wed, 7 Aug 2019 11:07:37 -0400 (EDT)

Hi,

On Tue, 6 Aug 2019, Qwerky wrote:

>
> On 2019-08-06 15:47, Qwerky wrote:
>>
>>
>> On 2019-08-06 13:42, Mitchell wrote:
>>> Hi,
>>>
>>> On Tue, 6 Aug 2019, Qwerky wrote:
>>>
>>>> Hi.  In my /USERHOME/init.lua, I have buffer.caret_sticky set to
>>>> buffer.CARETSTICKY_OFF (the default, confirmed to be '0'); I have also
>>>> tried
>>>> the other sticky options.  Regardless, the caret's horizontal position
>>>> changes from what it was previously in a buffer, to a different position
>>>> when
>>>> switching back to that buffer (happens for all buffers).
>>>>
>>>> With two (or more) buffers open, place caret in buffer one at known
>>>> column,
>>>> eg. 10, and place caret in buffer two at different known column, eg. 20.
>>>> From
>>>> buffer one, switch to buffer two.  Move caret up a line and back down
>>>> again.
>>>> Switch back to buffer one, and move caret up (or down) a line.  Caret
>>>> jumps
>>>> from column 10 to column 20.
>>>>
>>>> Is there some other setting that is responsible for this (I have
>>>> searched!)?
>>>
>>> I think the simplest explanation is that caret sticky is not a per-buffer
>>> setting, but a per-view one.
>>>
>>> Textadept does its best to try and differentiate between buffers and views
>>> as we know them, but Scintilla doesn't always make this easy.
>>>
>>> Cheers,
>>> Mitchell
>>
>> Hi Mitchell,
>>
>> Thanks.  I can't say I fully understand, but accept your word on it.  When
>> I look at the code in /core/ui.lua for switching between buffers, it seems
>> to be saving/restoring the the caret location (which I believe includes
>> both line and column), so I don't really understand why the caret jumps
>> that way.  And I'm unsure what code modifications would correct the issue.
>> However, if someone saw a way to do so, I would not be averse to modifying
>> the (Lua) code, as long as it doesn't mean recompiling.  :-)
>>
>> qwerky
>>
> Hi Mitchell,
>
> This is just a hack, but it seems to correct the issue:  In the
> 'events_connect(events.BUFFER_AFTER_SWITCH)' function of /core/ui.lua, just
> before the end of the function (immediately following the line
> 'buffer.x_offset = buffer._x_offset or 0'), I placed the two lines
> 'buffer.char_right()' and 'buffer.char_left()'.
>
> It seems that after the switch, the caret position is restored, but not
> somehow anchored to where it should be, so it looses track when the caret is
> moved to a new line (up or down).  The above hack just moves the caret
> right/left to anchor that position, before the user can move the caret to a
> new line, and is invisible to the user.  But I'm sure that you will know the
> correct way to fix it.

I have committed a proper fix[1]. Thanks for looking into this!

Cheers,
Mitchell

[1]: https://foicica.com/hg/textadept/rev/e74361d427dd

-- 
You are subscribed to code.att.foicica.com.
To change subscription settings, send an e-mail to code+help.att.foicica.com.
To unsubscribe, send an e-mail to code+unsubscribe.att.foicica.com.
Received on Wed 07 Aug 2019 - 11:07:37 EDT

This archive was generated by hypermail 2.2.0 : Thu 08 Aug 2019 - 06:32:58 EDT