Merge pull request #18716 from zeertzjq/vim-8.2.5007

vim-patch:8.2.{3484,5007,5123}: spell suggestion fixes
This commit is contained in:
zeertzjq 2022-06-27 06:45:00 +08:00 committed by GitHub
commit a0a815ec57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 58 additions and 8 deletions

View File

@ -2596,6 +2596,8 @@ ambw_end:
// only encoding=utf-8 allowed // only encoding=utf-8 allowed
if (STRCMP(p_enc, "utf-8") != 0) { if (STRCMP(p_enc, "utf-8") != 0) {
errmsg = e_unsupportedoption; errmsg = e_unsupportedoption;
} else {
spell_reload();
} }
} }
} }

View File

@ -3663,6 +3663,12 @@ static void suggest_try_change(suginfo_T *su)
p = su->su_badptr + su->su_badlen; p = su->su_badptr + su->su_badlen;
(void)spell_casefold(curwin, p, (int)STRLEN(p), fword + n, MAXWLEN - n); (void)spell_casefold(curwin, p, (int)STRLEN(p), fword + n, MAXWLEN - n);
// Make sure the resulting text is not longer than the original text.
n = (int)STRLEN(su->su_badptr);
if (n < MAXWLEN) {
fword[n] = NUL;
}
for (int lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) { for (int lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) {
lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi); lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi);
@ -4375,7 +4381,9 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
#endif #endif
++depth; ++depth;
sp = &stack[depth]; sp = &stack[depth];
++sp->ts_fidx; if (fword[sp->ts_fidx] != NUL) {
sp->ts_fidx++;
}
tword[sp->ts_twordlen++] = c; tword[sp->ts_twordlen++] = c;
sp->ts_arridx = idxs[arridx]; sp->ts_arridx = idxs[arridx];
if (newscore == SCORE_SUBST) { if (newscore == SCORE_SUBST) {
@ -4391,7 +4399,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
sp->ts_fcharstart = sp->ts_fidx - 1; sp->ts_fcharstart = sp->ts_fidx - 1;
sp->ts_isdiff = (newscore != 0) sp->ts_isdiff = (newscore != 0)
? DIFF_YES : DIFF_NONE; ? DIFF_YES : DIFF_NONE;
} else if (sp->ts_isdiff == DIFF_INSERT) { } else if (sp->ts_isdiff == DIFF_INSERT && sp->ts_fidx > 0) {
// When inserting trail bytes don't advance in the // When inserting trail bytes don't advance in the
// bad word. // bad word.
sp->ts_fidx--; sp->ts_fidx--;

View File

@ -72,6 +72,16 @@ func Test_z_equal_on_invalid_utf8_word()
bwipe! bwipe!
endfunc endfunc
func Test_z_equal_on_single_character()
" this was decrementing the index below zero
new
norm a0\Ê
norm zW
norm z=
bwipe!
endfunc
" Test spellbadword() with argument " Test spellbadword() with argument
func Test_spellbadword() func Test_spellbadword()
set spell set spell

View File

@ -576,7 +576,6 @@ endfunc
"Compound words "Compound words
func Test_spell_compound() func Test_spell_compound()
throw 'skipped: TODO: '
call LoadAffAndDic(g:test_data_aff3, g:test_data_dic3) call LoadAffAndDic(g:test_data_aff3, g:test_data_dic3)
call RunGoodBad("foo m\u00EF foobar foofoobar barfoo barbarfoo", call RunGoodBad("foo m\u00EF foobar foofoobar barfoo barbarfoo",
\ "bad: bar la foom\u00EF barm\u00EF m\u00EFfoo m\u00EFbar m\u00EFm\u00EF lala m\u00EFla lam\u00EF foola labar", \ "bad: bar la foom\u00EF barm\u00EF m\u00EFfoo m\u00EFbar m\u00EFm\u00EF lala m\u00EFla lam\u00EF foola labar",
@ -624,14 +623,14 @@ endfunc
" Test affix flags with two characters " Test affix flags with two characters
func Test_spell_affix() func Test_spell_affix()
throw 'skipped: TODO: ' CheckNotMSWindows " FIXME: Why does this fail with MSVC?
call LoadAffAndDic(g:test_data_aff5, g:test_data_dic5) call LoadAffAndDic(g:test_data_aff5, g:test_data_dic5)
call RunGoodBad("fooa1 fooa\u00E9 bar prebar barbork prebarbork startprebar start end startend startmiddleend nouend", call RunGoodBad("fooa1 fooa\u00E9 bar prebar barbork prebarbork startprebar start end startend startmiddleend nouend",
\ "bad: foo fooa2 prabar probarbirk middle startmiddle middleend endstart startprobar startnouend", \ "bad: foo fooa2 prabar probarbirk middle startmiddle middleend endstart startprobar startnouend",
\ ["bar", "barbork", "end", "fooa1", "fooa\u00E9", "nouend", "prebar", "prebarbork", "start"], \ ["bar", "barbork", "end", "fooa1", "fooa\u00E9", "nouend", "prebar", "prebarbork", "start"],
\ [ \ [
\ ["bad", ["bar", "end", "fooa1"]], \ ["bad", ["bar", "end", "fooa1"]],
\ ["foo", ["fooa1", "fooa\u00E9", "bar"]], \ ["foo", ["fooa1", "bar", "end"]],
\ ["fooa2", ["fooa1", "fooa\u00E9", "bar"]], \ ["fooa2", ["fooa1", "fooa\u00E9", "bar"]],
\ ["prabar", ["prebar", "bar", "bar bar"]], \ ["prabar", ["prebar", "bar", "bar bar"]],
\ ["probarbirk", ["prebarbork"]], \ ["probarbirk", ["prebarbork"]],
@ -649,7 +648,7 @@ func Test_spell_affix()
\ ["bar", "barbork", "end", "lead", "meea1", "meea\u00E9", "prebar", "prebarbork"], \ ["bar", "barbork", "end", "lead", "meea1", "meea\u00E9", "prebar", "prebarbork"],
\ [ \ [
\ ["bad", ["bar", "end", "lead"]], \ ["bad", ["bar", "end", "lead"]],
\ ["mee", ["meea1", "meea\u00E9", "bar"]], \ ["mee", ["meea1", "bar", "end"]],
\ ["meea2", ["meea1", "meea\u00E9", "lead"]], \ ["meea2", ["meea1", "meea\u00E9", "lead"]],
\ ["prabar", ["prebar", "bar", "leadbar"]], \ ["prabar", ["prebar", "bar", "leadbar"]],
\ ["probarbirk", ["prebarbork"]], \ ["probarbirk", ["prebarbork"]],
@ -666,7 +665,7 @@ func Test_spell_affix()
\ ["bar", "barmeat", "lead", "meea1", "meea\u00E9", "meezero", "prebar", "prebarmeat", "tail"], \ ["bar", "barmeat", "lead", "meea1", "meea\u00E9", "meezero", "prebar", "prebarmeat", "tail"],
\ [ \ [
\ ["bad", ["bar", "lead", "tail"]], \ ["bad", ["bar", "lead", "tail"]],
\ ["mee", ["meea1", "meea\u00E9", "bar"]], \ ["mee", ["meea1", "bar", "lead"]],
\ ["meea2", ["meea1", "meea\u00E9", "lead"]], \ ["meea2", ["meea1", "meea\u00E9", "lead"]],
\ ["prabar", ["prebar", "bar", "leadbar"]], \ ["prabar", ["prebar", "bar", "leadbar"]],
\ ["probarmaat", ["prebarmeat"]], \ ["probarmaat", ["prebarmeat"]],
@ -700,7 +699,6 @@ endfunc
" Affix flags " Affix flags
func Test_spell_affix_flags() func Test_spell_affix_flags()
throw 'skipped: TODO: '
call LoadAffAndDic(g:test_data_aff10, g:test_data_dic10) call LoadAffAndDic(g:test_data_aff10, g:test_data_dic10)
call RunGoodBad("drink drinkable drinkables drinktable drinkabletable", call RunGoodBad("drink drinkable drinkables drinktable drinkabletable",
\ "bad: drinks drinkstable drinkablestable", \ "bad: drinks drinkstable drinkablestable",
@ -761,11 +759,30 @@ func Test_spell_sal_and_addition()
set spl=Xtest_ca.utf-8.spl set spl=Xtest_ca.utf-8.spl
call assert_equal("elequint", FirstSpellWord()) call assert_equal("elequint", FirstSpellWord())
call assert_equal("elekwint", SecondSpellWord()) call assert_equal("elekwint", SecondSpellWord())
set spellfile=
set spl&
endfunc endfunc
func Test_spellfile_value() func Test_spellfile_value()
set spellfile=Xdir/Xtest.utf-8.add set spellfile=Xdir/Xtest.utf-8.add
set spellfile=Xdir/Xtest.utf-8.add,Xtest_other.add set spellfile=Xdir/Xtest.utf-8.add,Xtest_other.add
set spellfile=
endfunc
func Test_no_crash_with_weird_text()
new
let lines =<< trim END
r<sfile>
€
€
END
call setline(1, lines)
exe "%norm \<C-v>ez=>\<C-v>wzG"
bwipe!
endfunc endfunc
" Invalid bytes may cause trouble when creating the word list. " Invalid bytes may cause trouble when creating the word list.
@ -773,5 +790,18 @@ func Test_check_for_valid_word()
call assert_fails("spellgood! 0\xac", 'E1280:') call assert_fails("spellgood! 0\xac", 'E1280:')
endfunc endfunc
" This was going over the end of the word
func Test_word_index()
new
norm R0
spellgood! fl0
sil norm z=
bwipe!
" clear the word list
set enc=utf-8
call delete('Xtmpfile')
endfunc
" vim: shiftwidth=2 sts=2 expandtab " vim: shiftwidth=2 sts=2 expandtab