summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-10-08 21:13:40 +0100
committerBram Moolenaar <Bram@vim.org>2022-10-08 21:13:40 +0100
commit8cf3459878198c5bb4a96f3c63214b2beccce341 (patch)
tree01a1000aa7e15f6577a2cd702043cf3675946870
parent25f3a146a0e4c731b8608f4cfbbfdf7a71b2d05e (diff)
patch 9.0.0701: with 'smoothscroll' cursor position not adjusted in long linev9.0.0701
Problem: With 'smoothscroll' the cursor position s not adjusted in a long line. Solution: Move the cursor further up or down in the line.
-rw-r--r--src/move.c42
-rw-r--r--src/testdir/dumps/Test_smooth_long_1.dump6
-rw-r--r--src/testdir/dumps/Test_smooth_long_2.dump6
-rw-r--r--src/testdir/dumps/Test_smooth_long_3.dump6
-rw-r--r--src/testdir/dumps/Test_smooth_long_4.dump6
-rw-r--r--src/testdir/dumps/Test_smooth_long_5.dump6
-rw-r--r--src/testdir/test_scroll_opt.vim28
-rw-r--r--src/version.c2
8 files changed, 100 insertions, 2 deletions
diff --git a/src/move.c b/src/move.c
index 139ee177ca..613791e3e9 100644
--- a/src/move.c
+++ b/src/move.c
@@ -1602,6 +1602,27 @@ scrolldown(
#endif
coladvance(curwin->w_curswant);
}
+
+ if (curwin->w_cursor.lnum == curwin->w_topline && do_sms)
+ {
+ // make sure the cursor is in the visible text
+ validate_virtcol();
+ int col = curwin->w_virtcol - curwin->w_skipcol;
+ int row = 0;
+ if (col >= width1)
+ {
+ col -= width1;
+ ++row;
+ }
+ if (col > width2)
+ {
+ row += col / width2;
+ col = col % width2;
+ }
+ if (row >= curwin->w_height)
+ coladvance(curwin->w_virtcol
+ - (row - curwin->w_height + 1) * width2);
+ }
}
/*
@@ -1651,8 +1672,7 @@ scrollup(
// for a closed fold: go to the last line in the fold
(void)hasFolding(lnum, NULL, &lnum);
# endif
- if (lnum == curwin->w_topline
- && curwin->w_p_wrap && curwin->w_p_sms)
+ if (lnum == curwin->w_topline && do_sms)
{
// 'smoothscroll': increase "w_skipcol" until it goes over
// the end of the line, then advance to the next line.
@@ -1725,6 +1745,24 @@ scrollup(
~(VALID_WROW|VALID_WCOL|VALID_CHEIGHT|VALID_CROW|VALID_VIRTCOL);
coladvance(curwin->w_curswant);
}
+ 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
+ validate_virtcol();
+ if (curwin->w_virtcol < curwin->w_skipcol + 3)
+ {
+ 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)
+ col += width2;
+ coladvance(col);
+ }
+ }
}
#ifdef FEAT_DIFF
diff --git a/src/testdir/dumps/Test_smooth_long_1.dump b/src/testdir/dumps/Test_smooth_long_1.dump
new file mode 100644
index 0000000000..a6f4cfb166
--- /dev/null
+++ b/src/testdir/dumps/Test_smooth_long_1.dump
@@ -0,0 +1,6 @@
+|L+0&#ffffff0|i|n|e| |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| |l|o|t|s| |o|f| |t|e
+| @21|3|,|1|0| @9|B|o|t|
diff --git a/src/testdir/dumps/Test_smooth_long_2.dump b/src/testdir/dumps/Test_smooth_long_2.dump
new file mode 100644
index 0000000000..0c2634f18c
--- /dev/null
+++ b/src/testdir/dumps/Test_smooth_long_2.dump
@@ -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|,|5|0| @9|B|o|t|
diff --git a/src/testdir/dumps/Test_smooth_long_3.dump b/src/testdir/dumps/Test_smooth_long_3.dump
new file mode 100644
index 0000000000..c06144c552
--- /dev/null
+++ b/src/testdir/dumps/Test_smooth_long_3.dump
@@ -0,0 +1,6 @@
+|<+0#4040ff13#ffffff0@2| +0#0000000&|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|i|t
+| @21|3|,|2|5|0| @8|B|o|t|
diff --git a/src/testdir/dumps/Test_smooth_long_4.dump b/src/testdir/dumps/Test_smooth_long_4.dump
new file mode 100644
index 0000000000..98f2c62563
--- /dev/null
+++ b/src/testdir/dumps/Test_smooth_long_4.dump
@@ -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|,|2|1|0| @8|B|o|t|
diff --git a/src/testdir/dumps/Test_smooth_long_5.dump b/src/testdir/dumps/Test_smooth_long_5.dump
new file mode 100644
index 0000000000..901baca90d
--- /dev/null
+++ b/src/testdir/dumps/Test_smooth_long_5.dump
@@ -0,0 +1,6 @@
+|L+0&#ffffff0|i|n|e| |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| |l|o|t|s| |o|f| |t|e
+| @21|3|,|1|7|0| @8|B|o|t|
diff --git a/src/testdir/test_scroll_opt.vim b/src/testdir/test_scroll_opt.vim
index 0292fa1f80..c369fa8642 100644
--- a/src/testdir/test_scroll_opt.vim
+++ b/src/testdir/test_scroll_opt.vim
@@ -198,5 +198,33 @@ func Test_smoothscroll_wrap_scrolloff_zero()
call StopVimInTerminal(buf)
endfunc
+func Test_smoothscroll_wrap_long_line()
+ CheckScreendump
+
+ let lines =<< trim END
+ vim9script
+ setline(1, ['one', 'two', 'Line' .. (' with lots of text'->repeat(30))])
+ set smoothscroll scrolloff=0
+ normal 3G10|zt
+ END
+ call writefile(lines, 'XSmoothWrap', 'D')
+ let buf = RunVimInTerminal('-S XSmoothWrap', #{rows: 6, cols: 40})
+ call VerifyScreenDump(buf, 'Test_smooth_long_1', {})
+
+ " scrolling up, cursor moves screen line down
+ call term_sendkeys(buf, "\<C-E>")
+ call VerifyScreenDump(buf, 'Test_smooth_long_2', {})
+ call term_sendkeys(buf, "5\<C-E>")
+ call VerifyScreenDump(buf, 'Test_smooth_long_3', {})
+
+ " scrolling down, cursor moves screen line up
+ call term_sendkeys(buf, "5\<C-Y>")
+ call VerifyScreenDump(buf, 'Test_smooth_long_4', {})
+ call term_sendkeys(buf, "\<C-Y>")
+ call VerifyScreenDump(buf, 'Test_smooth_long_5', {})
+
+ call StopVimInTerminal(buf)
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/version.c b/src/version.c
index 453df911f9..79ec146424 100644
--- a/src/version.c
+++ b/src/version.c
@@ -700,6 +700,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 701,
+/**/
700,
/**/
699,