Patch 8.2.4947
Problem:    Text properties not adjusted when accepting spell suggestion.
Solution:   Adjust text properties when text changes. (closes #10414)
Files:      src/spell.c, src/spellsuggest.c, src/testdir/test_textprop.vim


*** ../vim-8.2.4946/src/spell.c 2022-04-15 13:53:30.056708670 +0100
--- src/spell.c 2022-05-13 12:38:53.065570453 +0100
***************
*** 2913,2918 ****
--- 2913,2921 ----
            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)
            {
*** ../vim-8.2.4946/src/spellsuggest.c  2022-05-09 20:09:19.290641428 +0100
--- src/spellsuggest.c  2022-05-13 12:39:39.265547028 +0100
***************
*** 681,686 ****
--- 681,688 ----
        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,703 ****
--- 700,708 ----
            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
*** ../vim-8.2.4946/src/testdir/test_textprop.vim       2022-05-12 
18:45:14.778530646 +0100
--- src/testdir/test_textprop.vim       2022-05-13 12:36:20.401653343 +0100
***************
*** 1889,1892 ****
--- 1889,1937 ----
    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
*** ../vim-8.2.4946/src/version.c       2022-05-12 22:02:53.287681016 +0100
--- src/version.c       2022-05-13 12:38:13.925590873 +0100
***************
*** 748,749 ****
--- 748,751 ----
  {   /* Add new patch number below this line */
+ /**/
+     4947,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
186. You overstay in the office so you can have more time surfing the net.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20220513114225.0CF011C0F60%40moolenaar.net.

Raspunde prin e-mail lui