Loading ...
Sorry, an error occurred while loading the content.
 

Re: Bug with )

Expand Messages
  • Bram Moolenaar
    ... Looking at this again, I notice a few other issues. The cursor column is decremented, which means it can end up on the trail byte of a multi-byte
    Message 1 of 9 , Jan 9, 2008
      Ben Schmidt wrote:
      > Ben Schmidt wrote:
      > > Adri Verhoef wrote:
      > >> An easy way to reproduce this bug:
      > >>
      > >> $ echo y > y
      > >> $ vim -u NONE y
      > >> "y" 1 line, 2 characters
      > >>
      > >> Then type ) and the cursor moves one position to the right, although there's nothing there!
      > >>
      > >>
      > >> Vim 7.1 - Included patches: 1-2, 4-6, 8-12 - on Fedora 7.
      > >
      > > I believe Bram fixed this bug with patch 190-something. I long way off your
      > > version, by the look of it. It seems to work in my Vim now, though, which is 7.1.203.
      >
      > Though, Bram, perhaps if 've' contains onemore, it should indeed place
      > the cursor beyond EOL? It doesn't now in either case.

      Looking at this again, I notice a few other issues. The cursor column
      is decremented, which means it can end up on the trail byte of a
      multi-byte character. I used the code for a word motion, so that code
      has the same problem.

      Also, in Visual mode when 'selection' is not "old" the cursor is allowed
      to remain past the end of the line.

      Have a look at this patch:

      *** ../vim-7.1.212/src/normal.c Sun Jan 6 20:05:36 2008
      --- src/normal.c Wed Jan 9 11:30:05 2008
      ***************
      *** 150,155 ****
      --- 150,156 ----
      static void nv_bck_word __ARGS((cmdarg_T *cap));
      static void nv_wordcmd __ARGS((cmdarg_T *cap));
      static void nv_beginline __ARGS((cmdarg_T *cap));
      + static void adjust_cursor __ARGS((oparg_T *oap));
      #ifdef FEAT_VISUAL
      static void adjust_for_sel __ARGS((cmdarg_T *cap));
      static int unadjust_for_sel __ARGS((void));
      ***************
      *** 6567,6578 ****
      clearopbeep(cap->oap);
      else
      {
      ! /* Don't leave the cursor on the NUL past a line */
      ! if (curwin->w_cursor.col > 0 && gchar_cursor() == NUL)
      ! {
      ! --curwin->w_cursor.col;
      ! cap->oap->inclusive = TRUE;
      ! }
      #ifdef FEAT_VIRTUALEDIT
      curwin->w_cursor.coladd = 0;
      #endif
      --- 6568,6575 ----
      clearopbeep(cap->oap);
      else
      {
      ! /* Don't leave the cursor on the NUL past end of line. */
      ! adjust_cursor(cap->oap);
      #ifdef FEAT_VIRTUALEDIT
      curwin->w_cursor.coladd = 0;
      #endif
      ***************
      *** 8408,8419 ****
      else
      n = fwd_word(cap->count1, cap->arg, cap->oap->op_type != OP_NOP);

      ! /* Don't leave the cursor on the NUL past a line */
      ! if (n != FAIL && curwin->w_cursor.col > 0 && gchar_cursor() == NUL)
      ! {
      ! --curwin->w_cursor.col;
      ! cap->oap->inclusive = TRUE;
      ! }

      if (n == FAIL && cap->oap->op_type == OP_NOP)
      clearopbeep(cap->oap);
      --- 8405,8413 ----
      else
      n = fwd_word(cap->count1, cap->arg, cap->oap->op_type != OP_NOP);

      ! /* Don't leave the cursor on the NUL past the end of line. */
      ! if (n != FAIL)
      ! adjust_cursor(cap->oap);

      if (n == FAIL && cap->oap->op_type == OP_NOP)
      clearopbeep(cap->oap);
      ***************
      *** 8426,8431 ****
      --- 8420,8458 ----
      if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP)
      foldOpenCursor();
      #endif
      + }
      + }
      +
      + /*
      + * Used after a movement command: If the cursor ends up on the NUL after the
      + * end of the line, may move it back to the last character and make the motion
      + * inclusive.
      + */
      + static void
      + adjust_cursor(oap)
      + oparg_T *oap;
      + {
      + /* The cursor cannot remain on the NUL when:
      + * - the column is 0
      + * - not in Visual mode or 'selection' is "o"
      + * - 'virtualedit' is not "all" and not "onemore".
      + */
      + if (curwin->w_cursor.col > 0 && gchar_cursor() == NUL
      + #ifdef FEAT_VISUAL
      + && (!VIsual_active || *p_sel == 'o')
      + #endif
      + #ifdef FEAT_VIRTUALEDIT
      + && !virtual_active() && (ve_flags & VE_ONEMORE) == 0
      + #endif
      + )
      + {
      + --curwin->w_cursor.col;
      + #ifdef FEAT_MBYTE
      + /* prevent cursor from moving on the trail byte */
      + if (has_mbyte)
      + mb_adjust_cursor();
      + #endif
      + oap->inclusive = TRUE;
      }
      }



      --
      There are 10 kinds of people: Those who understand binary and those who don't.

      /// Bram Moolenaar -- Bram@... -- 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 ///

      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_dev" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    Your message has been successfully submitted and would be delivered to recipients shortly.