patch 8.2.4947: text properties not adjusted when accepting spell suggestion v8.2.4947
authorLemonBoy <thatlemon@gmail.com>
Fri, 13 May 2022 11:41:50 +0000 (12:41 +0100)
committerBram Moolenaar <Bram@vim.org>
Fri, 13 May 2022 11:41:50 +0000 (12:41 +0100)
Problem:    Text properties not adjusted when accepting spell suggestion.
Solution:   Adjust text properties when text changes. (closes #10414)

src/spell.c
src/spellsuggest.c
src/testdir/test_textprop.vim
src/version.c

index 0c1890472a9a61f040d617b33c8599708ecc8792..e5c2f7d1f4e7eb4254cff3bc7c6393071785bdf6 100644 (file)
@@ -2913,6 +2913,9 @@ ex_spellrepall(exarg_T *eap UNUSED)
            STRCAT(p, line + curwin->w_cursor.col + STRLEN(repl_from));
            ml_replace(curwin->w_cursor.lnum, p, FALSE);
            changed_bytes(curwin->w_cursor.lnum, curwin->w_cursor.col);
+           if (curbuf->b_has_textprop && addlen != 0)
+               adjust_prop_columns(curwin->w_cursor.lnum,
+                                curwin->w_cursor.col, addlen, APC_SUBSTITUTE);
 
            if (curwin->w_cursor.lnum != prev_lnum)
            {
index ecb54550d675bf9319521368d6c93c9c3e7beea0..4a714388185e45bd95934757d3b0c1960d859240 100644 (file)
@@ -681,6 +681,8 @@ spell_suggest(int count)
        p = alloc(STRLEN(line) - stp->st_orglen + stp->st_wordlen + 1);
        if (p != NULL)
        {
+           int len_diff = stp->st_wordlen - stp->st_orglen;
+
            c = (int)(sug.su_badptr - line);
            mch_memmove(p, line, c);
            STRCPY(p + c, stp->st_word);
@@ -698,6 +700,9 @@ spell_suggest(int count)
            curwin->w_cursor.col = c;
 
            changed_bytes(curwin->w_cursor.lnum, c);
+           if (curbuf->b_has_textprop && len_diff != 0)
+               adjust_prop_columns(curwin->w_cursor.lnum, c, len_diff,
+                                                              APC_SUBSTITUTE);
        }
     }
     else
index fee3bdb6bb88b634c4cf85122c7fbb42f9523108..20ab85a8cc91c0caf284093cb1ccf2792aeba073 100644 (file)
@@ -1889,4 +1889,49 @@ func Test_prop_find_prev_on_same_line()
   bwipe!
 endfunc
 
+func Test_prop_spell()
+  new
+  set spell
+  call AddPropTypes()
+
+  call setline(1, ["helo world", "helo helo helo"])
+  call prop_add(1, 1, #{type: 'one', length: 4})
+  call prop_add(1, 6, #{type: 'two', length: 5})
+  call prop_add(2, 1, #{type: 'three', length: 4})
+  call prop_add(2, 6, #{type: 'three', length: 4})
+  call prop_add(2, 11, #{type: 'three', length: 4})
+
+  " The first prop over 'helo' increases its length after the word is corrected
+  " to 'Hello', the second one is shifted to the right.
+  let expected = [
+      \ {'id': 0, 'col': 1, 'type_bufnr': 0, 'end': 1, 'type': 'one',
+      \ 'length': 5, 'start': 1},
+      \ {'id': 0, 'col': 7, 'type_bufnr': 0, 'end': 1, 'type': 'two',
+      \ 'length': 5, 'start': 1}
+      \ ]
+  call feedkeys("z=1\<CR>", 'xt')
+
+  call assert_equal('Hello world', getline(1))
+  call assert_equal(expected, prop_list(1))
+
+  " Repeat the replacement done by z=
+  spellrepall
+
+  let expected = [
+      \ {'id': 0, 'col': 1, 'type_bufnr': 0, 'end': 1, 'type': 'three',
+      \ 'length': 5, 'start': 1},
+      \ {'id': 0, 'col': 7, 'type_bufnr': 0, 'end': 1, 'type': 'three',
+      \ 'length': 5, 'start': 1},
+      \ {'id': 0, 'col': 13, 'type_bufnr': 0, 'end': 1, 'type': 'three',
+      \ 'length': 5, 'start': 1}
+      \ ]
+  call assert_equal('Hello Hello Hello', getline(2))
+  call assert_equal(expected, prop_list(2))
+
+  call DeletePropTypes()
+  set spell&
+  bwipe!
+endfunc
+
+
 " vim: shiftwidth=2 sts=2 expandtab
index e63e6b13942d7b480a726e2b7cf887c7edbc26c3..196537359bcf790bd811b1b6338c890a6281fe0f 100644 (file)
@@ -746,6 +746,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4947,
 /**/
     4946,
 /**/