Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(mark): do not try to restore the view of a mark without a view #19224

Merged
merged 1 commit into from
Jul 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/nvim/mark.c
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,8 @@ void mark_view_restore(fmark_T *fm)
{
if (fm != NULL && fm->view.topline_offset >= 0) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW I didn't notice this >= 0 check previously. Then a negative number can also indicate that there is no view.

linenr_T topline = fm->mark.lnum - fm->view.topline_offset;
// If the mark does not have a view, topline_offset is MAXLNUM,
// and this check can prevent restoring mark view in that case.
if (topline >= 1) {
set_topline(curwin, topline);
}
Expand Down
3 changes: 2 additions & 1 deletion src/nvim/mark_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ typedef enum {
/// Represents view in which the mark was created
typedef struct fmarkv {
linenr_T topline_offset; ///< Amount of lines from the mark lnum to the top of the window.
///< Use MAXLNUM to indicate that the mark does not have a view.
} fmarkv_T;

#define INIT_FMARKV { 0 }
#define INIT_FMARKV { MAXLNUM }

/// Structure defining single local mark
typedef struct filemark {
Expand Down
28 changes: 28 additions & 0 deletions test/functional/editor/jump_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -251,4 +251,32 @@ describe("jumpoptions=view", function()
|
]])
end)

it('falls back to standard behavior for a mark without a view', function()
local screen = Screen.new(5, 8)
screen:attach()
command('edit ' .. file1)
feed('10ggzzvwy')
screen:expect([[
7 line |
8 line |
9 line |
^10 line |
11 line |
12 line |
13 line |
|
]])
feed('`]')
screen:expect([[
7 line |
8 line |
9 line |
10 ^line |
11 line |
12 line |
13 line |
|
]])
end)
end)