diff options
| author | Eli Zaretskii | 2018-06-06 18:28:44 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2018-06-06 18:28:44 +0300 |
| commit | e5ab25deaeb5daf58d2e3b0c990cd67e6020bb38 (patch) | |
| tree | 581e449920bba48915918905bd040926868c65e1 | |
| parent | d20beef5f104909f765430e347f5f3711ea51149 (diff) | |
| download | emacs-e5ab25deaeb5daf58d2e3b0c990cd67e6020bb38.tar.gz emacs-e5ab25deaeb5daf58d2e3b0c990cd67e6020bb38.zip | |
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)
| -rw-r--r-- | lisp/simple.el | 22 | ||||
| -rw-r--r-- | src/indent.c | 10 |
2 files changed, 7 insertions, 25 deletions
diff --git a/lisp/simple.el b/lisp/simple.el index bcf2b067704..cbad75193a4 100644 --- a/lisp/simple.el +++ b/lisp/simple.el | |||
| @@ -5972,10 +5972,6 @@ columns by which window is scrolled from left margin. | |||
| 5972 | When the `track-eol' feature is doing its job, the value is | 5972 | When the `track-eol' feature is doing its job, the value is |
| 5973 | `most-positive-fixnum'.") | 5973 | `most-positive-fixnum'.") |
| 5974 | 5974 | ||
| 5975 | (defvar last--line-number-width 0 | ||
| 5976 | "Last value of width used for displaying line numbers. | ||
| 5977 | Used internally by `line-move-visual'.") | ||
| 5978 | |||
| 5979 | (defcustom line-move-ignore-invisible t | 5975 | (defcustom line-move-ignore-invisible t |
| 5980 | "Non-nil means commands that move by lines ignore invisible newlines. | 5976 | "Non-nil means commands that move by lines ignore invisible newlines. |
| 5981 | When this option is non-nil, \\[next-line], \\[previous-line], \\[move-end-of-line], and \\[move-beginning-of-line] behave | 5977 | 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." | |||
| 6254 | (memq last-command `(next-line previous-line ,this-command))) | 6250 | (memq last-command `(next-line previous-line ,this-command))) |
| 6255 | ;; If so, there's no need to reset `temporary-goal-column', | 6251 | ;; If so, there's no need to reset `temporary-goal-column', |
| 6256 | ;; but we may need to hscroll. | 6252 | ;; but we may need to hscroll. |
| 6257 | (progn | 6253 | (if (or (/= (cdr temporary-goal-column) hscroll) |
| 6258 | (if (or (/= (cdr temporary-goal-column) hscroll) | 6254 | (> (cdr temporary-goal-column) 0)) |
| 6259 | (> (cdr temporary-goal-column) 0)) | 6255 | (setq target-hscroll (cdr temporary-goal-column))) |
| 6260 | (setq target-hscroll (cdr temporary-goal-column))) | ||
| 6261 | ;; Update the COLUMN part of temporary-goal-column if the | ||
| 6262 | ;; line-number display changed its width since the last | ||
| 6263 | ;; time. | ||
| 6264 | (setq temporary-goal-column | ||
| 6265 | (cons (+ (car temporary-goal-column) | ||
| 6266 | (/ (float (- lnum-width last--line-number-width)) | ||
| 6267 | (frame-char-width))) | ||
| 6268 | (cdr temporary-goal-column))) | ||
| 6269 | (setq last--line-number-width lnum-width)) | ||
| 6270 | ;; Otherwise, we should reset `temporary-goal-column'. | 6256 | ;; Otherwise, we should reset `temporary-goal-column'. |
| 6271 | (let ((posn (posn-at-point)) | 6257 | (let ((posn (posn-at-point)) |
| 6272 | x-pos) | 6258 | x-pos) |
| @@ -6276,7 +6262,7 @@ If NOERROR, don't signal an error if we can't move that many lines." | |||
| 6276 | ((memq (nth 1 posn) '(right-fringe left-fringe)) | 6262 | ((memq (nth 1 posn) '(right-fringe left-fringe)) |
| 6277 | (setq temporary-goal-column (cons (window-width) hscroll))) | 6263 | (setq temporary-goal-column (cons (window-width) hscroll))) |
| 6278 | ((car (posn-x-y posn)) | 6264 | ((car (posn-x-y posn)) |
| 6279 | (setq x-pos (car (posn-x-y posn))) | 6265 | (setq x-pos (- (car (posn-x-y posn)) lnum-width)) |
| 6280 | ;; In R2L lines, the X pixel coordinate is measured from the | 6266 | ;; In R2L lines, the X pixel coordinate is measured from the |
| 6281 | ;; left edge of the window, but columns are still counted | 6267 | ;; left edge of the window, but columns are still counted |
| 6282 | ;; from the logical-order beginning of the line, i.e. from | 6268 | ;; from the logical-order beginning of the line, i.e. from |
diff --git a/src/indent.c b/src/indent.c index 316171e609b..bcffa0d11e5 100644 --- a/src/indent.c +++ b/src/indent.c | |||
| @@ -2278,7 +2278,9 @@ whether or not it is currently displayed in some window. */) | |||
| 2278 | overshoot_handled = 1; | 2278 | overshoot_handled = 1; |
| 2279 | } | 2279 | } |
| 2280 | if (lcols_given) | 2280 | if (lcols_given) |
| 2281 | to_x = window_column_x (w, window, extract_float (lcols), lcols); | 2281 | to_x = |
| 2282 | window_column_x (w, window, extract_float (lcols), lcols) | ||
| 2283 | + lnum_pixel_width; | ||
| 2282 | if (nlines <= 0) | 2284 | if (nlines <= 0) |
| 2283 | { | 2285 | { |
| 2284 | it.vpos = vpos_init; | 2286 | it.vpos = vpos_init; |
| @@ -2330,12 +2332,6 @@ whether or not it is currently displayed in some window. */) | |||
| 2330 | an addition to the hscroll amount. */ | 2332 | an addition to the hscroll amount. */ |
| 2331 | if (lcols_given) | 2333 | if (lcols_given) |
| 2332 | { | 2334 | { |
| 2333 | /* If we are displaying line numbers, we could cross the | ||
| 2334 | line where the width of the line-number display changes, | ||
| 2335 | in which case we need to fix up the pixel coordinate | ||
| 2336 | accordingly. */ | ||
| 2337 | if (lnum_pixel_width > 0) | ||
| 2338 | to_x += it.lnum_pixel_width - lnum_pixel_width; | ||
| 2339 | move_it_in_display_line (&it, ZV, first_x + to_x, MOVE_TO_X); | 2335 | move_it_in_display_line (&it, ZV, first_x + to_x, MOVE_TO_X); |
| 2340 | /* If we find ourselves in the middle of an overlay string | 2336 | /* If we find ourselves in the middle of an overlay string |
| 2341 | which includes a newline after current string position, | 2337 | which includes a newline after current string position, |