To: vim-dev@vim.org Subject: Patch 7.1.220 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit ------------ Patch 7.1.220 Problem: When a ")" or word movement command moves the cursor back from the end of the line it may end up on the trail byte of a multi-byte character. It's also moved back when it isn't needed. Solution: Add the adjust_cursor() function. Files: src/normal.c *** ../vim-7.1.219/src/normal.c Sun Jan 6 20:05:36 2008 --- src/normal.c Sat Jan 12 17:10:14 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; } } *** ../vim-7.1.219/src/version.c Sat Jan 12 16:45:25 2008 --- src/version.c Sat Jan 12 17:07:28 2008 *************** *** 668,669 **** --- 668,671 ---- { /* Add new patch number below this line */ + /**/ + 220, /**/ -- A hamburger walks into a bar, and the bartender says: "I'm sorry, but we don't serve food here." /// Bram Moolenaar -- Bram@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 ///