]> granicus.if.org Git - vim/commitdiff
patch 8.2.1478: Vim9: cannot use "true" for some popup options v8.2.1478
authorBram Moolenaar <Bram@vim.org>
Tue, 18 Aug 2020 11:04:15 +0000 (13:04 +0200)
committerBram Moolenaar <Bram@vim.org>
Tue, 18 Aug 2020 11:04:15 +0000 (13:04 +0200)
Problem:    Vim9: cannot use "true" for some popup options.
Solution:   Add dict_get_bool(). (closes #6725)

src/dict.c
src/popupwin.c
src/proto/dict.pro
src/version.c

index b3517309aeebfb8ac15016c1cca32b930d763027..01a2edaa28ac77a47fcb9e0687ba09506dc89d95 100644 (file)
@@ -702,6 +702,21 @@ dict_get_number_check(dict_T *d, char_u *key)
     return tv_get_number(&di->di_tv);
 }
 
+/*
+ * Get a bool item (number or true/false) from a dictionary.
+ * Returns "def" if the entry doesn't exist.
+ */
+    varnumber_T
+dict_get_bool(dict_T *d, char_u *key, int def)
+{
+    dictitem_T *di;
+
+    di = dict_find(d, key, -1);
+    if (di == NULL)
+       return def;
+    return tv_get_bool(&di->di_tv);
+}
+
 /*
  * Return an allocated string with the string representation of a Dictionary.
  * May return NULL.
index ff9e810044555c4e906e8d6320e361c6694151f4..4b85fec1932c9807edea619027c59d9c56c57598 100644 (file)
@@ -438,9 +438,10 @@ apply_move_options(win_T *wp, dict_T *d)
     if (nr != MAXCOL)
        wp->w_wantcol = nr;
 
-    di = dict_find(d, (char_u *)"fixed", -1);
-    if (di != NULL)
-       wp->w_popup_fixed = dict_get_number(d, (char_u *)"fixed") != 0;
+
+    nr = dict_get_bool(d, (char_u *)"fixed", -1);
+    if (nr != -1)
+       wp->w_popup_fixed = nr != 0;
 
     {
        poppos_T ppt = get_pos_entry(d, TRUE);
@@ -674,37 +675,31 @@ apply_general_options(win_T *wp, dict_T *dict)
        wp->w_popup_title = vim_strsave(str);
     }
 
-    di = dict_find(dict, (char_u *)"wrap", -1);
-    if (di != NULL)
-    {
-       nr = dict_get_number(dict, (char_u *)"wrap");
+    nr = dict_get_bool(dict, (char_u *)"wrap", -1);
+    if (nr != -1)
        wp->w_p_wrap = nr != 0;
-    }
 
-    di = dict_find(dict, (char_u *)"drag", -1);
-    if (di != NULL)
+    nr = dict_get_bool(dict, (char_u *)"drag", -1);
+    if (nr != -1)
     {
-       nr = dict_get_number(dict, (char_u *)"drag");
        if (nr)
            wp->w_popup_flags |= POPF_DRAG;
        else
            wp->w_popup_flags &= ~POPF_DRAG;
     }
 
-    di = dict_find(dict, (char_u *)"posinvert", -1);
-    if (di != NULL)
+    nr = dict_get_bool(dict, (char_u *)"posinvert", -1);
+    if (nr != -1)
     {
-       nr = dict_get_number(dict, (char_u *)"posinvert");
        if (nr)
            wp->w_popup_flags |= POPF_POSINVERT;
        else
            wp->w_popup_flags &= ~POPF_POSINVERT;
     }
 
-    di = dict_find(dict, (char_u *)"resize", -1);
-    if (di != NULL)
+    nr = dict_get_bool(dict, (char_u *)"resize", -1);
+    if (nr != -1)
     {
-       nr = dict_get_number(dict, (char_u *)"resize");
        if (nr)
            wp->w_popup_flags |= POPF_RESIZE;
        else
@@ -902,10 +897,9 @@ apply_general_options(win_T *wp, dict_T *dict)
            set_callback(&wp->w_filter_cb, &callback);
        }
     }
-    di = dict_find(dict, (char_u *)"mapping", -1);
-    if (di != NULL)
+    nr = dict_get_bool(dict, (char_u *)"mapping", -1);
+    if (nr != -1)
     {
-       nr = dict_get_number(dict, (char_u *)"mapping");
        if (nr)
            wp->w_popup_flags |= POPF_MAPPING;
        else
@@ -950,7 +944,7 @@ apply_options(win_T *wp, dict_T *dict)
 
     apply_general_options(wp, dict);
 
-    nr = dict_get_number(dict, (char_u *)"hidden");
+    nr = dict_get_bool(dict, (char_u *)"hidden", FALSE);
     if (nr > 0)
        wp->w_popup_flags |= POPF_HIDDEN;
 
index 093139f4299c119af8849701f8bdfc2e60e82f2c..3b6638440dd87b3dcd5669a246fc209043ecf2f3 100644 (file)
@@ -31,6 +31,7 @@ char_u *dict_get_string(dict_T *d, char_u *key, int save);
 varnumber_T dict_get_number(dict_T *d, char_u *key);
 varnumber_T dict_get_number_def(dict_T *d, char_u *key, int def);
 varnumber_T dict_get_number_check(dict_T *d, char_u *key);
+varnumber_T dict_get_bool(dict_T *d, char_u *key, int def);
 char_u *dict2string(typval_T *tv, int copyID, int restore_copyID);
 int eval_dict(char_u **arg, typval_T *rettv, evalarg_T *evalarg, int literal);
 void dict_extend(dict_T *d1, dict_T *d2, char_u *action);
index e332c011eddbab1802c990d2771cd0e4dba1e1b7..b17bcd2f3fd626c6a9def4fa2c863e7ac6bac27e 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1478,
 /**/
     1477,
 /**/