Menu

#1996 Scintilla: Editor::lastXChosen has incorrect initilal value

Bug
open
nobody
None
5
2018-02-08
2018-02-08
No

Scintilla 3.7.6, Editor class, lastXChosen member.

An editor (such as SciTE) during initialization sends commands SCI_SETMARGINLEFT and SCI_SETMARGINWIDTHN to Scintilla. Scintilla, while performing these commands, corrects lastXChosen. I noticed lastXChosensometimes becomes negative. Even if it remains positive, it has incorrect value until the first user input event (such as mouse click or keypress).

For example, after starting SciTE (on my system with my configuration) with a file, the caret is in the first line before the first character (i. e. in position 0), lastXChosen is 37. After moving the caret one character right, it becomes 65, after moving the caret one character left (i. e. returning to initial position), it becomes 54 (note: not 37).

I tracked down the problem. Editor constructor initializes lastXChosen to 0, but 0is not a correct initial value for lastXChosen. Sum of all margins looks like better choice.

If proposed patch is applied, my experiment shows that initial value of lastXChosen is 54( not 37 as before), then it becomes 65, then returns back to 54.

1 Attachments

Related

Bugs: #2415

Discussion

  • Neil Hodgson

    Neil Hodgson - 2018-02-08

    This looks wrong for margin outside platforms like Cocoa where the margins are in a separate view.

    The Editor constructor is run before ViewStyle::marginInside is reset. Maybe change constructors so that marginInside is initialized to correct value instead of being changed later in ScintillaCocoa constructor.

    ViewStyle::CalculateMarginWidthAndMask has already added up the widths of the margins to get fixedColumnWidth at the point the patch is setting lastXChosen.

     
  • Neil Hodgson

    Neil Hodgson - 2018-02-08

    Does a low value for lastXChosen affect any behaviour? It should just result in vertical key movement hugging the left side just as it would with an accurate value.

     
    • Van de Bugger

      Van de Bugger - 2018-02-09

      Does a low value for lastXChosen affect any behaviour?

      It probably does not affects stock Scintilla.

      It should just result in vertical key movement hugging the left side just as it would with an accurate value.

      I am experimenting with "wobble-free" vertical caret movement (it highly depends on lastXChosen) and noticed that lastXChosen is not correct at the very beginning. I thought is is better to make it correct from the beginning rather than check "is this correct?" every time.

      This looks wrong for margin outside platforms…

      May be. Proposed patch works for me (Linux/GTK, tested in SciTE and Geany), but I am not an experienced Scintilla (and GUI in general) hacker, so it may be not fully correct on other platforms.

       
      • Neil Hodgson

        Neil Hodgson - 2018-02-09

        Checked the Cocoa test application and it leads to an initial down arrow moving to the right by the width of the margins.

        Because the patch is inside the Editor contructor, it doesn't know the margins are in a separate view. This code should either be run later after marginInside is set by the most derived constructor or the constructor chain take arguments so that it is accurate by the time the Editor constructor is run.

        Another possibility would be to make lastXChosen be relative to the text origin which is more sensible although that would affect and destabilize much more code.

         

Log in to post a comment.

MongoDB Logo MongoDB