]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.0.0707: with 'smoothscroll' cursor position not adjusted in long line v9.0.0707
authorBram Moolenaar <Bram@vim.org>
Sun, 9 Oct 2022 16:19:27 +0000 (17:19 +0100)
committerBram Moolenaar <Bram@vim.org>
Sun, 9 Oct 2022 16:19:27 +0000 (17:19 +0100)
Problem:    With 'smoothscroll' and 'scrolloff' non-zero the cursor position
            is not properly adjusted in a long line.
Solution:   Move the cursor further up or down in the line.

src/move.c
src/testdir/dumps/Test_smooth_long_6.dump [new file with mode: 0644]
src/testdir/dumps/Test_smooth_long_7.dump [new file with mode: 0644]
src/testdir/dumps/Test_smooth_long_8.dump [new file with mode: 0644]
src/testdir/dumps/Test_smooth_long_9.dump [new file with mode: 0644]
src/testdir/test_scroll_opt.vim
src/version.c

index 613791e3e9f35b5b9bb58987f9a65d3f8c193c15..32cd6f37e73c79d1f94e4cf7215da5a3c8df80a3 100644 (file)
@@ -1605,9 +1605,12 @@ scrolldown(
 
     if (curwin->w_cursor.lnum == curwin->w_topline && do_sms)
     {
+       long    so = curwin->w_p_so >= 0 ? curwin->w_p_so : p_so;
+       int     scrolloff_cols = so == 0 ? 0 : width1 + (so - 1) * width2;
+
        // make sure the cursor is in the visible text
        validate_virtcol();
-       int col = curwin->w_virtcol - curwin->w_skipcol;
+       int col = curwin->w_virtcol - curwin->w_skipcol + scrolloff_cols;
        int row = 0;
        if (col >= width1)
        {
@@ -1620,8 +1623,11 @@ scrolldown(
            col = col % width2;
        }
        if (row >= curwin->w_height)
-           coladvance(curwin->w_virtcol
-                                     - (row - curwin->w_height + 1) * width2);
+       {
+           curwin->w_curswant = curwin->w_virtcol
+                                      - (row - curwin->w_height + 1) * width2;
+           coladvance(curwin->w_curswant);
+       }
     }
 }
 
@@ -1748,19 +1754,24 @@ scrollup(
     if (curwin->w_cursor.lnum == curwin->w_topline
                                            && do_sms && curwin->w_skipcol > 0)
     {
-       // make sure the cursor is in a visible part of the line
+       int     width1 = curwin->w_width - curwin_col_off();
+       int     width2 = width1 + curwin_col_off2();
+       long    so = curwin->w_p_so >= 0 ? curwin->w_p_so : p_so;
+       int     scrolloff_cols = so == 0 ? 0 : width1 + (so - 1) * width2;
+
+       // Make sure the cursor is in a visible part of the line, taking
+       // 'scrolloff' into account, but using screen lines.
        validate_virtcol();
-       if (curwin->w_virtcol < curwin->w_skipcol + 3)
+       if (curwin->w_virtcol < curwin->w_skipcol + 3 + scrolloff_cols)
        {
-           int     width1 = curwin->w_width - curwin_col_off();
-           int     width2 = width1 + curwin_col_off2();
            colnr_T col = curwin->w_virtcol;
 
            if (col < width1)
                col += width1;
-           while (col < curwin->w_skipcol + 3)
+           while (col < curwin->w_skipcol + 3 + scrolloff_cols)
                col += width2;
-           coladvance(col);
+           curwin->w_curswant = col;
+           coladvance(curwin->w_curswant);
        }
     }
 }
diff --git a/src/testdir/dumps/Test_smooth_long_6.dump b/src/testdir/dumps/Test_smooth_long_6.dump
new file mode 100644 (file)
index 0000000..b7ef6bf
--- /dev/null
@@ -0,0 +1,6 @@
+|<+0#4040ff13#ffffff0@2|t+0#0000000&|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t
+|h| |l|o|t|s| |o|f> |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o
+|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o
+|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e
+|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w
+| @21|3|,|9|0| @9|B|o|t| 
diff --git a/src/testdir/dumps/Test_smooth_long_7.dump b/src/testdir/dumps/Test_smooth_long_7.dump
new file mode 100644 (file)
index 0000000..27cb393
--- /dev/null
@@ -0,0 +1,6 @@
+|<+0#4040ff13#ffffff0@2|t+0#0000000&|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t
+|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o
+|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o
+|f| |t|e|x|t| |w|i>t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e
+|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w
+| @21|3|,|1|7|0| @8|B|o|t| 
diff --git a/src/testdir/dumps/Test_smooth_long_8.dump b/src/testdir/dumps/Test_smooth_long_8.dump
new file mode 100644 (file)
index 0000000..c796d9a
--- /dev/null
@@ -0,0 +1,6 @@
+|<+0#4040ff13#ffffff0@2|t+0#0000000&|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t
+|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o
+|t|s| |o|f| |t|e|x>t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o
+|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e
+|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w
+| @21|3|,|1|3|0| @8|B|o|t| 
diff --git a/src/testdir/dumps/Test_smooth_long_9.dump b/src/testdir/dumps/Test_smooth_long_9.dump
new file mode 100644 (file)
index 0000000..d3e6a08
--- /dev/null
@@ -0,0 +1,6 @@
+|<+0#4040ff13#ffffff0@2|o+0#0000000&|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o
+|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o
+|f| |t|e|x|t| |w|i>t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e
+|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w
+|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| 
+@22|3|,|1|7|0| @8|B|o|t| 
index c369fa86426a022d8455502d6533ac04eb2cda4b..5bea957235b6618723b664d8eca427519ddddf1e 100644 (file)
@@ -223,6 +223,28 @@ func Test_smoothscroll_wrap_long_line()
   call term_sendkeys(buf, "\<C-Y>")
   call VerifyScreenDump(buf, 'Test_smooth_long_5', {})
 
+  " 'scrolloff' set to 1, scrolling up, cursor moves screen line down
+  call term_sendkeys(buf, ":set scrolloff=1\<CR>")
+  call term_sendkeys(buf, "10|\<C-E>")
+  call VerifyScreenDump(buf, 'Test_smooth_long_6', {})
+  
+  " 'scrolloff' set to 1, scrolling down, cursor moves screen line up
+  call term_sendkeys(buf, "\<C-E>")
+  call term_sendkeys(buf, "gjgj")
+  call term_sendkeys(buf, "\<C-Y>")
+  call VerifyScreenDump(buf, 'Test_smooth_long_7', {})
+  
+  " 'scrolloff' set to 2, scrolling up, cursor moves screen line down
+  call term_sendkeys(buf, ":set scrolloff=2\<CR>")
+  call term_sendkeys(buf, "10|\<C-E>")
+  call VerifyScreenDump(buf, 'Test_smooth_long_8', {})
+  
+  " 'scrolloff' set to 2, scrolling down, cursor moves screen line up
+  call term_sendkeys(buf, "\<C-E>")
+  call term_sendkeys(buf, "gj")
+  call term_sendkeys(buf, "\<C-Y>")
+  call VerifyScreenDump(buf, 'Test_smooth_long_9', {})
+  
   call StopVimInTerminal(buf)
 endfunc
 
index 9adceae12dd399bb7541a0987043a7db89f042c1..f006710d9bcae9c1a28b63c4a46f39699dce8399 100644 (file)
@@ -699,6 +699,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    707,
 /**/
     706,
 /**/