Last active
August 29, 2015 14:14
-
-
Save mattn/47d39a30a63786d0d3dc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -r 84171683fd66 src/Makefile | |
--- a/src/Makefile Tue Jan 27 22:52:15 2015 +0100 | |
+++ b/src/Makefile Fri Jan 30 11:20:05 2015 +0900 | |
@@ -1907,6 +1907,7 @@ | |
test_signs \ | |
test_utf8 \ | |
test_writefile \ | |
+ test_erasebackword \ | |
test2 test3 test4 test5 test6 test7 test8 test9 \ | |
test10 test11 test12 test13 test14 test15 test16 test17 test18 test19 \ | |
test20 test21 test22 test23 test24 test25 test26 test27 test28 test29 \ | |
diff -r 84171683fd66 src/edit.c | |
--- a/src/edit.c Tue Jan 27 22:52:15 2015 +0100 | |
+++ b/src/edit.c Fri Jan 30 11:20:05 2015 +0900 | |
@@ -9038,72 +9038,93 @@ | |
/* | |
* 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 */ | |
-#endif | |
- 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)) | |
- { | |
+ if (!revins_on) /* put cursor on char to be deleted */ | |
+#endif | |
+ dec_cursor(); | |
+ | |
+ 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) | |
-#endif | |
- inc_cursor(); | |
+ if (!revins_on) | |
+#endif | |
+ inc_cursor(); | |
#ifdef FEAT_RIGHTLEFT | |
- else if (State & REPLACE_FLAG) | |
- dec_cursor(); | |
-#endif | |
- break; | |
- } | |
- if (State & REPLACE_FLAG) | |
- replace_do_bs(-1); | |
- else | |
- { | |
+ else if (State & REPLACE_FLAG) | |
+ dec_cursor(); | |
+#endif | |
+ 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); | |
-#endif | |
- (void)del_char(FALSE); | |
+ if (enc_utf8 && p_deco) | |
+ (void)utfc_ptr2char(ml_get_cursor(), cpc); | |
+#endif | |
+ (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 || | |
-#endif | |
- (curwin->w_cursor.col > mincol | |
- && (curwin->w_cursor.lnum != Insstart_orig.lnum | |
- || curwin->w_cursor.col != Insstart_orig.col))); | |
+ revins_on || | |
+#endif | |
+ (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 | |
diff -r 84171683fd66 src/testdir/test_erasebackword.in | |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 | |
+++ b/src/testdir/test_erasebackword.in Fri Jan 30 11:20:05 2015 +0900 | |
@@ -0,0 +1,19 @@ | |
+Test for erasing backword | |
+ | |
+STARTTEST | |
+:so small.vim | |
+:so mbyte.vim | |
+:set encoding=utf-8 | |
+G | |
+o wwwこんにちわ世界ワールドvim x23x27 | |
+o wwwこんにちわ世界ワールドvim x23x23x27 | |
+o wwwこんにちわ世界ワールドvim x23x23x23x27 | |
+o wwwこんにちわ世界ワールドvim x23x23x23x23x27 | |
+o wwwこんにちわ世界ワールドvim x23x23x23x23x23x27 | |
+o wwwこんにちわ世界ワールドvim x23x23x23x23x23x23x27 | |
+:/^test/,$w! test.out | |
+:qa! | |
+ENDTEST | |
+ | |
+test starts here: | |
+ | |
diff -r 84171683fd66 src/testdir/test_erasebackword.ok | |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 | |
+++ b/src/testdir/test_erasebackword.ok Fri Jan 30 11:20:05 2015 +0900 | |
@@ -0,0 +1,8 @@ | |
+test starts here: | |
+ | |
+ wwwこんにちわ世界ワールド | |
+ wwwこんにちわ世界 | |
+ wwwこんにちわ | |
+ www | |
+ | |
+ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment