#1512 Wrong horizontal caret position

scintilla (326)

When changing the margin width (any margin), the memorized X position of the caret doesn't get adjusted properly, a vertical change then jumps to the wrong horizontal position.

Steps to reproduce:
- open SciTE
- if enabled, disable "View -> Line Numbers"
- enter two lines each containing "012345678"
- place the caret between 7 and 8 of the first line
- enable "View -> Line Numbers"
- press the arrow down key to move the caret down
- notice how the caret jumps a few characters to the left

This is because the last X position is remembered in pixels from the left of the window including all margins, but isn't updated when any margin changes (by SCI_SETMARGINWIDTHN). I came across this problem in the Notepad++ bug tracker, it happens there f.e. when going from 3 digit to 4 digit line numbers and the margin width is automatically adjusted.

There is another margin that can be changed with SCI_SETMARGINLEFT, it has the same problem. This one is mostly constant after initialization, but since I'm at it...

To reproduce it, do this:
- open SciTE
- go to "Options -> Open Global Options File"
- search for "blank.margin.left" and uncomment it
- place the caret before the 4 (the default value) and enter a 6, making it 64
- press Ctrl+S to save, the options will take effect and make a big margin
- press the arrow up/down key to move the caret up/down
- notice how the caret jumps a few characters to the left

This problem is in all revisions up to and including 53b22698a1b0 (the current one at the time of this report). The attached patch consists of basically two one-liners that adjust the memorized position by the amount of change in both places.

A similar problem exists when the zoom level is changed, the memorized X position is not adjusted. But fixing this one is not as simple if rounding errors must be avoided (f.e. zooming in or out n steps and back again should result in the same X position as before), therefore I left it as is.

1 Attachments


  • Neil Hodgson

    Neil Hodgson - 2013-08-08
    • labels: --> scintilla
    • status: open --> open-fixed
    • assigned_to: Neil Hodgson
  • Neil Hodgson

    Neil Hodgson - 2013-08-31
    • status: open-fixed --> closed-fixed

Log in to post a comment.