diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/change.c | 10 | ||||
-rw-r--r-- | src/nvim/drawline.c | 18 | ||||
-rw-r--r-- | src/nvim/edit.c | 5 | ||||
-rw-r--r-- | src/nvim/spell.c | 14 | ||||
-rw-r--r-- | src/nvim/undo.c | 7 |
5 files changed, 38 insertions, 16 deletions
diff --git a/src/nvim/change.c b/src/nvim/change.c index f4969d0ca9..9e1767c2f3 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -43,6 +43,7 @@ #include "nvim/plines.h" #include "nvim/pos.h" #include "nvim/search.h" +#include "nvim/spell.h" #include "nvim/state.h" #include "nvim/strings.h" #include "nvim/textformat.h" @@ -393,6 +394,15 @@ void changed_bytes(linenr_T lnum, colnr_T col) { changedOneline(curbuf, lnum); changed_common(lnum, col, lnum + 1, 0); + // When text has been changed at the end of the line, possibly the start of + // the next line may have SpellCap that should be removed or it needs to be + // displayed. Schedule the next line for redrawing just in case. + // Don't do this when displaying '$' at the end of changed text. + if (spell_check_window(curwin) + && lnum < curbuf->b_ml.ml_line_count + && vim_strchr(p_cpo, CPO_DOLLAR) == NULL) { + redrawWinline(curwin, lnum + 1); + } // notify any channels that are watching buf_updates_send_changes(curbuf, lnum, 1, 1); diff --git a/src/nvim/drawline.c b/src/nvim/drawline.c index 927b1247be..54da38a6ff 100644 --- a/src/nvim/drawline.c +++ b/src/nvim/drawline.c @@ -1203,12 +1203,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, draw_color_col = advance_color_col(VCOL_HLC, &color_cols); } - if (wp->w_p_spell - && !has_fold - && !end_fill - && *wp->w_s->b_p_spl != NUL - && !GA_EMPTY(&wp->w_s->b_langp) - && *(char **)(wp->w_s->b_langp.ga_data) != NULL) { + if (!has_fold && !end_fill && spell_check_window(wp)) { // Prepare for spell checking. has_spell = true; extra_check = true; @@ -2188,12 +2183,13 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, v = (ptr - line); if (has_spell && v >= word_end && v > cur_checked_col) { spell_attr = 0; - if (c != 0 && ((!has_syntax && !no_plain_buffer) || can_spell)) { - char *prev_ptr; + char *prev_ptr = ptr - mb_l; + // do not calculate cap_col at the end of the line or when + // only white space is following + if (c != 0 && (*skipwhite(prev_ptr) != NUL) + && ((!has_syntax && !no_plain_buffer) || can_spell)) { char *p; - int len; hlf_T spell_hlf = HLF_COUNT; - prev_ptr = ptr - mb_l; v -= mb_l - 1; // Use nextline[] if possible, it has the start of the @@ -2206,7 +2202,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, cap_col -= (int)(prev_ptr - line); size_t tmplen = spell_check(wp, p, &spell_hlf, &cap_col, nochange); assert(tmplen <= INT_MAX); - len = (int)tmplen; + int len = (int)tmplen; word_end = (int)v + len; // In Insert mode only highlight a word that diff --git a/src/nvim/edit.c b/src/nvim/edit.c index a25387f5a6..d6d5ff8ac7 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -53,6 +53,7 @@ #include "nvim/popupmenu.h" #include "nvim/pos.h" #include "nvim/search.h" +#include "nvim/spell.h" #include "nvim/state.h" #include "nvim/strings.h" #include "nvim/syntax.h" @@ -1526,8 +1527,8 @@ void edit_unputchar(void) } } -// Called when p_dollar is set: display a '$' at the end of the changed text -// Only works when cursor is in the line that changes. +/// Called when "$" is in 'cpoptions': display a '$' at the end of the changed +/// text. Only works when cursor is in the line that changes. void display_dollar(colnr_T col_arg) { colnr_T col = col_arg < 0 ? 0 : col_arg; diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 84875261f1..498bd56b9e 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -1189,11 +1189,19 @@ bool spell_valid_case(int wordflags, int treeflags) || (wordflags & WF_ONECAP) != 0)); } -// Returns true if spell checking is not enabled. +/// Return true if spell checking is enabled for "wp". +bool spell_check_window(win_T *wp) +{ + return wp->w_p_spell + && *wp->w_s->b_p_spl != NUL + && wp->w_s->b_langp.ga_len > 0 + && *(char **)(wp->w_s->b_langp.ga_data) != NULL; +} + +/// Return true and give an error if spell checking is not enabled. bool no_spell_checking(win_T *wp) { - if (!wp->w_p_spell || *wp->w_s->b_p_spl == NUL - || GA_EMPTY(&wp->w_s->b_langp)) { + if (!wp->w_p_spell || *wp->w_s->b_p_spl == NUL || GA_EMPTY(&wp->w_s->b_langp)) { emsg(_(e_no_spell)); return true; } diff --git a/src/nvim/undo.c b/src/nvim/undo.c index 00a3922a5b..1eb73d85d7 100644 --- a/src/nvim/undo.c +++ b/src/nvim/undo.c @@ -120,6 +120,7 @@ #include "nvim/path.h" #include "nvim/pos.h" #include "nvim/sha256.h" +#include "nvim/spell.h" #include "nvim/state.h" #include "nvim/strings.h" #include "nvim/types.h" @@ -2372,6 +2373,12 @@ static void u_undoredo(int undo, bool do_buf_event) } changed_lines(top + 1, 0, bot, newsize - oldsize, do_buf_event); + // When text has been changed, possibly the start of the next line + // may have SpellCap that should be removed or it needs to be + // displayed. Schedule the next line for redrawing just in case. + if (spell_check_window(curwin) && bot <= curbuf->b_ml.ml_line_count) { + redrawWinline(curwin, bot); + } // Set the '[ mark. if (top + 1 < curbuf->b_op_start.lnum) { |