mirror of
https://github.com/neovim/neovim.git
synced 2024-12-29 14:41:06 -07:00
vim-patch:9.0.1595: line pointer becomes invalid when using spell checking
Problem: Line pointer becomes invalid when using spell checking.
Solution: Call ml_get() at the right places. (Luuk van Baal, closes vim/vim#12456)
e84c773d42
This commit is contained in:
parent
316c877034
commit
ac1ad9651e
@ -1377,9 +1377,6 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool number_onl
|
||||
line_attr_lowprio_save = wlv.line_attr_lowprio;
|
||||
}
|
||||
|
||||
line = end_fill ? "" : ml_get_buf(wp->w_buffer, lnum, false);
|
||||
ptr = line;
|
||||
|
||||
if (spv->spv_has_spell && !number_only) {
|
||||
// Prepare for spell checking.
|
||||
extra_check = true;
|
||||
@ -1389,28 +1386,36 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool number_onl
|
||||
if (lnum == spv->spv_checked_lnum) {
|
||||
cur_checked_col = spv->spv_checked_col;
|
||||
}
|
||||
if (lnum != spv->spv_capcol_lnum) {
|
||||
// Previous line was not spell checked, check for capital. This happens
|
||||
// for the first line in an updated region or after a closed fold.
|
||||
if (spv->spv_capcol_lnum == 0 && check_need_cap(wp, lnum, 0)) {
|
||||
spv->spv_cap_col = 0;
|
||||
} else if (lnum != spv->spv_capcol_lnum) {
|
||||
spv->spv_cap_col = -1;
|
||||
}
|
||||
spv->spv_checked_lnum = 0;
|
||||
|
||||
// For checking first word with a capital skip white space.
|
||||
if (spv->spv_cap_col == 0) {
|
||||
spv->spv_cap_col = (int)getwhitecols(line);
|
||||
} else if (*skipwhite(line) == NUL) {
|
||||
// If current line is empty, check first word in next line for capital.
|
||||
spv->spv_cap_col = 0;
|
||||
spv->spv_capcol_lnum = lnum + 1;
|
||||
}
|
||||
|
||||
// Get the start of the next line, so that words that wrap to the
|
||||
// next line are found too: "et<line-break>al.".
|
||||
// Trick: skip a few chars for C/shell/Vim comments
|
||||
nextline[SPWORDLEN] = NUL;
|
||||
if (lnum < wp->w_buffer->b_ml.ml_line_count) {
|
||||
spell_cat_line(nextline + SPWORDLEN,
|
||||
ml_get_buf(wp->w_buffer, lnum + 1, false), SPWORDLEN);
|
||||
line = ml_get_buf(wp->w_buffer, lnum + 1, false);
|
||||
spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
|
||||
}
|
||||
line = end_fill ? "" : ml_get_buf(wp->w_buffer, lnum, false);
|
||||
|
||||
// If current line is empty, check first word in next line for capital.
|
||||
ptr = skipwhite(line);
|
||||
if (*ptr == NUL) {
|
||||
spv->spv_cap_col = 0;
|
||||
spv->spv_capcol_lnum = lnum + 1;
|
||||
}
|
||||
// For checking first word with a capital skip white space.
|
||||
else if (spv->spv_cap_col == 0) {
|
||||
spv->spv_cap_col = (int)(ptr - line);
|
||||
}
|
||||
|
||||
// Copy the end of the current line into nextline[].
|
||||
if (nextline[SPWORDLEN] == NUL) {
|
||||
// No next line or it is empty.
|
||||
@ -1434,6 +1439,9 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool number_onl
|
||||
}
|
||||
}
|
||||
|
||||
line = end_fill ? "" : ml_get_buf(wp->w_buffer, lnum, false);
|
||||
ptr = line;
|
||||
|
||||
colnr_T trailcol = MAXCOL; // start of trailing spaces
|
||||
colnr_T leadcol = 0; // start of leading spaces
|
||||
|
||||
|
@ -1995,11 +1995,9 @@ static void win_update(win_T *wp, DecorProviders *providers)
|
||||
spellvars_T spv = { 0 };
|
||||
linenr_T lnum = wp->w_topline; // first line shown in window
|
||||
// Initialize spell related variables for the first drawn line.
|
||||
spv.spv_has_spell = spell_check_window(wp);
|
||||
if (spv.spv_has_spell) {
|
||||
if (spell_check_window(wp)) {
|
||||
spv.spv_has_spell = true;
|
||||
spv.spv_unchanged = mod_top == 0;
|
||||
spv.spv_capcol_lnum = mod_top ? mod_top : lnum;
|
||||
spv.spv_cap_col = check_need_cap(wp, spv.spv_capcol_lnum, 0) ? 0 : -1;
|
||||
}
|
||||
|
||||
// Update all the window rows.
|
||||
@ -2242,16 +2240,10 @@ static void win_update(win_T *wp, DecorProviders *providers)
|
||||
syntax_last_parsed = lnum;
|
||||
} else {
|
||||
foldinfo.fi_lines--;
|
||||
linenr_T lnume = lnum + foldinfo.fi_lines;
|
||||
wp->w_lines[idx].wl_folded = true;
|
||||
wp->w_lines[idx].wl_lastlnum = lnume;
|
||||
|
||||
// Check if the line after this fold requires a capital.
|
||||
if (spv.spv_has_spell && check_need_cap(wp, lnume + 1, 0)) {
|
||||
spv.spv_cap_col = 0;
|
||||
spv.spv_capcol_lnum = lnume + 1;
|
||||
}
|
||||
wp->w_lines[idx].wl_lastlnum = lnum + foldinfo.fi_lines;
|
||||
did_update = DID_FOLD;
|
||||
spv.spv_capcol_lnum = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2288,6 +2280,7 @@ static void win_update(win_T *wp, DecorProviders *providers)
|
||||
}
|
||||
lnum = wp->w_lines[idx - 1].wl_lastlnum + 1;
|
||||
did_update = DID_NONE;
|
||||
spv.spv_capcol_lnum = 0;
|
||||
}
|
||||
|
||||
// 'statuscolumn' width has changed or errored, start from the top.
|
||||
|
@ -178,6 +178,30 @@ describe("'spell'", function()
|
||||
{0:~ }|
|
||||
|
|
||||
]])
|
||||
-- Adding an empty line does not remove Cap in "mod_bot" area
|
||||
feed('zbO<Esc>')
|
||||
screen:expect([[
|
||||
This line has a {1:sepll} error. {2:and} missing caps and trailing spaces. |
|
||||
^ |
|
||||
{2:another} missing cap here |
|
||||
{10:+-- 2 lines: Not·······························································}|
|
||||
{2:and} here. |
|
||||
{0:~ }|
|
||||
{0:~ }|
|
||||
|
|
||||
]])
|
||||
-- Multiple empty lines does not remove Cap in the line after
|
||||
feed('O<Esc><C-L>')
|
||||
screen:expect([[
|
||||
This line has a {1:sepll} error. {2:and} missing caps and trailing spaces. |
|
||||
^ |
|
||||
|
|
||||
{2:another} missing cap here |
|
||||
{10:+-- 2 lines: Not·······························································}|
|
||||
{2:and} here. |
|
||||
{0:~ }|
|
||||
|
|
||||
]])
|
||||
end)
|
||||
|
||||
-- oldtest: Test_spell_compatible()
|
||||
|
@ -962,6 +962,7 @@ func Test_spell_screendump()
|
||||
CheckScreendump
|
||||
|
||||
let lines =<< trim END
|
||||
call test_override('alloc_lines', 1)
|
||||
call setline(1, [
|
||||
\ "This is some text without any spell errors. Everything",
|
||||
\ "should just be black, nothing wrong here.",
|
||||
@ -984,6 +985,7 @@ func Test_spell_screendump_spellcap()
|
||||
CheckScreendump
|
||||
|
||||
let lines =<< trim END
|
||||
call test_override('alloc_lines', 1)
|
||||
call setline(1, [
|
||||
\ " This line has a sepll error. and missing caps and trailing spaces. ",
|
||||
\ "another missing cap here.",
|
||||
@ -1023,6 +1025,14 @@ func Test_spell_screendump_spellcap()
|
||||
call term_sendkeys(buf, "\<C-E>\<C-L>")
|
||||
call VerifyScreenDump(buf, 'Test_spell_8', {})
|
||||
|
||||
" Adding an empty line does not remove Cap in "mod_bot" area
|
||||
call term_sendkeys(buf, "zbO\<Esc>")
|
||||
call VerifyScreenDump(buf, 'Test_spell_9', {})
|
||||
|
||||
" Multiple empty lines does not remove Cap in the line after
|
||||
call term_sendkeys(buf, "O\<Esc>\<C-L>")
|
||||
call VerifyScreenDump(buf, 'Test_spell_10', {})
|
||||
|
||||
" clean up
|
||||
call StopVimInTerminal(buf)
|
||||
endfunc
|
||||
@ -1031,6 +1041,7 @@ func Test_spell_compatible()
|
||||
CheckScreendump
|
||||
|
||||
let lines =<< trim END
|
||||
call test_override('alloc_lines', 1)
|
||||
call setline(1, [
|
||||
\ "test "->repeat(20),
|
||||
\ "",
|
||||
|
Loading…
Reference in New Issue
Block a user