Skip to content

Commit

Permalink
fix(folds): cursorline highlight is not always applied on closed folds
Browse files Browse the repository at this point in the history
Problem:    The cursor line number was inaccurate when closing a fold
            and when moving to a closed fold with screenrow motions.
Solution:   Update cursor line number to the first line of the closed
            fold.

Fix #22232
  • Loading branch information
luukvbaal committed Feb 13, 2023
1 parent 5d3769e commit 956ccd5
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 83 deletions.
3 changes: 3 additions & 0 deletions src/nvim/fold.c
Original file line number Diff line number Diff line change
Expand Up @@ -1266,6 +1266,9 @@ static linenr_T setManualFoldWin(win_T *wp, linenr_T lnum, int opening, int recu
wp->w_fold_manual = true;
if (done & DONE_ACTION) {
changed_window_setting_win(wp);
if (!opening) {
foldAdjustCursor(); // Make sure cursor is at start of closed fold
}
}
done |= DONE_FOLD;
} else if (donep == NULL && wp == curwin) {
Expand Down
1 change: 1 addition & 0 deletions src/nvim/normal.c
Original file line number Diff line number Diff line change
Expand Up @@ -2534,6 +2534,7 @@ static bool nv_screengo(oparg_T *oap, int dir, long dist)
}
}

foldAdjustCursor(); // Adjust for when cursor has landed on a closed fold
if (virtual_active() && atend) {
coladvance(MAXCOL);
} else {
Expand Down
174 changes: 91 additions & 83 deletions test/functional/ui/fold_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ local meths = helpers.meths
local exec = helpers.exec
local exec_lua = helpers.exec_lua
local assert_alive = helpers.assert_alive
local poke_eventloop = helpers.poke_eventloop


local content1 = [[
Expand Down Expand Up @@ -90,112 +91,119 @@ describe("folded lines", function()
end)

it("highlights with CursorLineFold when 'cursorline' is set", function()
command("set cursorline foldcolumn=2 foldmethod=marker")
command("set number cursorline foldcolumn=2 foldmethod=marker")
command("hi link CursorLineFold Search")
insert(content1)
feed("zf3j")
feed("ggzf3jj")
if multigrid then
screen:expect([[
## grid 1
[2:---------------------------------------------]|
[2:---------------------------------------------]|
[2:---------------------------------------------]|
[2:---------------------------------------------]|
[2:---------------------------------------------]|
[2:---------------------------------------------]|
[2:---------------------------------------------]|
[3:---------------------------------------------]|
## grid 2
{7: }This is a |
{7: }valid English |
{7: }sentence composed by |
{7: }an exhausted developer |
{7: }in his cave. |
{6: }{12:^ }|
{1:~ }|
## grid 3
|
## grid 1
[2:---------------------------------------------]|
[2:---------------------------------------------]|
[2:---------------------------------------------]|
[2:---------------------------------------------]|
[2:---------------------------------------------]|
[2:---------------------------------------------]|
[2:---------------------------------------------]|
[3:---------------------------------------------]|
## grid 2
{7:+ }{8: 1 }{5:+-- 4 lines: This is a················}|
{6: }{9: 5 }{12:^in his cave. }|
{7: }{8: 6 } |
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
## grid 3
|
]])
else
screen:expect([[
{7: }This is a |
{7: }valid English |
{7: }sentence composed by |
{7: }an exhausted developer |
{7: }in his cave. |
{6: }{12:^ }|
{1:~ }|
|
{7:+ }{8: 1 }{5:+-- 4 lines: This is a················}|
{6: }{9: 5 }{12:^in his cave. }|
{7: }{8: 6 } |
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
|
]])
end
feed("k")
if multigrid then
screen:expect([[
## grid 1
[2:---------------------------------------------]|
[2:---------------------------------------------]|
[2:---------------------------------------------]|
[2:---------------------------------------------]|
[2:---------------------------------------------]|
[2:---------------------------------------------]|
[2:---------------------------------------------]|
[3:---------------------------------------------]|
## grid 2
{7: }This is a |
{7: }valid English |
{7: }sentence composed by |
{7: }an exhausted developer |
{6: }{12:^in his cave. }|
{7: } |
{1:~ }|
## grid 3
|
## grid 1
[2:---------------------------------------------]|
[2:---------------------------------------------]|
[2:---------------------------------------------]|
[2:---------------------------------------------]|
[2:---------------------------------------------]|
[2:---------------------------------------------]|
[2:---------------------------------------------]|
[3:---------------------------------------------]|
## grid 2
{6:+ }{9: 1 }{12:^+-- 4 lines: This is a················}|
{7: }{8: 5 }in his cave. |
{7: }{8: 6 } |
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
## grid 3
|
]])
else
screen:expect([[
{7: }This is a |
{7: }valid English |
{7: }sentence composed by |
{7: }an exhausted developer |
{6: }{12:^in his cave. }|
{7: } |
{1:~ }|
|
{6:+ }{9: 1 }{12:^+-- 4 lines: This is a················}|
{7: }{8: 5 }in his cave. |
{7: }{8: 6 } |
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
|
]])
end
-- CursorLine is applied correctly with screenrow motions and when closing a fold #22232
feed("jgk")
poke_eventloop()
screen:expect_unchanged()
feed("zojzc")
poke_eventloop()
screen:expect_unchanged()
command("set cursorlineopt=line")
if multigrid then
screen:expect([[
## grid 1
[2:---------------------------------------------]|
[2:---------------------------------------------]|
[2:---------------------------------------------]|
[2:---------------------------------------------]|
[2:---------------------------------------------]|
[2:---------------------------------------------]|
[2:---------------------------------------------]|
[3:---------------------------------------------]|
## grid 2
{7: }This is a |
{7: }valid English |
{7: }sentence composed by |
{7: }an exhausted developer |
{7: }{12:^in his cave. }|
{7: } |
{1:~ }|
## grid 3
|
## grid 1
[2:---------------------------------------------]|
[2:---------------------------------------------]|
[2:---------------------------------------------]|
[2:---------------------------------------------]|
[2:---------------------------------------------]|
[2:---------------------------------------------]|
[2:---------------------------------------------]|
[3:---------------------------------------------]|
## grid 2
{7:+ }{8: 1 }{12:^+-- 4 lines: This is a················}|
{7: }{8: 5 }in his cave. |
{7: }{8: 6 } |
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
## grid 3
|
]])
else
screen:expect([[
{7: }This is a |
{7: }valid English |
{7: }sentence composed by |
{7: }an exhausted developer |
{7: }{12:^in his cave. }|
{7: } |
{1:~ }|
|
{7:+ }{8: 1 }{12:^+-- 4 lines: This is a················}|
{7: }{8: 5 }in his cave. |
{7: }{8: 6 } |
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
|
]])
end
end)
Expand Down

0 comments on commit 956ccd5

Please sign in to comment.