vim-patch:8.0.0262,8.0.0263 (#8123)

vim-patch:8.0.0262: Farsi support is barely tested
Problem:    Farsi support is barely tested.
Solution:   Add more tests for Farsi.  Clean up the code.
ddf662a1c8

vim-patch:8.0.0263: Farsi support is not tested enough
Problem:    Farsi support is not tested enough.
Solution:   Add more tests for Farsi.  Clean up the code.
80627cf51f
This commit is contained in:
KunMing Xie
2018-03-12 02:22:58 +08:00
committed by Justin M. Keyes
parent 9154782386
commit a2d1e9cc79
3 changed files with 256 additions and 201 deletions

View File

@@ -5241,28 +5241,27 @@ insertchar (
buf[0] = c; buf[0] = c;
i = 1; i = 1;
if (textwidth > 0) if (textwidth > 0) {
virtcol = get_nolist_virtcol(); virtcol = get_nolist_virtcol();
/* }
* Stop the string when: // Stop the string when:
* - no more chars available // - no more chars available
* - finding a special character (command key) // - finding a special character (command key)
* - buffer is full // - buffer is full
* - running into the 'textwidth' boundary // - running into the 'textwidth' boundary
* - need to check for abbreviation: A non-word char after a word-char // - need to check for abbreviation: A non-word char after a word-char
*/ while ((c = vpeekc()) != NUL
while ( (c = vpeekc()) != NUL && !ISSPECIAL(c)
&& !ISSPECIAL(c) && (!has_mbyte || MB_BYTE2LEN_CHECK(c) == 1)
&& (!has_mbyte || MB_BYTE2LEN_CHECK(c) == 1) && i < INPUT_BUFLEN
&& i < INPUT_BUFLEN && !(p_fkmap && KeyTyped) // Farsi mode mapping moves cursor
&& (textwidth == 0 && (textwidth == 0
|| (virtcol += byte2cells(buf[i - 1])) < (colnr_T)textwidth) || (virtcol += byte2cells(buf[i - 1])) < (colnr_T)textwidth)
&& !(!no_abbr && !vim_iswordc(c) && vim_iswordc(buf[i - 1]))) { && !(!no_abbr && !vim_iswordc(c) && vim_iswordc(buf[i - 1]))) {
c = vgetc(); c = vgetc();
if (p_hkmap && KeyTyped) if (p_hkmap && KeyTyped) {
c = hkmap(c); /* Hebrew mode mapping */ c = hkmap(c); // Hebrew mode mapping
if (p_fkmap && KeyTyped) }
c = fkmap(c); /* Farsi mode mapping */
buf[i++] = c; buf[i++] = c;
} }

View File

@@ -596,78 +596,83 @@ static void chg_r_to_Xor_X_(void)
int fkmap(int c) int fkmap(int c)
{ {
int tempc; int tempc;
static int revins; int insert_mode = (State & INSERT);
static int revins = 0;
if (IS_SPECIAL(c)) { if (IS_SPECIAL(c)) {
return c; return c;
} }
if (ascii_isdigit(c) if (insert_mode) {
|| ((c == '.' if (ascii_isdigit(c)
|| c == '+' || ((c == '.'
|| c == '-' || c == '+'
|| c == '^' || c == '-'
|| c == '%' || c == '^'
|| c == '#' || c == '%'
|| c == '=') || c == '#'
&& revins)) { || c == '=')
if (!revins) { && revins)) {
if (curwin->w_cursor.col) { // Numbers are entered left-to-right.
if (!p_ri) { if (!revins) {
dec_cursor();
}
chg_c_toX_orX();
chg_l_toXor_X();
if (!p_ri) {
inc_cursor();
}
}
}
arrow_used = TRUE;
(void)stop_arrow();
if (!curwin->w_p_rl && revins) {
inc_cursor();
}
revins++;
p_ri = 1;
} else {
if (revins) {
arrow_used = TRUE;
(void)stop_arrow();
revins = 0;
if (curwin->w_p_rl) {
while ((F_isdigit(gchar_cursor())
|| (gchar_cursor() == F_PERIOD
|| gchar_cursor() == F_PLUS
|| gchar_cursor() == F_MINUS
|| gchar_cursor() == F_MUL
|| gchar_cursor() == F_DIVIDE
|| gchar_cursor() == F_PERCENT
|| gchar_cursor() == F_EQUALS))
&& gchar_cursor() != NUL) {
curwin->w_cursor.col++;
}
} else {
if (curwin->w_cursor.col) { if (curwin->w_cursor.col) {
while ((F_isdigit(gchar_cursor()) if (!p_ri) {
|| (gchar_cursor() == F_PERIOD dec_cursor();
|| gchar_cursor() == F_PLUS }
|| gchar_cursor() == F_MINUS
|| gchar_cursor() == F_MUL chg_c_toX_orX();
|| gchar_cursor() == F_DIVIDE chg_l_toXor_X();
|| gchar_cursor() == F_PERCENT if (!p_ri) {
|| gchar_cursor() == F_EQUALS)) inc_cursor();
&& --curwin->w_cursor.col) {
} }
} }
}
if (!F_isdigit(gchar_cursor())) { arrow_used = true;
++curwin->w_cursor.col; (void)stop_arrow();
if (!curwin->w_p_rl && revins) {
inc_cursor();
}
revins++;
p_ri = 1;
} else {
if (revins) {
// Stop entering number.
arrow_used = true;
(void)stop_arrow();
revins = 0;
if (curwin->w_p_rl) {
while ((F_isdigit(gchar_cursor())
|| (gchar_cursor() == F_PERIOD
|| gchar_cursor() == F_PLUS
|| gchar_cursor() == F_MINUS
|| gchar_cursor() == F_MUL
|| gchar_cursor() == F_DIVIDE
|| gchar_cursor() == F_PERCENT
|| gchar_cursor() == F_EQUALS))
&& gchar_cursor() != NUL) {
curwin->w_cursor.col++;
}
} else {
if (curwin->w_cursor.col) {
while ((F_isdigit(gchar_cursor())
|| (gchar_cursor() == F_PERIOD
|| gchar_cursor() == F_PLUS
|| gchar_cursor() == F_MINUS
|| gchar_cursor() == F_MUL
|| gchar_cursor() == F_DIVIDE
|| gchar_cursor() == F_PERCENT
|| gchar_cursor() == F_EQUALS))
&& --curwin->w_cursor.col) {
}
}
if (!F_isdigit(gchar_cursor())) {
curwin->w_cursor.col++;
}
} }
} }
} }
@@ -755,7 +760,7 @@ int fkmap(int c)
case 'Y': case 'Y':
case NL: case NL:
case TAB: case TAB:
if (p_ri && (c == NL) && curwin->w_cursor.col) { if (p_ri && (c == NL) && curwin->w_cursor.col && insert_mode) {
// If the char before the cursor is _X_ or X_ do not change // If the char before the cursor is _X_ or X_ do not change
// the one under the cursor with X type. // the one under the cursor with X type.
@@ -826,135 +831,137 @@ int fkmap(int c)
} }
} }
if (!p_ri) { if (insert_mode) {
dec_cursor(); if (!p_ri) {
} dec_cursor();
}
switch ((tempc = gchar_cursor())) { switch ((tempc = gchar_cursor())) {
case _BE: case _BE:
case _PE: case _PE:
case _TE: case _TE:
case _SE: case _SE:
case _JIM: case _JIM:
case _CHE: case _CHE:
case _HE_J: case _HE_J:
case _XE: case _XE:
case _SIN: case _SIN:
case _SHIN: case _SHIN:
case _SAD: case _SAD:
case _ZAD: case _ZAD:
case _FE: case _FE:
case _GHAF: case _GHAF:
case _KAF: case _KAF:
case _KAF_H: case _KAF_H:
case _GAF: case _GAF:
case _LAM: case _LAM:
case _MIM: case _MIM:
case _NOON: case _NOON:
case _HE: case _HE:
case _HE_: case _HE_:
case _TA: case _TA:
case _ZA: case _ZA:
put_curr_and_l_to_X(toF_TyA((char_u)tempc)); put_curr_and_l_to_X(toF_TyA((char_u)tempc));
break; break;
case _AYN: case _AYN:
case _AYN_: case _AYN_:
if (!p_ri) { if (!p_ri) {
if (!curwin->w_cursor.col) { if (!curwin->w_cursor.col) {
put_curr_and_l_to_X(AYN); put_curr_and_l_to_X(AYN);
break; break;
}
} }
}
if (p_ri) { if (p_ri) {
inc_cursor(); inc_cursor();
} else { } else {
dec_cursor(); dec_cursor();
}
if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR)) {
tempc = AYN_;
} else {
tempc = AYN;
}
if (p_ri) {
dec_cursor();
} else {
inc_cursor();
}
put_curr_and_l_to_X((char_u)tempc);
break;
case _GHAYN:
case _GHAYN_:
if (!p_ri) {
if (!curwin->w_cursor.col) {
put_curr_and_l_to_X(GHAYN);
break;
} }
}
if (p_ri) { if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR)) {
inc_cursor(); tempc = AYN_;
} else { } else {
dec_cursor(); tempc = AYN;
}
if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR)) {
tempc = GHAYN_;
} else {
tempc = GHAYN;
}
if (p_ri) {
dec_cursor();
} else {
inc_cursor();
}
put_curr_and_l_to_X((char_u)tempc);
break;
case _YE:
case _IE:
case _YEE:
if (!p_ri) {
if (!curwin->w_cursor.col) {
put_curr_and_l_to_X(
(tempc == _YE ? YE : tempc == _IE ? IE : YEE));
break;
} }
}
if (p_ri) { if (p_ri) {
inc_cursor(); dec_cursor();
} else { } else {
dec_cursor(); inc_cursor();
} }
if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR)) { put_curr_and_l_to_X((char_u)tempc);
tempc = (tempc == _YE ? YE_ : tempc == _IE ? IE_ : YEE_); break;
} else {
tempc = (tempc == _YE ? YE : tempc == _IE ? IE : YEE);
}
if (p_ri) { case _GHAYN:
dec_cursor(); case _GHAYN_:
} else {
inc_cursor();
}
put_curr_and_l_to_X((char_u)tempc); if (!p_ri) {
break; if (!curwin->w_cursor.col) {
} put_curr_and_l_to_X(GHAYN);
break;
}
}
if (!p_ri) { if (p_ri) {
inc_cursor(); inc_cursor();
} else {
dec_cursor();
}
if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR)) {
tempc = GHAYN_;
} else {
tempc = GHAYN;
}
if (p_ri) {
dec_cursor();
} else {
inc_cursor();
}
put_curr_and_l_to_X((char_u)tempc);
break;
case _YE:
case _IE:
case _YEE:
if (!p_ri) {
if (!curwin->w_cursor.col) {
put_curr_and_l_to_X(
(tempc == _YE ? YE : tempc == _IE ? IE : YEE));
break;
}
}
if (p_ri) {
inc_cursor();
} else {
dec_cursor();
}
if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR)) {
tempc = (tempc == _YE ? YE_ : tempc == _IE ? IE_ : YEE_);
} else {
tempc = (tempc == _YE ? YE : tempc == _IE ? IE : YEE);
}
if (p_ri) {
dec_cursor();
} else {
inc_cursor();
}
put_curr_and_l_to_X((char_u)tempc);
break;
}
if (!p_ri) {
inc_cursor();
}
} }
tempc = 0; tempc = 0;

