Bug with cursor position in binary and rightleft mode?

0 views
Skip to first unread message

Dominique Pelle

unread,
Jan 12, 2008, 11:55:08 AM1/12/08
to vim_dev
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.

-- Dominique

Bram Moolenaar

unread,
Jan 12, 2008, 3:44:22 PM1/12/08
to Dominique Pelle, vim_dev

Dominique Pelle wrote:

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.

--
An indication you must be a manager:
You feel sorry for Dilbert's boss.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ download, build and distribute -- http://www.A-A-P.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Yukihiro Nakadaira

unread,
Feb 8, 2008, 10:00:02 AM2/8/08
to Bram Moolenaar, vim_dev

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 - yukihiro....@gmail.com


Dominique Pelle

unread,
Feb 9, 2008, 3:17:35 AM2/9/08
to vim...@googlegroups.com
On Feb 8, 2008 4:00 PM, Yukihiro Nakadaira <yukihiro....@gmail.com> wrote:

> Bram Moolenaar wrote:
> >
> > Dominique Pelle wrote:
> >
> >> Cursor seems to be at incorrect position when
> >> using 'binary' and 'rightleft' options.

[...]

> 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,

Just to confirm that your patch indeed fixes the bug I reported.

Thanks
-- Dominique

Reply all
Reply to author
Forward
0 new messages