aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-07-05 04:28:14 +0800
committerGitHub <noreply@github.com>2022-07-04 13:28:14 -0700
commit826fe56f5cf30a823dc627b8a710174d04004cef (patch)
tree51bbea0e951123baac79eafee533a677a7d577e7
parent1803b0ffd7f08b50a3f59272ebe7290ffd21e90f (diff)
downloadrneovim-826fe56f5cf30a823dc627b8a710174d04004cef.tar.gz
rneovim-826fe56f5cf30a823dc627b8a710174d04004cef.tar.bz2
rneovim-826fe56f5cf30a823dc627b8a710174d04004cef.zip
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.
-rw-r--r--src/nvim/mark.c2
-rw-r--r--src/nvim/mark_defs.h3
-rw-r--r--test/functional/editor/jump_spec.lua28
3 files changed, 32 insertions, 1 deletions
diff --git a/src/nvim/mark.c b/src/nvim/mark.c
index 2402ea3035..0bf5875269 100644
--- a/src/nvim/mark.c
+++ b/src/nvim/mark.c
@@ -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);
}
diff --git a/src/nvim/mark_defs.h b/src/nvim/mark_defs.h
index 16d85a6e51..a78056c5f9 100644
--- a/src/nvim/mark_defs.h
+++ b/src/nvim/mark_defs.h
@@ -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 {
diff --git a/test/functional/editor/jump_spec.lua b/test/functional/editor/jump_spec.lua
index d3d3d7f79d..63f522fe6e 100644
--- a/test/functional/editor/jump_spec.lua
+++ b/test/functional/editor/jump_spec.lua
@@ -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)