comparison src/normal.c @ 18291:11f68eb58fda v8.1.2140

patch 8.1.2140: "gk" and "gj" do not work correctly in number column Commit: https://github.com/vim/vim/commit/ceba3dd5187788e09f65bd41b07b40f6f9aab953 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Oct 12 16:12:54 2019 +0200 patch 8.1.2140: "gk" and "gj" do not work correctly in number column Problem: "gk" and "gj" do not work correctly in number column. Solution: Allow for a negative "curswant". (Zach Wegner, closes https://github.com/vim/vim/issues/4969)
author Bram Moolenaar <Bram@vim.org>
date Sat, 12 Oct 2019 16:15:03 +0200
parents 5d67f207f7c3
children 9f51d0cef8da
comparison
equal deleted inserted replaced
18290:b31d3745f179 18291:11f68eb58fda
2497 { 2497 {
2498 if (linelen > width1) 2498 if (linelen > width1)
2499 n = ((linelen - width1 - 1) / width2 + 1) * width2 + width1; 2499 n = ((linelen - width1 - 1) / width2 + 1) * width2 + width1;
2500 else 2500 else
2501 n = width1; 2501 n = width1;
2502 if (curwin->w_curswant > (colnr_T)n + 1) 2502 if (curwin->w_curswant >= (colnr_T)n)
2503 curwin->w_curswant -= ((curwin->w_curswant - n) / width2 + 1) 2503 curwin->w_curswant = n - 1;
2504 * width2;
2505 } 2504 }
2506 2505
2507 while (dist--) 2506 while (dist--)
2508 { 2507 {
2509 if (dir == BACKWARD) 2508 if (dir == BACKWARD)
2510 { 2509 {
2511 if ((long)curwin->w_curswant > width2) 2510 if ((long)curwin->w_curswant >= width1)
2512 // move back within line 2511 // Move back within the line. This can give a negative value
2512 // for w_curswant if width1 < width2 (with cpoptions+=n),
2513 // which will get clipped to column 0.
2513 curwin->w_curswant -= width2; 2514 curwin->w_curswant -= width2;
2514 else 2515 else
2515 { 2516 {
2516 /* to previous line */ 2517 /* to previous line */
2517 if (curwin->w_cursor.lnum == 1) 2518 if (curwin->w_cursor.lnum == 1)
2555 retval = FAIL; 2556 retval = FAIL;
2556 break; 2557 break;
2557 } 2558 }
2558 curwin->w_cursor.lnum++; 2559 curwin->w_cursor.lnum++;
2559 curwin->w_curswant %= width2; 2560 curwin->w_curswant %= width2;
2561 // Check if the cursor has moved below the number display
2562 // when width1 < width2 (with cpoptions+=n). Subtract width2
2563 // to get a negative value for w_curswant, which will get
2564 // clipped to column 0.
2565 if (curwin->w_curswant >= width1)
2566 curwin->w_curswant -= width2;
2560 linelen = linetabsize(ml_get_curline()); 2567 linelen = linetabsize(ml_get_curline());
2561 } 2568 }
2562 } 2569 }
2563 } 2570 }
2564 } 2571 }