View File

@@ -1,4 +1,5 @@
" Simplistic testing of Farsi mode. " Simplistic testing of Farsi mode.
" Note: must be edited with latin1 encoding.
if !has('farsi') || has('nvim') " Not supported in Nvim. #6192 if !has('farsi') || has('nvim') " Not supported in Nvim. #6192
finish finish
@@ -82,3 +83,51 @@ func Test_farsi_map()
set noaltkeymap set noaltkeymap
bwipe! bwipe!
endfunc endfunc
func Test_input_farsi()
new
setlocal rightleft fkmap
" numbers switch input direction
call feedkeys("aabc0123456789.+-^%#=xyz\<Esc>", 'tx')
call assert_equal("\x8c<38>ν<EFBFBD><CEBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\x93<39>", getline('.'))
" all non-number special chars with spaces
call feedkeys("oB E F H I K L M O P Q R T U W Y ` ! @ # $ % ^ & * () - _ = + \\ | : \" . / < > ? \<Esc>", 'tx')
call assert_equal("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> [<5B>]<5D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>񠢠<EFBFBD><F1A0A2A0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E8A0A8><EFBFBD><EFBFBD><EFBFBD><E9A0BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EAA0BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", getline('.'))
" all non-number special chars without spaces
call feedkeys("oBEFHIKLMOPQRTUWY`!@#$%^&*()-_=+\\|:\"./<>?\<Esc>",'tx')
call assert_equal("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>[]<5D><><EFBFBD><EFBFBD><EFBFBD>񢣧<EFBFBD><F1A2A3A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EABABB><EFBFBD><EFBFBD><EFBFBD>", getline('.'))
" all letter chars with spaces
call feedkeys("oa A b c C d D e f g G h i j J k l m n N o p q r s S t u v V w x X y z Z ; \ , [ ] \<Esc>", 'tx')
call assert_equal(<><D1A0>̠ΠϠ<CEA0><CFA0><EFBFBD><EFBFBD>Ơàܠ<C3A0><DCA0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Š<EFBFBD><C5A0>ޠݠĠˠˠʠɠӠ٠Р<D9A0><D0A0>ؠ֠͠͠ҠԠԠנՠ<D7A0><D5A0>ڠ<EFBFBD>ߠǠȠ", getline('.'))
" all letter chars without spaces
call feedkeys("oaAbcCdDefgGhijJklmnNopqrsStuvVwxXyzZ;\,[]\<Esc>", 'tx')
call assert_equal("\x8c<38><63><EFBFBD><EFBFBD>\x9f<39>\x86\x83<38><33><EFBFBD>\x9d\x85\x80\x9c\x9b\x84<38><34>\x8a\x89\x8e\x96\x8b<38>\x95\x90<39><30>\x8d<38><64>\x93<39><33>\x97<39>\x87\x88", getline('.'))
bwipe!
endfunc
func Test_command_line_farsi()
set allowrevins altkeymap
" letter characters with spaces
call feedkeys(":\"\<C-_>a A b c C d D e f g G h i j J k l m n N o p q r s S t u v V w x X y z Z ; \\ , [ ]\<CR>", 'tx')
call assert_equal("\"\x88<38>Ǡߠ<C7A0><DFA0>ڠՠՠנԠԠҠ֠͠͠ؠ<D6A0><D8A0>Р٠ӠɠʠˠˠĠݠޠ<DDA0><DEA0>Š<EFBFBD><C5A0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܠàƠ<C3A0><C6A0><EFBFBD><EFBFBD>ϠΠ̠<CEA0><CCA0><EFBFBD>", getreg(':'))
" letter characters without spaces
call feedkeys(":\"\<C-_>aAbcCdDefgGhijJklmnNopqrsStuvVwxXyzZ;\\,[]\<CR>", 'tx')
call assert_equal("\"\x88\x87<38><37><EFBFBD><EFBFBD><EFBFBD>\x93<39><33>\x8d<38><64>\x90\x95<39>\x8b\x96\x8e\x89\x8a<38><61>\x84\x9b\x9c\x80\x85\x9d<39><64><EFBFBD>\x83\x86<38>\x9f<39><66><EFBFBD><EFBFBD>\x8c", getreg(':'))
" other characters with spaces
call feedkeys(":\"\<C-_>0 1 2 3 4 5 6 7 8 9 ` . ! \" $ % ^ & / () = \\ ? + - _ * : # ~ @ < > { } | B E F H I K L M O P Q R T U W Y\<CR>", 'tx')
call assert_equal("\"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>]<5D>[<5B> <EFBFBD><C2A0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>}<7D>{<7B><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>~<7E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E9A0AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EBA0BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", getreg(':'))
" other characters without spaces
call feedkeys(":\"\<C-_>0123456789`.!\"$%^&/()=\\?+-_*:#~@<>{}|BEFHIKLMOPQRTUWY\<CR>", 'tx')
call assert_equal("\"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>][<5B><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>}{<7B><><EFBFBD>~<7E><><EFBFBD><EFBFBD><EFBFBD><EBBDA9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", getreg(':'))
set noallowrevins noaltkeymap
endfunc