Mercurial > vim
comparison src/memline.c @ 15361:58b125df3e9b v8.1.0688
patch 8.1.0688: text properties are not restored by undo
commit https://github.com/vim/vim/commit/ccae4672fd622f2feac8322be71b6e43e68dc4fc
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Jan 4 15:09:57 2019 +0100
patch 8.1.0688: text properties are not restored by undo
Problem: Text properties are not restored by undo.
Solution: Also save text properties for undo.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 04 Jan 2019 15:15:06 +0100 |
parents | 21580db06cf3 |
children | 55ccc2d353bd |
comparison
equal
deleted
inserted
replaced
15360:4a4212c844d6 | 15361:58b125df3e9b |
---|---|
3215 { | 3215 { |
3216 colnr_T len = -1; | 3216 colnr_T len = -1; |
3217 | 3217 |
3218 if (line != NULL) | 3218 if (line != NULL) |
3219 len = (colnr_T)STRLEN(line); | 3219 len = (colnr_T)STRLEN(line); |
3220 return ml_replace_len(lnum, line, len, copy); | 3220 return ml_replace_len(lnum, line, len, FALSE, copy); |
3221 } | 3221 } |
3222 | 3222 |
3223 /* | |
3224 * Replace a line for the current buffer. Like ml_replace() with: | |
3225 * "len_arg" is the length of the text, excluding NUL. | |
3226 * If "has_props" is TRUE then "line_arg" includes the text properties and | |
3227 * "len_arg" includes the NUL of the text. | |
3228 */ | |
3223 int | 3229 int |
3224 ml_replace_len(linenr_T lnum, char_u *line_arg, colnr_T len_arg, int copy) | 3230 ml_replace_len( |
3231 linenr_T lnum, | |
3232 char_u *line_arg, | |
3233 colnr_T len_arg, | |
3234 int has_props, | |
3235 int copy) | |
3225 { | 3236 { |
3226 char_u *line = line_arg; | 3237 char_u *line = line_arg; |
3227 colnr_T len = len_arg; | 3238 colnr_T len = len_arg; |
3228 | 3239 |
3229 if (line == NULL) /* just checking... */ | 3240 if (line == NULL) /* just checking... */ |
3231 | 3242 |
3232 /* When starting up, we might still need to create the memfile */ | 3243 /* When starting up, we might still need to create the memfile */ |
3233 if (curbuf->b_ml.ml_mfp == NULL && open_buffer(FALSE, NULL, 0) == FAIL) | 3244 if (curbuf->b_ml.ml_mfp == NULL && open_buffer(FALSE, NULL, 0) == FAIL) |
3234 return FAIL; | 3245 return FAIL; |
3235 | 3246 |
3236 if (copy && (line = vim_strnsave(line, len)) == NULL) /* allocate memory */ | 3247 if (!has_props) |
3237 return FAIL; | 3248 ++len; // include the NUL after the text |
3249 if (copy) | |
3250 { | |
3251 // copy the line to allocated memory | |
3252 #ifdef FEAT_TEXT_PROP | |
3253 if (has_props) | |
3254 line = vim_memsave(line, len); | |
3255 else | |
3256 #endif | |
3257 line = vim_strnsave(line, len - 1); | |
3258 if (line == NULL) | |
3259 return FAIL; | |
3260 } | |
3261 | |
3238 #ifdef FEAT_NETBEANS_INTG | 3262 #ifdef FEAT_NETBEANS_INTG |
3239 if (netbeans_active()) | 3263 if (netbeans_active()) |
3240 { | 3264 { |
3241 netbeans_removed(curbuf, lnum, 0, (long)STRLEN(ml_get(lnum))); | 3265 netbeans_removed(curbuf, lnum, 0, (long)STRLEN(ml_get(lnum))); |
3242 netbeans_inserted(curbuf, lnum, 0, line, (int)STRLEN(line)); | 3266 netbeans_inserted(curbuf, lnum, 0, line, (int)STRLEN(line)); |
3247 // another line is buffered, flush it | 3271 // another line is buffered, flush it |
3248 ml_flush_line(curbuf); | 3272 ml_flush_line(curbuf); |
3249 curbuf->b_ml.ml_flags &= ~ML_LINE_DIRTY; | 3273 curbuf->b_ml.ml_flags &= ~ML_LINE_DIRTY; |
3250 | 3274 |
3251 #ifdef FEAT_TEXT_PROP | 3275 #ifdef FEAT_TEXT_PROP |
3252 if (curbuf->b_has_textprop) | 3276 if (curbuf->b_has_textprop && !has_props) |
3253 // Need to fetch the old line to copy over any text properties. | 3277 // Need to fetch the old line to copy over any text properties. |
3254 ml_get_buf(curbuf, lnum, TRUE); | 3278 ml_get_buf(curbuf, lnum, TRUE); |
3255 #endif | 3279 #endif |
3256 } | 3280 } |
3257 | 3281 |
3258 #ifdef FEAT_TEXT_PROP | 3282 #ifdef FEAT_TEXT_PROP |
3259 if (curbuf->b_has_textprop) | 3283 if (curbuf->b_has_textprop && !has_props) |
3260 { | 3284 { |
3261 size_t oldtextlen = STRLEN(curbuf->b_ml.ml_line_ptr) + 1; | 3285 size_t oldtextlen = STRLEN(curbuf->b_ml.ml_line_ptr) + 1; |
3262 | 3286 |
3263 if (oldtextlen < (size_t)curbuf->b_ml.ml_line_len) | 3287 if (oldtextlen < (size_t)curbuf->b_ml.ml_line_len) |
3264 { | 3288 { |
3265 char_u *newline; | 3289 char_u *newline; |
3266 size_t textproplen = curbuf->b_ml.ml_line_len - oldtextlen; | 3290 size_t textproplen = curbuf->b_ml.ml_line_len - oldtextlen; |
3267 | 3291 |
3268 // Need to copy over text properties, stored after the text. | 3292 // Need to copy over text properties, stored after the text. |
3269 newline = alloc(len + 1 + (int)textproplen); | 3293 newline = alloc(len + (int)textproplen); |
3270 if (newline != NULL) | 3294 if (newline != NULL) |
3271 { | 3295 { |
3272 mch_memmove(newline, line, len + 1); | 3296 mch_memmove(newline, line, len); |
3273 mch_memmove(newline + len + 1, curbuf->b_ml.ml_line_ptr + oldtextlen, textproplen); | 3297 mch_memmove(newline + len, curbuf->b_ml.ml_line_ptr + oldtextlen, textproplen); |
3274 vim_free(line); | 3298 vim_free(line); |
3275 line = newline; | 3299 line = newline; |
3276 len += (colnr_T)textproplen; | 3300 len += (colnr_T)textproplen; |
3277 } | 3301 } |
3278 } | 3302 } |
3279 } | 3303 } |
3280 #endif | 3304 #endif |
3281 | 3305 |
3282 if (curbuf->b_ml.ml_flags & ML_LINE_DIRTY) /* same line allocated */ | 3306 if (curbuf->b_ml.ml_flags & ML_LINE_DIRTY) // same line allocated |
3283 vim_free(curbuf->b_ml.ml_line_ptr); /* free it */ | 3307 vim_free(curbuf->b_ml.ml_line_ptr); // free it |
3284 | 3308 |
3285 curbuf->b_ml.ml_line_ptr = line; | 3309 curbuf->b_ml.ml_line_ptr = line; |
3286 curbuf->b_ml.ml_line_len = len + 1; | 3310 curbuf->b_ml.ml_line_len = len; |
3287 curbuf->b_ml.ml_line_lnum = lnum; | 3311 curbuf->b_ml.ml_line_lnum = lnum; |
3288 curbuf->b_ml.ml_flags = (curbuf->b_ml.ml_flags | ML_LINE_DIRTY) & ~ML_EMPTY; | 3312 curbuf->b_ml.ml_flags = (curbuf->b_ml.ml_flags | ML_LINE_DIRTY) & ~ML_EMPTY; |
3289 | 3313 |
3290 return OK; | 3314 return OK; |
3291 } | 3315 } |