Mercurial > vim
diff src/evalfunc.c @ 16600:ff3c99bd1038 v8.1.1303
patch 8.1.1303: not possible to hide a balloon
commit https://github.com/vim/vim/commit/be0a2597ae0d9eb0b8a8a2fc9ae1784faa929844
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu May 9 13:50:16 2019 +0200
patch 8.1.1303: not possible to hide a balloon
Problem: Not possible to hide a balloon.
Solution: Hide the balloon when balloon_show() is called with an empty
string or list. Add balloon_gettext().
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 09 May 2019 14:00:07 +0200 |
parents | bcc343175103 |
children | 1e0a5f09fdf1 |
line wrap: on
line diff
--- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -63,6 +63,7 @@ static void f_atan(typval_T *argvars, ty static void f_atan2(typval_T *argvars, typval_T *rettv); #endif #ifdef FEAT_BEVAL +static void f_balloon_gettext(typval_T *argvars, typval_T *rettv); static void f_balloon_show(typval_T *argvars, typval_T *rettv); # if defined(FEAT_BEVAL_TERM) static void f_balloon_split(typval_T *argvars, typval_T *rettv); @@ -552,6 +553,7 @@ static struct fst {"atan2", 2, 2, f_atan2}, #endif #ifdef FEAT_BEVAL + {"balloon_gettext", 0, 0, f_balloon_gettext}, {"balloon_show", 1, 1, f_balloon_show}, # if defined(FEAT_BEVAL_TERM) {"balloon_split", 1, 1, f_balloon_split}, @@ -1764,6 +1766,19 @@ f_atan2(typval_T *argvars, typval_T *ret */ #ifdef FEAT_BEVAL static void +f_balloon_gettext(typval_T *argvars UNUSED, typval_T *rettv) +{ + rettv->v_type = VAR_STRING; + if (balloonEval != NULL) + { + if (balloonEval->msg == NULL) + rettv->vval.v_string = NULL; + else + rettv->vval.v_string = vim_strsave(balloonEval->msg); + } +} + + static void f_balloon_show(typval_T *argvars, typval_T *rettv UNUSED) { if (balloonEval != NULL) @@ -1773,9 +1788,21 @@ f_balloon_show(typval_T *argvars, typval && !gui.in_use # endif ) - post_balloon(balloonEval, NULL, argvars[0].vval.v_list); - else - post_balloon(balloonEval, tv_get_string_chk(&argvars[0]), NULL); + { + list_T *l = argvars[0].vval.v_list; + + // empty list removes the balloon + post_balloon(balloonEval, NULL, + l == NULL || l->lv_len == 0 ? NULL : l); + } + else + { + char_u *mesg = tv_get_string_chk(&argvars[0]); + + if (mesg != NULL) + // empty string removes the balloon + post_balloon(balloonEval, *mesg == NUL ? NULL : mesg, NULL); + } } }