aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/misc1.c7
-rw-r--r--src/nvim/popupmnu.c8
-rw-r--r--src/nvim/testdir/test_popup.vim37
3 files changed, 49 insertions, 3 deletions
diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c
index 8bd59b5886..b0232b6516 100644
--- a/src/nvim/misc1.c
+++ b/src/nvim/misc1.c
@@ -1469,7 +1469,7 @@ void ins_char_bytes(char_u *buf, size_t charlen)
}
}
- char_u *newp = (char_u *) xmalloc((size_t)(linelen + newlen - oldlen));
+ char_u *newp = xmalloc((size_t)(linelen + newlen - oldlen));
// Copy bytes before the cursor.
if (col > 0) {
@@ -1478,7 +1478,10 @@ void ins_char_bytes(char_u *buf, size_t charlen)
// Copy bytes after the changed character(s).
char_u *p = newp + col;
- memmove(p + newlen, oldp + col + oldlen, (size_t)(linelen - col - oldlen));
+ if (linelen > col + oldlen) {
+ memmove(p + newlen, oldp + col + oldlen,
+ (size_t)(linelen - col - oldlen));
+ }
// Insert or overwrite the new character.
memmove(p, buf, charlen);
diff --git a/src/nvim/popupmnu.c b/src/nvim/popupmnu.c
index bf79e4b84f..348daf028a 100644
--- a/src/nvim/popupmnu.c
+++ b/src/nvim/popupmnu.c
@@ -567,6 +567,7 @@ static int pum_set_selected(int n, int repeat)
&& (repeat <= 1)
&& (vim_strchr(p_cot, 'p') != NULL)) {
win_T *curwin_save = curwin;
+ tabpage_T *curtab_save = curtab;
int res = OK;
// Open a preview window. 3 lines by default. Prefer
@@ -647,7 +648,12 @@ static int pum_set_selected(int n, int repeat)
curwin->w_cursor.lnum = 1;
curwin->w_cursor.col = 0;
- if ((curwin != curwin_save) && win_valid(curwin_save)) {
+ if ((curwin != curwin_save && win_valid(curwin_save))
+ || (curtab != curtab_save && valid_tabpage(curtab_save))) {
+ if (curtab != curtab_save && valid_tabpage(curtab_save)) {
+ goto_tabpage_tp(curtab_save, false, false);
+ }
+
// When the first completion is done and the preview
// window is not resized, skip the preview window's
// status line redrawing.
diff --git a/src/nvim/testdir/test_popup.vim b/src/nvim/testdir/test_popup.vim
index e1ba142d1c..7f818dd40d 100644
--- a/src/nvim/testdir/test_popup.vim
+++ b/src/nvim/testdir/test_popup.vim
@@ -570,4 +570,41 @@ func Test_completion_clear_candidate_list()
endfunc
+func Test_popup_and_preview_autocommand()
+ " This used to crash Vim
+ if !has('python')
+ return
+ endif
+ let h = winheight(0)
+ if h < 15
+ return
+ endif
+ new
+ augroup MyBufAdd
+ au!
+ au BufAdd * nested tab sball
+ augroup END
+ set omnifunc=pythoncomplete#Complete
+ call setline(1, 'import os')
+ " make the line long
+ call setline(2, ' os.')
+ $
+ call feedkeys("A\<C-X>\<C-O>\<C-N>\<C-N>\<C-N>\<enter>\<esc>", 'tx')
+ call assert_equal(["import os", " os.EX_IOERR", ''], getline(1,'$'))
+ call assert_equal(1, winnr('$'))
+ " previewwindow option is not set
+ call assert_equal(0, &previewwindow)
+ norm! gt
+ call assert_equal(0, &previewwindow)
+ norm! gT
+ call assert_equal(12, tabpagenr('$'))
+ tabonly
+ pclose
+ augroup MyBufAdd
+ au!
+ augroup END
+ augroup! MyBufAdd
+ bw!
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab