aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/doc/vim_diff.txt3
-rw-r--r--src/nvim/edit.c9
-rw-r--r--src/nvim/mark.c16
-rw-r--r--src/nvim/shada.c2
-rw-r--r--src/nvim/window.c21
-rw-r--r--test/functional/normal/jump_spec.lua48
-rw-r--r--test/functional/shada/marks_spec.lua6
-rw-r--r--test/functional/shada/merging_spec.lua11
8 files changed, 90 insertions, 26 deletions
diff --git a/runtime/doc/vim_diff.txt b/runtime/doc/vim_diff.txt
index 7c3f6f9ce8..1833c2cde3 100644
--- a/runtime/doc/vim_diff.txt
+++ b/runtime/doc/vim_diff.txt
@@ -319,6 +319,9 @@ Macro/|recording| behavior
macros and 'keymap' at the same time. This also means you can use |:imap| on
the results of keys from 'keymap'.
+Motion:
+ The |jumplist| avoids useless/phantom jumps.
+
Normal commands:
|Q| is the same as |gQ|
diff --git a/src/nvim/edit.c b/src/nvim/edit.c
index e6d9dcf092..4d22d427e4 100644
--- a/src/nvim/edit.c
+++ b/src/nvim/edit.c
@@ -667,8 +667,9 @@ static int insert_execute(VimState *state, int key)
// there is nothing to add, CTRL-L works like CTRL-P then.
if (s->c == Ctrl_L
&& (!CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode)
- || (int)STRLEN(compl_shown_match->cp_str)
- > curwin->w_cursor.col - compl_col)) {
+ || (compl_shown_match->cp_str != NULL
+ && (int)STRLEN(compl_shown_match->cp_str)
+ > curwin->w_cursor.col - compl_col))) {
ins_compl_addfrommatch();
return 1; // continue
}
@@ -3005,7 +3006,6 @@ bool ins_compl_active(void)
// Get complete information
void get_complete_info(list_T *what_list, dict_T *retdict)
{
- int ret = OK;
#define CI_WHAT_MODE 0x01
#define CI_WHAT_PUM_VISIBLE 0x02
#define CI_WHAT_ITEMS 0x04
@@ -3037,7 +3037,8 @@ void get_complete_info(list_T *what_list, dict_T *retdict)
}
}
- if (ret == OK && (what_flag & CI_WHAT_MODE)) {
+ int ret = OK;
+ if (what_flag & CI_WHAT_MODE) {
ret = tv_dict_add_str(retdict, S_LEN("mode"),
(char *)ins_compl_mode());
}
diff --git a/src/nvim/mark.c b/src/nvim/mark.c
index af404c354b..ecd1f098ca 100644
--- a/src/nvim/mark.c
+++ b/src/nvim/mark.c
@@ -1188,9 +1188,23 @@ void cleanup_jumplist(void)
xfree(curwin->w_jumplist[from].fname);
}
}
- if (curwin->w_jumplistidx == curwin->w_jumplistlen)
+ if (curwin->w_jumplistidx == curwin->w_jumplistlen) {
curwin->w_jumplistidx = to;
+ }
curwin->w_jumplistlen = to;
+
+ // When pointer is below last jump, remove the jump if it matches the current
+ // line. This avoids useless/phantom jumps. #9805
+ if (curwin->w_jumplistlen
+ && curwin->w_jumplistidx == curwin->w_jumplistlen) {
+ const xfmark_T *fm_last = &curwin->w_jumplist[curwin->w_jumplistlen - 1];
+ if (fm_last->fmark.fnum == curbuf->b_fnum
+ && fm_last->fmark.mark.lnum == curwin->w_cursor.lnum) {
+ xfree(fm_last->fname);
+ curwin->w_jumplistlen--;
+ curwin->w_jumplistidx--;
+ }
+ }
}
/*
diff --git a/src/nvim/shada.c b/src/nvim/shada.c
index 8864301e4c..658cd1ba46 100644
--- a/src/nvim/shada.c
+++ b/src/nvim/shada.c
@@ -2739,8 +2739,8 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer,
// Initialize jump list
const void *jump_iter = NULL;
- setpcmark();
cleanup_jumplist();
+ setpcmark();
do {
xfmark_T fm;
jump_iter = mark_jumplist_iter(jump_iter, curwin, &fm);
diff --git a/src/nvim/window.c b/src/nvim/window.c
index ad38a34dac..e135d7436d 100644
--- a/src/nvim/window.c
+++ b/src/nvim/window.c
@@ -2575,15 +2575,12 @@ void win_close_othertab(win_T *win, int free_buf, tabpage_T *tp)
free_tabpage(tp);
}
-/*
- * Free the memory used for a window.
- * Returns a pointer to the window that got the freed up space.
- */
-static win_T *
-win_free_mem (
+// Free the memory used for a window.
+// Returns a pointer to the window that got the freed up space.
+static win_T *win_free_mem(
win_T *win,
- int *dirp, /* set to 'v' or 'h' for direction if 'ea' */
- tabpage_T *tp /* tab page "win" is in, NULL for current */
+ int *dirp, // set to 'v' or 'h' for direction if 'ea'
+ tabpage_T *tp // tab page "win" is in, NULL for current
)
{
frame_T *frp;
@@ -2595,6 +2592,7 @@ win_free_mem (
wp = winframe_remove(win, dirp, tp);
xfree(frp);
} else {
+ *dirp = 'h'; // Dummy value.
if (win_valid(prevwin) && prevwin != win) {
wp = prevwin;
} else {
@@ -2603,10 +2601,11 @@ win_free_mem (
}
win_free(win, tp);
- /* When deleting the current window of another tab page select a new
- * current window. */
- if (tp != NULL && win == tp->tp_curwin)
+ // When deleting the current window of another tab page select a new
+ // current window.
+ if (tp != NULL && win == tp->tp_curwin) {
tp->tp_curwin = wp;
+ }
return wp;
}
diff --git a/test/functional/normal/jump_spec.lua b/test/functional/normal/jump_spec.lua
new file mode 100644
index 0000000000..5bed541752
--- /dev/null
+++ b/test/functional/normal/jump_spec.lua
@@ -0,0 +1,48 @@
+local helpers = require('test.functional.helpers')(after_each)
+
+local clear = helpers.clear
+local command = helpers.command
+local eq = helpers.eq
+local funcs = helpers.funcs
+local feed = helpers.feed
+local write_file = helpers.write_file
+
+describe('jumplist', function()
+ local fname1 = 'Xtest-functional-normal-jump'
+ local fname2 = fname1..'2'
+ before_each(clear)
+ after_each(function()
+ os.remove(fname1)
+ os.remove(fname2)
+ end)
+
+ it('does not add a new entry on startup', function()
+ eq('\n jump line col file/text\n>', funcs.execute('jumps'))
+ end)
+
+ it('does not require two <C-O> strokes to jump back', function()
+ write_file(fname1, 'first file contents')
+ write_file(fname2, 'second file contents')
+
+ command('args '..fname1..' '..fname2)
+ local buf1 = funcs.bufnr(fname1)
+ local buf2 = funcs.bufnr(fname2)
+
+ command('next')
+ feed('<C-O>')
+ eq(buf1, funcs.bufnr('%'))
+
+ command('first')
+ command('snext')
+ feed('<C-O>')
+ eq(buf1, funcs.bufnr('%'))
+ feed('<C-I>')
+ eq(buf2, funcs.bufnr('%'))
+ feed('<C-O>')
+ eq(buf1, funcs.bufnr('%'))
+
+ command('drop '..fname2)
+ feed('<C-O>')
+ eq(buf1, funcs.bufnr('%'))
+ end)
+end)
diff --git a/test/functional/shada/marks_spec.lua b/test/functional/shada/marks_spec.lua
index c2f6351e00..e6450e68b3 100644
--- a/test/functional/shada/marks_spec.lua
+++ b/test/functional/shada/marks_spec.lua
@@ -189,9 +189,6 @@ describe('ShaDa support code', function()
eq(1, nvim_current_line())
nvim_command('execute "normal! \\<C-o>"')
eq(testfilename, funcs.bufname('%'))
- eq(1, nvim_current_line())
- nvim_command('execute "normal! \\<C-o>"')
- eq(testfilename, funcs.bufname('%'))
eq(2, nvim_current_line())
nvim_command('execute "normal! \\<C-o>"')
eq(testfilename_2, funcs.bufname('%'))
@@ -199,6 +196,9 @@ describe('ShaDa support code', function()
nvim_command('execute "normal! \\<C-o>"')
eq(testfilename_2, funcs.bufname('%'))
eq(2, nvim_current_line())
+ nvim_command('execute "normal! \\<C-o>"')
+ eq(testfilename_2, funcs.bufname('%'))
+ eq(2, nvim_current_line())
end)
it('is able to dump and restore change list', function()
diff --git a/test/functional/shada/merging_spec.lua b/test/functional/shada/merging_spec.lua
index a628baff53..22f2b8348d 100644
--- a/test/functional/shada/merging_spec.lua
+++ b/test/functional/shada/merging_spec.lua
@@ -912,12 +912,11 @@ describe('ShaDa jumps support code', function()
eq('', curbufmeths.get_name())
eq('\n'
.. ' jump line col file/text\n'
- .. ' 6 2 0 ' .. mock_file_path .. 'c\n'
- .. ' 5 2 0 ' .. mock_file_path .. 'd\n'
- .. ' 4 3 0 ' .. mock_file_path .. 'd\n'
- .. ' 3 2 0 ' .. mock_file_path .. 'e\n'
- .. ' 2 2 0 ' .. mock_file_path .. 'f\n'
- .. ' 1 1 0 \n'
+ .. ' 5 2 0 ' .. mock_file_path .. 'c\n'
+ .. ' 4 2 0 ' .. mock_file_path .. 'd\n'
+ .. ' 3 3 0 ' .. mock_file_path .. 'd\n'
+ .. ' 2 2 0 ' .. mock_file_path .. 'e\n'
+ .. ' 1 2 0 ' .. mock_file_path .. 'f\n'
.. '>', redir_exec('jumps'))
end)