comparison src/misc1.c @ 5403:b9c1c1f4cda9 v7.4.052

updated for version 7.4.052 Problem: With 'fo' set to "a2" inserting a space in the first column may cause the cursor to jump to the previous line. Solution: Handle the case when there is no comment leader properly. (Tor Perkins) Also fix that cursor is in the wrong place when spaces get replaced with a Tab.
author Bram Moolenaar <bram@vim.org>
date Sun, 06 Oct 2013 17:46:56 +0200
parents 965044860b7f
children 38b948f534e4
comparison
equal deleted inserted replaced
5402:8d1edeae0e62 5403:b9c1c1f4cda9
301 if (!(flags & SIN_UNDO) || u_savesub(curwin->w_cursor.lnum) == OK) 301 if (!(flags & SIN_UNDO) || u_savesub(curwin->w_cursor.lnum) == OK)
302 { 302 {
303 ml_replace(curwin->w_cursor.lnum, newline, FALSE); 303 ml_replace(curwin->w_cursor.lnum, newline, FALSE);
304 if (flags & SIN_CHANGED) 304 if (flags & SIN_CHANGED)
305 changed_bytes(curwin->w_cursor.lnum, 0); 305 changed_bytes(curwin->w_cursor.lnum, 0);
306 /* Correct saved cursor position if it's after the indent. */ 306 /* Correct saved cursor position if it is in this line. */
307 if (saved_cursor.lnum == curwin->w_cursor.lnum 307 if (saved_cursor.lnum == curwin->w_cursor.lnum)
308 && saved_cursor.col >= (colnr_T)(p - oldline)) 308 {
309 saved_cursor.col += ind_len - (colnr_T)(p - oldline); 309 if (saved_cursor.col >= (colnr_T)(p - oldline))
310 /* cursor was after the indent, adjust for the number of
311 * bytes added/removed */
312 saved_cursor.col += ind_len - (colnr_T)(p - oldline);
313 else if (saved_cursor.col >= (colnr_T)(s - newline))
314 /* cursor was in the indent, and is now after it, put it back
315 * at the start of the indent (replacing spaces with TAB) */
316 saved_cursor.col = (colnr_T)(s - newline);
317 }
310 retval = TRUE; 318 retval = TRUE;
311 } 319 }
312 else 320 else
313 vim_free(newline); 321 vim_free(newline);
314 322
1579 return retval; 1587 return retval;
1580 } 1588 }
1581 1589
1582 #if defined(FEAT_COMMENTS) || defined(PROTO) 1590 #if defined(FEAT_COMMENTS) || defined(PROTO)
1583 /* 1591 /*
1584 * get_leader_len() returns the length of the prefix of the given string 1592 * get_leader_len() returns the length in bytes of the prefix of the given
1585 * which introduces a comment. If this string is not a comment then 0 is 1593 * string which introduces a comment. If this string is not a comment then
1586 * returned. 1594 * 0 is returned.
1587 * When "flags" is not NULL, it is set to point to the flags of the recognized 1595 * When "flags" is not NULL, it is set to point to the flags of the recognized
1588 * comment leader. 1596 * comment leader.
1589 * "backward" must be true for the "O" command. 1597 * "backward" must be true for the "O" command.
1590 * If "include_space" is set, include trailing whitespace while calculating the 1598 * If "include_space" is set, include trailing whitespace while calculating the
1591 * length. 1599 * length.