aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarco Hinz <mh.codebro+github@gmail.com>2019-03-31 15:13:38 +0200
committerGitHub <noreply@github.com>2019-03-31 15:13:38 +0200
commit4c4a57015687df67c9bf48b721ab81e295f39118 (patch)
treecd4f677f17ce19e65d9cc2dfb7fe5cf276076e48
parent11f03ee3f3da623440607220b8167a3b797d9daa (diff)
parent33d4c381315412b52e3e2867d37ac0851e3d0faf (diff)
downloadrneovim-4c4a57015687df67c9bf48b721ab81e295f39118.tar.gz
rneovim-4c4a57015687df67c9bf48b721ab81e295f39118.tar.bz2
rneovim-4c4a57015687df67c9bf48b721ab81e295f39118.zip
Merge #9807 from mhinz/window-local-last-cursormoved
-rw-r--r--src/nvim/buffer_defs.h1
-rw-r--r--src/nvim/edit.c4
-rw-r--r--src/nvim/globals.h2
-rw-r--r--src/nvim/misc1.c2
-rw-r--r--src/nvim/normal.c4
-rw-r--r--src/nvim/window.c9
-rw-r--r--test/functional/autocmd/cursormoved_spec.lua34
7 files changed, 46 insertions, 10 deletions
diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h
index 1b0af8aa49..2e6f24d9c4 100644
--- a/src/nvim/buffer_defs.h
+++ b/src/nvim/buffer_defs.h
@@ -1035,6 +1035,7 @@ struct window_S {
// current virtual column
linenr_T w_last_cursorline; ///< where last 'cursorline' was drawn
+ pos_T w_last_cursormoved; ///< for CursorMoved event
// the next seven are used to update the visual part
char w_old_visual_mode; ///< last known VIsual_mode
diff --git a/src/nvim/edit.c b/src/nvim/edit.c
index 7b31fa0c76..e6d9dcf092 100644
--- a/src/nvim/edit.c
+++ b/src/nvim/edit.c
@@ -1398,7 +1398,7 @@ ins_redraw (
// Trigger CursorMoved if the cursor moved. Not when the popup menu is
// visible, the command might delete it.
if (ready && (has_event(EVENT_CURSORMOVEDI) || curwin->w_p_cole > 0)
- && !equalpos(last_cursormoved, curwin->w_cursor)
+ && !equalpos(curwin->w_last_cursormoved, curwin->w_cursor)
&& !pum_visible()) {
// Need to update the screen first, to make sure syntax
// highlighting is correct after making a change (e.g., inserting
@@ -1414,7 +1414,7 @@ ins_redraw (
ins_apply_autocmds(EVENT_CURSORMOVEDI);
}
conceal_cursor_moved = true;
- last_cursormoved = curwin->w_cursor;
+ curwin->w_last_cursormoved = curwin->w_cursor;
}
// Trigger TextChangedI if changedtick differs.
diff --git a/src/nvim/globals.h b/src/nvim/globals.h
index 004b3252da..a4d31c0c08 100644
--- a/src/nvim/globals.h
+++ b/src/nvim/globals.h
@@ -788,8 +788,6 @@ EXTERN char_u *autocmd_fname INIT(= NULL); // fname for <afile> on cmdline
EXTERN int autocmd_bufnr INIT(= 0); // fnum for <abuf> on cmdline
EXTERN char_u *autocmd_match INIT(= NULL); // name for <amatch> on cmdline
EXTERN int did_cursorhold INIT(= false); // set when CursorHold t'gerd
-// for CursorMoved event
-EXTERN pos_T last_cursormoved INIT(= { 0, 0, 0 });
EXTERN int postponed_split INIT(= 0); /* for CTRL-W CTRL-] command */
EXTERN int postponed_split_flags INIT(= 0); /* args for win_split() */
diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c
index d06fa8f762..e5c22e5be3 100644
--- a/src/nvim/misc1.c
+++ b/src/nvim/misc1.c
@@ -2175,7 +2175,7 @@ static void changed_common(linenr_T lnum, colnr_T col, linenr_T lnume, long xtra
/* when the cursor line is changed always trigger CursorMoved */
if (lnum <= curwin->w_cursor.lnum
&& lnume + (xtra < 0 ? -xtra : xtra) > curwin->w_cursor.lnum)
- last_cursormoved.lnum = 0;
+ curwin->w_last_cursormoved.lnum = 0;
}
/*
diff --git a/src/nvim/normal.c b/src/nvim/normal.c
index f12abd362f..8da64bf01b 100644
--- a/src/nvim/normal.c
+++ b/src/nvim/normal.c
@@ -1187,12 +1187,12 @@ static void normal_check_cursor_moved(NormalState *s)
{
// Trigger CursorMoved if the cursor moved.
if (!finish_op && (has_event(EVENT_CURSORMOVED) || curwin->w_p_cole > 0)
- && !equalpos(last_cursormoved, curwin->w_cursor)) {
+ && !equalpos(curwin->w_last_cursormoved, curwin->w_cursor)) {
if (has_event(EVENT_CURSORMOVED)) {
apply_autocmds(EVENT_CURSORMOVED, NULL, NULL, false, curbuf);
}
- last_cursormoved = curwin->w_cursor;
+ curwin->w_last_cursormoved = curwin->w_cursor;
}
}
diff --git a/src/nvim/window.c b/src/nvim/window.c
index 2bc1ed945a..ad38a34dac 100644
--- a/src/nvim/window.c
+++ b/src/nvim/window.c
@@ -4256,9 +4256,12 @@ static void win_enter_ext(win_T *wp, bool undo_sync, int curwin_invalid,
apply_autocmds(EVENT_WINNEW, NULL, NULL, false, curbuf);
}
if (trigger_enter_autocmds) {
- apply_autocmds(EVENT_WINENTER, NULL, NULL, FALSE, curbuf);
- if (other_buffer)
- apply_autocmds(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf);
+ apply_autocmds(EVENT_WINENTER, NULL, NULL, false, curbuf);
+ if (other_buffer) {
+ apply_autocmds(EVENT_BUFENTER, NULL, NULL, false, curbuf);
+ }
+ apply_autocmds(EVENT_CURSORMOVED, NULL, NULL, false, curbuf);
+ curwin->w_last_cursormoved = curwin->w_cursor;
}
maketitle();
diff --git a/test/functional/autocmd/cursormoved_spec.lua b/test/functional/autocmd/cursormoved_spec.lua
new file mode 100644
index 0000000000..d0f46e689b
--- /dev/null
+++ b/test/functional/autocmd/cursormoved_spec.lua
@@ -0,0 +1,34 @@
+local helpers = require('test.functional.helpers')(after_each)
+
+local clear = helpers.clear
+local eq = helpers.eq
+local eval = helpers.eval
+local funcs = helpers.funcs
+local source = helpers.source
+
+describe('CursorMoved', function()
+ before_each(clear)
+
+ it('is triggered by changing windows', function()
+ source([[
+ let g:cursormoved = 0
+ vsplit
+ autocmd CursorMoved * let g:cursormoved += 1
+ wincmd w
+ wincmd w
+ ]])
+ eq(2, eval('g:cursormoved'))
+ end)
+
+ it("is not triggered by functions that don't change the window", function()
+ source([[
+ let g:cursormoved = 0
+ let g:buf = bufnr('%')
+ vsplit foo
+ autocmd CursorMoved * let g:cursormoved += 1
+ call nvim_buf_set_lines(g:buf, 0, -1, v:true, ['aaa'])
+ ]])
+ eq({'aaa'}, funcs.nvim_buf_get_lines(eval('g:buf'), 0, -1, true))
+ eq(0, eval('g:cursormoved'))
+ end)
+end)