diff options
author | Bram Moolenaar <bram@vim.org> | 2015-03-24 17:49:51 +0100 |
---|---|---|
committer | Bram Moolenaar <bram@vim.org> | 2015-03-24 17:49:51 +0100 |
commit | 21bd62125c1f99e6b341b714d7b56e73b9a68731 (patch) | |
tree | 9ca776ed5f9ef7e36d68dd7c4ae2fbf2e2add873 /src/edit.c | |
parent | 02b4fe7745ec50eab9f452e43db092f53c14c5d2 (diff) | |
download | vim-21bd62125c1f99e6b341b714d7b56e73b9a68731.tar.gz |
Problem: CTRL-W in Insert mode does not work well for multi-byte
characters.
Solution: Use mb_get_class(). (Yasuhiro Matsumoto)
Diffstat (limited to 'src/edit.c')
-rw-r--r-- | src/edit.c | 120 |
1 files changed, 71 insertions, 49 deletions
@@ -9047,72 +9047,94 @@ ins_bs(c, mode, inserted_space_p) /* * Delete upto starting point, start of line or previous word. */ - else do + else { +#ifdef FEAT_MBYTE + int cclass = 0, prev_cclass = 0; + + if (has_mbyte) + cclass = mb_get_class(ml_get_cursor()); +#endif + do + { #ifdef FEAT_RIGHTLEFT - if (!revins_on) /* put cursor on char to be deleted */ + if (!revins_on) /* put cursor on char to be deleted */ #endif - dec_cursor(); + dec_cursor(); - /* start of word? */ - if (mode == BACKSPACE_WORD && !vim_isspace(gchar_cursor())) - { - mode = BACKSPACE_WORD_NOT_SPACE; - temp = vim_iswordc(gchar_cursor()); - } - /* end of word? */ - else if (mode == BACKSPACE_WORD_NOT_SPACE - && (vim_isspace(cc = gchar_cursor()) - || vim_iswordc(cc) != temp)) - { + cc = gchar_cursor(); +#ifdef FEAT_MBYTE + /* look multi-byte character class */ + if (has_mbyte) + { + prev_cclass = cclass; + cclass = mb_get_class(ml_get_cursor()); + } +#endif + + /* start of word? */ + if (mode == BACKSPACE_WORD && !vim_isspace(cc)) + { + mode = BACKSPACE_WORD_NOT_SPACE; + temp = vim_iswordc(cc); + } + /* end of word? */ + else if (mode == BACKSPACE_WORD_NOT_SPACE + && ((vim_isspace(cc) || vim_iswordc(cc) != temp) +#ifdef FEAT_MBYTE + || prev_cclass != cclass +#endif + )) + { #ifdef FEAT_RIGHTLEFT - if (!revins_on) + if (!revins_on) #endif - inc_cursor(); + inc_cursor(); #ifdef FEAT_RIGHTLEFT - else if (State & REPLACE_FLAG) - dec_cursor(); + else if (State & REPLACE_FLAG) + dec_cursor(); #endif - break; - } - if (State & REPLACE_FLAG) - replace_do_bs(-1); - else - { + break; + } + if (State & REPLACE_FLAG) + replace_do_bs(-1); + else + { #ifdef FEAT_MBYTE - if (enc_utf8 && p_deco) - (void)utfc_ptr2char(ml_get_cursor(), cpc); + if (enc_utf8 && p_deco) + (void)utfc_ptr2char(ml_get_cursor(), cpc); #endif - (void)del_char(FALSE); + (void)del_char(FALSE); #ifdef FEAT_MBYTE - /* - * If there are combining characters and 'delcombine' is set - * move the cursor back. Don't back up before the base - * character. - */ - if (enc_utf8 && p_deco && cpc[0] != NUL) - inc_cursor(); + /* + * If there are combining characters and 'delcombine' is set + * move the cursor back. Don't back up before the base + * character. + */ + if (enc_utf8 && p_deco && cpc[0] != NUL) + inc_cursor(); #endif #ifdef FEAT_RIGHTLEFT - if (revins_chars) - { - revins_chars--; - revins_legal++; + if (revins_chars) + { + revins_chars--; + revins_legal++; + } + if (revins_on && gchar_cursor() == NUL) + break; +#endif } - if (revins_on && gchar_cursor() == NUL) + /* Just a single backspace?: */ + if (mode == BACKSPACE_CHAR) break; -#endif - } - /* Just a single backspace?: */ - if (mode == BACKSPACE_CHAR) - break; - } while ( + } while ( #ifdef FEAT_RIGHTLEFT - revins_on || + revins_on || #endif - (curwin->w_cursor.col > mincol - && (curwin->w_cursor.lnum != Insstart_orig.lnum - || curwin->w_cursor.col != Insstart_orig.col))); + (curwin->w_cursor.col > mincol + && (curwin->w_cursor.lnum != Insstart_orig.lnum + || curwin->w_cursor.col != Insstart_orig.col))); + } did_backspace = TRUE; } #ifdef FEAT_SMARTINDENT |