Bram Moolenaar wrote: > > Dominique Pelle wrote: > >> Cursor seems to be at incorrect position when >> using 'binary' and 'rightleft' options. >> >> Here is how to reproduce bug: >> >> 1/ Create a sample file with a non-text character: >> >> $ perl -e 'print chr(0xfe)' > foo.txt >> >> 2/ Start vim with binary option and rightleft mode: >> >> $ vim -u NONE -b -c 'set rightleft' foo.txt >> >> Window contains: >> >> <fe> >> ~ >> ~ >> >> 3/ Press 'I' command to insert text at beginning of line (i.e. on the right >> since we're in rightleft mode) >> >> 4/ I'd expect cursor to be on the right of <fe> since this is where text >> will be inserted, however, cursor is on the left of <fe> (it looks like >> a bug to me, and it's confusing) >> >> +------- actual position of cursor (bug?) >> | +---- expected position >> | | >> <fe> >> ~ >> ~ >> >> - Insert some text 'abc'. Observe that text is properly inserted (but that >> cursor remains at incorrect position while inserting text): >> >> +------- actual position of cursor >> | +---- expected position >> | | >> <fe>cba >> ~ >> ~ >> >> -> Is this a bug or is it the expected behavior? >> >> I'm using vim-7.1 (Patches 1-220) built with 'configure --with-features=huge' >> on Linux in a gnome-terminal. > > An addition: 'encoding' has to be utf-8. Then I can see the bug. > After doing: > :set enc=latin display=uhex isprint=32-127 > it appears to work OK. So it's specific for utf-8. >
The cause of the bug is that utf_ptr2cells() returns 4 for an illegal byte. This patch fix the problem. Index: screen.c =================================================================== --- screen.c (revision 867) +++ screen.c (working copy) @@ -8040,7 +8040,10 @@ #ifdef FEAT_RIGHTLEFT curwin->w_p_rl ? ((int)W_WIDTH(curwin) - curwin->w_wcol - ( # ifdef FEAT_MBYTE - has_mbyte ? (*mb_ptr2cells)(ml_get_cursor()) : + /* use 1 for ^X and <hex> */ + (has_mbyte && ptr2cells(ml_get_cursor()) == 2 + && vim_isprintc(gchar_cursor())) ? + 2 : # endif 1)) : #endif -- Yukihiro Nakadaira - [EMAIL PROTECTED] --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_dev" maillist. For more information, visit http://www.vim.org/maillist.php -~----------~----~----~----~------~----~------~--~---