1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-11-23 07:19:15 +00:00

Fix cursor movement by 'next-logical-line' after 'next-line'

* src/indent.c (Fvertical_motion): Adjust TO_X when line-numbers
are being displayed.  Remove unneeded "correction" of TO_X at the
goal line.

* lisp/simple.el (last--line-number-width): Remove unneeded
variable.
(line-move-visual): Account for line-number display width by
adjusting the pixel X coordinate that gets converted into
canonical columns passed to vertical-motion, instead of adjusting
temporary-goal-column (which then affects next commands, including
next-logical-line).  (Bug#31723)
This commit is contained in:
Eli Zaretskii 2018-06-06 18:28:44 +03:00
parent d20beef5f1
commit e5ab25deae
2 changed files with 7 additions and 25 deletions

View File

@ -5972,10 +5972,6 @@ columns by which window is scrolled from left margin.
When the `track-eol' feature is doing its job, the value is
`most-positive-fixnum'.")
(defvar last--line-number-width 0
"Last value of width used for displaying line numbers.
Used internally by `line-move-visual'.")
(defcustom line-move-ignore-invisible t
"Non-nil means commands that move by lines ignore invisible newlines.
When this option is non-nil, \\[next-line], \\[previous-line], \\[move-end-of-line], and \\[move-beginning-of-line] behave
@ -6254,19 +6250,9 @@ If NOERROR, don't signal an error if we can't move that many lines."
(memq last-command `(next-line previous-line ,this-command)))
;; If so, there's no need to reset `temporary-goal-column',
;; but we may need to hscroll.
(progn
(if (or (/= (cdr temporary-goal-column) hscroll)
(> (cdr temporary-goal-column) 0))
(setq target-hscroll (cdr temporary-goal-column)))
;; Update the COLUMN part of temporary-goal-column if the
;; line-number display changed its width since the last
;; time.
(setq temporary-goal-column
(cons (+ (car temporary-goal-column)
(/ (float (- lnum-width last--line-number-width))
(frame-char-width)))
(cdr temporary-goal-column)))
(setq last--line-number-width lnum-width))
;; Otherwise, we should reset `temporary-goal-column'.
(let ((posn (posn-at-point))
x-pos)
@ -6276,7 +6262,7 @@ If NOERROR, don't signal an error if we can't move that many lines."
((memq (nth 1 posn) '(right-fringe left-fringe))
(setq temporary-goal-column (cons (window-width) hscroll)))
((car (posn-x-y posn))
(setq x-pos (car (posn-x-y posn)))
(setq x-pos (- (car (posn-x-y posn)) lnum-width))
;; In R2L lines, the X pixel coordinate is measured from the
;; left edge of the window, but columns are still counted
;; from the logical-order beginning of the line, i.e. from

View File

@ -2278,7 +2278,9 @@ whether or not it is currently displayed in some window. */)
overshoot_handled = 1;
}
if (lcols_given)
to_x = window_column_x (w, window, extract_float (lcols), lcols);
to_x =
window_column_x (w, window, extract_float (lcols), lcols)
+ lnum_pixel_width;
if (nlines <= 0)
{
it.vpos = vpos_init;
@ -2330,12 +2332,6 @@ whether or not it is currently displayed in some window. */)
an addition to the hscroll amount. */
if (lcols_given)
{
/* If we are displaying line numbers, we could cross the
line where the width of the line-number display changes,
in which case we need to fix up the pixel coordinate
accordingly. */
if (lnum_pixel_width > 0)
to_x += it.lnum_pixel_width - lnum_pixel_width;
move_it_in_display_line (&it, ZV, first_x + to_x, MOVE_TO_X);
/* If we find ourselves in the middle of an overlay string
which includes a newline after current string position,