Mercurial > vim
comparison src/textprop.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 | fc58fee685e2 |
children | ce04ebdf26b8 |
comparison
equal
deleted
inserted
replaced
16810:53b2302072d2 | 16811:0457d49eb2d9 |
---|---|
140 * prop_add({lnum}, {col}, {props}) | 140 * prop_add({lnum}, {col}, {props}) |
141 */ | 141 */ |
142 void | 142 void |
143 f_prop_add(typval_T *argvars, typval_T *rettv UNUSED) | 143 f_prop_add(typval_T *argvars, typval_T *rettv UNUSED) |
144 { | 144 { |
145 linenr_T start_lnum; | |
146 colnr_T start_col; | |
147 | |
148 start_lnum = tv_get_number(&argvars[0]); | |
149 start_col = tv_get_number(&argvars[1]); | |
150 if (start_col < 1) | |
151 { | |
152 semsg(_(e_invalid_col), (long)start_col); | |
153 return; | |
154 } | |
155 if (argvars[2].v_type != VAR_DICT) | |
156 { | |
157 emsg(_(e_dictreq)); | |
158 return; | |
159 } | |
160 | |
161 prop_add_common(start_lnum, start_col, argvars[2].vval.v_dict, | |
162 curbuf, &argvars[2]); | |
163 } | |
164 | |
165 /* | |
166 * Shared between prop_add() and popup_create(). | |
167 * "dict_arg" is the function argument of a dict containing "bufnr". | |
168 * it is NULL for popup_create(). | |
169 */ | |
170 void | |
171 prop_add_common( | |
172 linenr_T start_lnum, | |
173 colnr_T start_col, | |
174 dict_T *dict, | |
175 buf_T *default_buf, | |
176 typval_T *dict_arg) | |
177 { | |
145 linenr_T lnum; | 178 linenr_T lnum; |
146 linenr_T start_lnum; | |
147 linenr_T end_lnum; | 179 linenr_T end_lnum; |
148 colnr_T start_col; | |
149 colnr_T end_col; | 180 colnr_T end_col; |
150 dict_T *dict; | |
151 char_u *type_name; | 181 char_u *type_name; |
152 proptype_T *type; | 182 proptype_T *type; |
153 buf_T *buf = curbuf; | 183 buf_T *buf = default_buf; |
154 int id = 0; | 184 int id = 0; |
155 char_u *newtext; | 185 char_u *newtext; |
156 int proplen; | 186 int proplen; |
157 size_t textlen; | 187 size_t textlen; |
158 char_u *props = NULL; | 188 char_u *props = NULL; |
159 char_u *newprops; | 189 char_u *newprops; |
160 textprop_T tmp_prop; | 190 textprop_T tmp_prop; |
161 int i; | 191 int i; |
162 | 192 |
163 start_lnum = tv_get_number(&argvars[0]); | |
164 start_col = tv_get_number(&argvars[1]); | |
165 if (start_col < 1) | |
166 { | |
167 semsg(_(e_invalid_col), (long)start_col); | |
168 return; | |
169 } | |
170 if (argvars[2].v_type != VAR_DICT) | |
171 { | |
172 emsg(_(e_dictreq)); | |
173 return; | |
174 } | |
175 dict = argvars[2].vval.v_dict; | |
176 | |
177 if (dict == NULL || dict_find(dict, (char_u *)"type", -1) == NULL) | 193 if (dict == NULL || dict_find(dict, (char_u *)"type", -1) == NULL) |
178 { | 194 { |
179 emsg(_("E965: missing property type name")); | 195 emsg(_("E965: missing property type name")); |
180 return; | 196 return; |
181 } | 197 } |
219 end_col = 1; | 235 end_col = 1; |
220 | 236 |
221 if (dict_find(dict, (char_u *)"id", -1) != NULL) | 237 if (dict_find(dict, (char_u *)"id", -1) != NULL) |
222 id = dict_get_number(dict, (char_u *)"id"); | 238 id = dict_get_number(dict, (char_u *)"id"); |
223 | 239 |
224 if (get_bufnr_from_arg(&argvars[2], &buf) == FAIL) | 240 if (dict_arg != NULL && get_bufnr_from_arg(dict_arg, &buf) == FAIL) |
225 return; | 241 return; |
226 | 242 |
227 type = lookup_prop_type(type_name, buf); | 243 type = lookup_prop_type(type_name, buf); |
228 if (type == NULL) | 244 if (type == NULL) |
229 return; | 245 return; |
276 return; | 292 return; |
277 // Copy the text, including terminating NUL. | 293 // Copy the text, including terminating NUL. |
278 mch_memmove(newtext, buf->b_ml.ml_line_ptr, textlen); | 294 mch_memmove(newtext, buf->b_ml.ml_line_ptr, textlen); |
279 | 295 |
280 // Find the index where to insert the new property. | 296 // Find the index where to insert the new property. |
281 // Since the text properties are not aligned properly when stored with the | 297 // Since the text properties are not aligned properly when stored with |
282 // text, we need to copy them as bytes before using it as a struct. | 298 // the text, we need to copy them as bytes before using it as a struct. |
283 for (i = 0; i < proplen; ++i) | 299 for (i = 0; i < proplen; ++i) |
284 { | 300 { |
285 mch_memmove(&tmp_prop, props + i * sizeof(textprop_T), | 301 mch_memmove(&tmp_prop, props + i * sizeof(textprop_T), |
286 sizeof(textprop_T)); | 302 sizeof(textprop_T)); |
287 if (tmp_prop.tp_col >= col) | 303 if (tmp_prop.tp_col >= col) |
288 break; | 304 break; |
289 } | 305 } |
290 newprops = newtext + textlen; | 306 newprops = newtext + textlen; |
291 if (i > 0) | 307 if (i > 0) |
296 tmp_prop.tp_id = id; | 312 tmp_prop.tp_id = id; |
297 tmp_prop.tp_type = type->pt_id; | 313 tmp_prop.tp_type = type->pt_id; |
298 tmp_prop.tp_flags = (lnum > start_lnum ? TP_FLAG_CONT_PREV : 0) | 314 tmp_prop.tp_flags = (lnum > start_lnum ? TP_FLAG_CONT_PREV : 0) |
299 | (lnum < end_lnum ? TP_FLAG_CONT_NEXT : 0); | 315 | (lnum < end_lnum ? TP_FLAG_CONT_NEXT : 0); |
300 mch_memmove(newprops + i * sizeof(textprop_T), &tmp_prop, | 316 mch_memmove(newprops + i * sizeof(textprop_T), &tmp_prop, |
301 sizeof(textprop_T)); | 317 sizeof(textprop_T)); |
302 | 318 |
303 if (i < proplen) | 319 if (i < proplen) |
304 mch_memmove(newprops + (i + 1) * sizeof(textprop_T), | 320 mch_memmove(newprops + (i + 1) * sizeof(textprop_T), |
305 props + i * sizeof(textprop_T), | 321 props + i * sizeof(textprop_T), |
306 sizeof(textprop_T) * (proplen - i)); | 322 sizeof(textprop_T) * (proplen - i)); |