mirror of
https://github.com/neovim/neovim.git
synced 2025-09-29 22:48:34 +00:00
fix(mark): mark without a view restores at topline #19224
For a local mark without a view, currently trying to restore its view will put the cursor at topline, which is not the correct behavior. Initialize `topline_offset` to `MAXLNUM` instead to fix this.
This commit is contained in:
@@ -607,6 +607,8 @@ void mark_view_restore(fmark_T *fm)
|
||||
{
|
||||
if (fm != NULL && fm->view.topline_offset >= 0) {
|
||||
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);
|
||||
}
|
||||
|
@@ -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 {
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user