0
0
mirror of https://github.com/vim/vim.git synced 2025-09-25 03:54:15 -04:00

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.
This commit is contained in:
Bram Moolenaar
2017-01-29 17:59:12 +01:00
parent 24c2e48ef8
commit ddf662a1c8
4 changed files with 313 additions and 309 deletions

View File

@@ -6166,6 +6166,9 @@ insertchar(
&& (!has_mbyte || MB_BYTE2LEN_CHECK(c) == 1)
#endif
&& i < INPUT_BUFLEN
# ifdef FEAT_FKMAP
&& !(p_fkmap && KeyTyped) /* Farsi mode mapping moves cursor */
# endif
&& (textwidth == 0
|| (virtcol += byte2cells(buf[i - 1])) < (colnr_T)textwidth)
&& !(!no_abbr && !vim_iswordc(c) && vim_iswordc(buf[i - 1])))
@@ -6174,10 +6177,6 @@ insertchar(
c = vgetc();
if (p_hkmap && KeyTyped)
c = hkmap(c); /* Hebrew mode mapping */
# ifdef FEAT_FKMAP
if (p_fkmap && KeyTyped)
c = fkmap(c); /* Farsi mode mapping */
# endif
buf[i++] = c;
#else
buf[i++] = vgetc();

View File

@@ -15,26 +15,7 @@
#if defined(FEAT_FKMAP) || defined(PROTO)
static int toF_Xor_X_(int c);
static int F_is_TyE(int c);
static int F_is_TyC_TyD(int c);
static int F_is_TyB_TyC_TyD(int src, int offset);
static int toF_TyB(int c);
static void put_curr_and_l_to_X(int c);
static void put_and_redo(int c);
static void chg_c_toX_orX(void);
static void chg_c_to_X_orX_(void);
static void chg_c_to_X_or_X(void);
static void chg_l_to_X_orX_(void);
static void chg_l_toXor_X(void);
static void chg_r_to_Xor_X_(void);
static int toF_leading(int c);
static int toF_Rjoin(int c);
static int canF_Ljoin(int c);
static int canF_Rjoin(int c);
static int F_isterm(int c);
static int toF_ending(int c);
static void lrswapbuf(char_u *buf, int len);
/*
* Convert the given Farsi character into a _X or _X_ type
@@ -275,6 +256,15 @@ toF_TyB(int c)
return c;
}
static void
put_and_redo(int c)
{
pchar_cursor(c);
AppendCharToRedobuff(K_BS);
AppendCharToRedobuff(c);
}
/*
* Overwrite the current redo and cursor characters + left adjust.
*/
@@ -312,14 +302,6 @@ put_curr_and_l_to_X(int c)
put_and_redo(c);
}
static void
put_and_redo(int c)
{
pchar_cursor(c);
AppendCharToRedobuff(K_BS);
AppendCharToRedobuff(c);
}
/*
* Change the char. under the cursor to a X_ or X type
*/
@@ -447,7 +429,6 @@ chg_c_toX_orX(void)
/*
* Change the char. under the cursor to a _X_ or X_ type
*/
static void
chg_c_to_X_orX_(void)
{
@@ -598,7 +579,6 @@ chg_l_to_X_orX_(void)
/*
* Change the character left to the cursor to a X or _X type
*/
static void
chg_l_toXor_X(void)
{
@@ -667,7 +647,6 @@ chg_l_toXor_X (void)
/*
* Change the character right to the cursor to a _X or _X_ type
*/
static void
chg_r_to_Xor_X_(void)
{
@@ -692,19 +671,22 @@ chg_r_to_Xor_X_(void)
/*
* Map Farsi keyboard when in fkmap mode.
*/
int
fkmap(int c)
{
int tempc;
static int revins;
int insert_mode = (State & INSERT);
static int revins = 0;
if (IS_SPECIAL(c))
return c;
if (insert_mode)
{
if (VIM_ISDIGIT(c) || ((c == '.' || c == '+' || c == '-' ||
c == '^' || c == '%' || c == '#' || c == '=') && revins))
{
/* Numbers are entered left-to-right. */
if (!revins)
{
if (curwin->w_cursor.col)
@@ -729,10 +711,9 @@ fkmap(int c)
++revins;
p_ri = 1;
}
else
{
if (revins)
else if (revins)
{
/* Stop entering number. */
arrow_used = TRUE;
(void)stop_arrow();
@@ -844,13 +825,12 @@ fkmap(int c)
case NL:
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
* the one under the cursor with X type.
*/
dec_cursor();
if (F_isalpha(gchar_cursor()))
@@ -920,6 +900,9 @@ fkmap(int c)
}
break;
}
if (insert_mode)
{
if (!p_ri)
dec_cursor();
@@ -1040,6 +1023,7 @@ fkmap(int c)
if (!p_ri)
inc_cursor();
}
tempc = 0;
@@ -1376,7 +1360,7 @@ fkmap(int c)
break;
}
if ((F_isalpha(tempc) || F_isdigit(tempc)))
if (F_isalpha(tempc) || F_isdigit(tempc))
{
if (!curwin->w_cursor.col && STRLEN(ml_get_curline()))
{

View File

@@ -1,4 +1,5 @@
" Simplistic testing of Farsi mode.
" Note: must be edited with latin1 encoding.
if !has('farsi')
finish
@@ -82,3 +83,21 @@ func Test_farsi_map()
set noaltkeymap
bwipe!
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
call feedkeys("aB E F H I K L M O P Q R T U W Y ` ! @ # $ % ^ & * () - _ = + \\ | : \" . / < > ? \<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ա<33><D5A1><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 letter chars
call feedkeys("aa 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("\x8c<38>ν<EFBFBD><CEBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\x93ա<33><D5A1><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>Ѡ<EFBFBD><D1A0>̠ΠϠ<CEA0><CFA0><EFBFBD><EFBFBD>Ơàܠ<C3A0><DCA0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Š<EFBFBD><C5A0>ޠݠĠˠˠʠɠӠ٠Р<D9A0><D0A0>ؠ֠͠͠ҠԠԠנՠ<D7A0><D5A0>ڠ<EFBFBD>ߠǠȠ", getline('.'))
bwipe!
endfunc

View File

@@ -764,6 +764,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
262,
/**/
261,
/**/