summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2019-05-24 20:41:55 +0200
committerBram Moolenaar <Bram@vim.org>2019-05-24 20:41:55 +0200
commitd79eef2eb1f24b53206c4e55b80a4634f548c429 (patch)
tree7e3363a5b1693bae6c3950987b1d12033511ad54
parent18a4ba29aeccb9841d5bfdd2eaaffdfae2f15ced (diff)
downloadvim-git-d79eef2eb1f24b53206c4e55b80a4634f548c429.tar.gz
patch 8.1.1387: calling prop_add() in an empty buffer doesn't workv8.1.1387
Problem: Calling prop_add() in an empty buffer doesn't work. (Dominique Pelle) Solution: Open the memline before adding a text property. (closes #4412)
-rw-r--r--src/testdir/test_textprop.vim8
-rw-r--r--src/textprop.c6
-rw-r--r--src/version.c2
3 files changed, 15 insertions, 1 deletions
diff --git a/src/testdir/test_textprop.vim b/src/testdir/test_textprop.vim
index 08b93dfc9..4d620eab8 100644
--- a/src/testdir/test_textprop.vim
+++ b/src/testdir/test_textprop.vim
@@ -752,3 +752,11 @@ func Test_textprop_screenshot_visual()
" Same, but delete four columns
call RunTestVisualBlock(4, '02')
endfunc
+
+" Adding a text property to a new buffer should not fail
+func Test_textprop_empty_buffer()
+ call prop_type_add('comment', {'highlight': 'Search'})
+ new
+ call prop_add(1, 1, {'type': 'comment'})
+ close
+endfunc
diff --git a/src/textprop.c b/src/textprop.c
index e993afce8..9011c663e 100644
--- a/src/textprop.c
+++ b/src/textprop.c
@@ -12,6 +12,7 @@
*
* TODO:
* - Adjust text property column and length when text is inserted/deleted.
+ * -> :substitute with multiple matches, issue #4427
* -> a :substitute with a multi-line match
* -> search for changed_bytes() from misc1.c
* -> search for mark_col_adjust()
@@ -238,6 +239,9 @@ f_prop_add(typval_T *argvars, typval_T *rettv UNUSED)
return;
}
+ if (buf->b_ml.ml_mfp == NULL)
+ ml_open(buf);
+
for (lnum = start_lnum; lnum <= end_lnum; ++lnum)
{
colnr_T col; // start column
@@ -327,7 +331,7 @@ get_text_props(buf_T *buf, linenr_T lnum, char_u **props, int will_change)
// Be quick when no text property types have been defined or the buffer,
// unless we are adding one.
- if (!buf->b_has_textprop && !will_change)
+ if ((!buf->b_has_textprop && !will_change) || buf->b_ml.ml_mfp == NULL)
return 0;
// Fetch the line to get the ml_line_len field updated.
diff --git a/src/version.c b/src/version.c
index 3653b9b61..ac1c67aca 100644
--- a/src/version.c
+++ b/src/version.c
@@ -768,6 +768,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1387,
+/**/
1386,
/**/
1385,