To: vim-dev@vim.org Subject: Patch 6.2.338 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit ------------ Patch 6.2.338 (after 6.2.331) Problem: When undoing "gwap" the cursor is always put at the start of the paragraph. When undoing auto-formatting the cursor may be above the change. Solution: Try to move the cursor back to where it was or to the first line that actually changed. Files: src/normal.c, src/ops.c, src/undo.c *** ../vim-6.2.337/src/normal.c Tue Mar 9 12:41:56 2004 --- src/normal.c Tue Mar 9 18:17:19 2004 *************** *** 7288,7297 **** * "gU" Change text to upper case. * "g?" rot13 encoding */ case 'w': oap->cursor_start = curwin->w_cursor; /*FALLTHROUGH*/ - case 'q': case '~': case 'u': case 'U': --- 7291,7300 ---- * "gU" Change text to upper case. * "g?" rot13 encoding */ + case 'q': case 'w': oap->cursor_start = curwin->w_cursor; /*FALLTHROUGH*/ case '~': case 'u': case 'U': *** ../vim-6.2.337/src/ops.c Tue Mar 9 12:41:56 2004 --- src/ops.c Tue Mar 9 18:23:06 2004 *************** *** 4052,4060 **** --- 4052,4065 ---- { long old_line_count = curbuf->b_ml.ml_line_count; + /* Place the cursor where the "gq" or "gw" command was given, so that "u" + * can put it back there. */ + curwin->w_cursor = oap->cursor_start; + if (u_save((linenr_T)(oap->start.lnum - 1), (linenr_T)(oap->end.lnum + 1)) == FAIL) return; + curwin->w_cursor = oap->start; #ifdef FEAT_VISUAL if (oap->is_VIsual) *************** *** 4065,4070 **** --- 4070,4077 ---- /* Set '[ mark at the start of the formatted area */ curbuf->b_op_start = oap->start; + /* For "gw" remember the cursor position and put it back below (adjusted + * for joined and split lines). */ if (keep_cursor) saved_cursor = oap->cursor_start; *** ../vim-6.2.337/src/undo.c Sun Feb 29 20:46:43 2004 --- src/undo.c Tue Mar 9 18:33:05 2004 *************** *** 563,575 **** return; } if (top < newlnum) { ! newlnum = top; ! curwin->w_cursor.lnum = top + 1; } - oldsize = bot - top - 1; /* number of lines before undo */ - newsize = uep->ue_size; /* number of lines after undo */ empty_buffer = FALSE; --- 563,602 ---- return; } + oldsize = bot - top - 1; /* number of lines before undo */ + newsize = uep->ue_size; /* number of lines after undo */ + if (top < newlnum) { ! /* If the saved cursor is somewhere in this undo block, move it to ! * the remembered position. Makes "gwap" put the cursor back ! * where it was. */ ! lnum = curbuf->b_u_curhead->uh_cursor.lnum; ! if (lnum >= top && lnum <= top + newsize + 1) ! { ! curwin->w_cursor = curbuf->b_u_curhead->uh_cursor; ! newlnum = curwin->w_cursor.lnum - 1; ! } ! else ! { ! /* Use the first line that actually changed. Avoids that ! * undoing auto-formatting puts the cursor in the previous ! * line. */ ! for (i = 0; i < newsize && i < oldsize; ++i) ! if (STRCMP(uep->ue_array[i], ml_get(top + 1 + i)) != 0) ! break; ! if (i == newsize && newlnum == MAXLNUM && uep->ue_next == NULL) ! { ! newlnum = top; ! curwin->w_cursor.lnum = newlnum + 1; ! } ! else if (i < newsize) ! { ! newlnum = top + i; ! curwin->w_cursor.lnum = newlnum + 1; ! } ! } } empty_buffer = FALSE; *** ../vim-6.2.337/src/version.c Tue Mar 9 19:41:00 2004 --- src/version.c Tue Mar 9 19:43:47 2004 *************** *** 639,640 **** --- 639,642 ---- { /* Add new patch number below this line */ + /**/ + 338, /**/ -- Your company is doomed if your primary product is overhead transparencies. (Scott Adams - The Dilbert principle) /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ Project leader for A-A-P -- http://www.A-A-P.org /// \\\ Buy at Amazon and help AIDS victims -- http://ICCF.nl/click1.html ///