comparison src/popupwin.c @ 16811:0457d49eb2d9 v8.1.1407

patch 8.1.1407: popup_create() does not support text properties commit https://github.com/vim/vim/commit/7a8d0278bd6bd57e04f61183cb8e2969cf148e3f Author: Bram Moolenaar <Bram@vim.org> Date: Sun May 26 23:32:06 2019 +0200 patch 8.1.1407: popup_create() does not support text properties Problem: Popup_create() does not support text properties. Solution: Support the third form of the text argument.
author Bram Moolenaar <Bram@vim.org>
date Sun, 26 May 2019 23:45:05 +0200
parents 5ff14f96f1c9
children 4cfad94161f4
comparison
equal deleted inserted replaced
16810:53b2302072d2 16811:0457d49eb2d9
55 55
56 str = dict_get_string(dict, (char_u *)"highlight", TRUE); 56 str = dict_get_string(dict, (char_u *)"highlight", TRUE);
57 if (str != NULL) 57 if (str != NULL)
58 set_string_option_direct_in_win(wp, (char_u *)"wincolor", -1, 58 set_string_option_direct_in_win(wp, (char_u *)"wincolor", -1,
59 str, OPT_FREE|OPT_LOCAL, 0); 59 str, OPT_FREE|OPT_LOCAL, 0);
60 }
61
62 /*
63 * Add lines to the popup from a list of strings.
64 */
65 static void
66 add_popup_strings(buf_T *buf, list_T *l)
67 {
68 listitem_T *li;
69 linenr_T lnum = 0;
70 char_u *p;
71
72 for (li = l->lv_first; li != NULL; li = li->li_next)
73 if (li->li_tv.v_type == VAR_STRING)
74 {
75 p = li->li_tv.vval.v_string;
76 ml_append_buf(buf, lnum++,
77 p == NULL ? (char_u *)"" : p, (colnr_T)0, TRUE);
78 }
79 }
80
81 /*
82 * Add lines to the popup from a list of dictionaries.
83 */
84 static void
85 add_popup_dicts(buf_T *buf, list_T *l)
86 {
87 listitem_T *li;
88 listitem_T *pli;
89 linenr_T lnum = 0;
90 char_u *p;
91 dict_T *dict;
92
93 // first add the text lines
94 for (li = l->lv_first; li != NULL; li = li->li_next)
95 {
96 if (li->li_tv.v_type != VAR_DICT)
97 {
98 emsg(_(e_dictreq));
99 return;
100 }
101 dict = li->li_tv.vval.v_dict;
102 p = dict == NULL ? NULL
103 : dict_get_string(dict, (char_u *)"text", FALSE);
104 ml_append_buf(buf, lnum++,
105 p == NULL ? (char_u *)"" : p, (colnr_T)0, TRUE);
106 }
107
108 // add the text properties
109 lnum = 1;
110 for (li = l->lv_first; li != NULL; li = li->li_next, ++lnum)
111 {
112 dictitem_T *di;
113 list_T *plist;
114
115 dict = li->li_tv.vval.v_dict;
116 di = dict_find(dict, (char_u *)"props", -1);
117 if (di != NULL)
118 {
119 if (di->di_tv.v_type != VAR_LIST)
120 {
121 emsg(_(e_listreq));
122 return;
123 }
124 plist = di->di_tv.vval.v_list;
125 if (plist != NULL)
126 {
127 for (pli = plist->lv_first; pli != NULL; pli = pli->li_next)
128 {
129 if (pli->li_tv.v_type != VAR_DICT)
130 {
131 emsg(_(e_dictreq));
132 return;
133 }
134 dict = pli->li_tv.vval.v_dict;
135 if (dict != NULL)
136 {
137 int col = dict_get_number(dict, (char_u *)"col");
138
139 prop_add_common( lnum, col, dict, buf, NULL);
140 }
141 }
142 }
143 }
144 }
60 } 145 }
61 146
62 /* 147 /*
63 * popup_create({text}, {options}) 148 * popup_create({text}, {options})
64 */ 149 */
126 // TODO: find tab page "nr" 211 // TODO: find tab page "nr"
127 emsg("Not implemented yet"); 212 emsg("Not implemented yet");
128 213
129 // Add text to the buffer. 214 // Add text to the buffer.
130 if (argvars[0].v_type == VAR_STRING) 215 if (argvars[0].v_type == VAR_STRING)
216 {
131 // just a string 217 // just a string
132 ml_append_buf(buf, 0, argvars[0].vval.v_string, (colnr_T)0, TRUE); 218 ml_append_buf(buf, 0, argvars[0].vval.v_string, (colnr_T)0, TRUE);
133 else if (argvars[0].vval.v_list->lv_first->li_tv.v_type == VAR_STRING)
134 {
135 listitem_T *li;
136 linenr_T lnum = 0;
137 char_u *p;
138
139 // list of strings
140 for (li = argvars[0].vval.v_list->lv_first; li != NULL;
141 li = li->li_next)
142 if (li->li_tv.v_type == VAR_STRING)
143 {
144 p = li->li_tv.vval.v_string;
145 ml_append_buf(buf, lnum++,
146 p == NULL ? (char_u *)"" : p, (colnr_T)0, TRUE);
147 }
148 } 219 }
149 else 220 else
150 // TODO: handle a list of dictionaries 221 {
151 emsg("Not implemented yet"); 222 list_T *l = argvars[0].vval.v_list;
223
224 if (l->lv_first->li_tv.v_type == VAR_STRING)
225 // list of strings
226 add_popup_strings(buf, l);
227 else
228 // list of dictionaries
229 add_popup_dicts(buf, l);
230 }
152 231
153 // Delete the line of the empty buffer. 232 // Delete the line of the empty buffer.
154 curbuf = buf; 233 curbuf = buf;
155 ml_delete(buf->b_ml.ml_line_count, FALSE); 234 ml_delete(buf->b_ml.ml_line_count, FALSE);
156 curbuf = curwin->w_buffer; 235 curbuf = curwin->w_buffer;