diff options
author | Bram Moolenaar <Bram@vim.org> | 2013-10-06 17:46:56 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2013-10-06 17:46:56 +0200 |
commit | 2c019c8696ca56d1a9d1bb10fd1411bad14df0c6 (patch) | |
tree | 43f484452ad6a18059a901cbf076fffd9b53e7bf /src/misc1.c | |
parent | a951e35478fd78d6d3cd970842502fb76c377df9 (diff) | |
download | vim-git-2c019c8696ca56d1a9d1bb10fd1411bad14df0c6.tar.gz |
updated for version 7.4.052v7.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.
Diffstat (limited to 'src/misc1.c')
-rw-r--r-- | src/misc1.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/src/misc1.c b/src/misc1.c index 0a2d83be0..2063d427e 100644 --- a/src/misc1.c +++ b/src/misc1.c @@ -303,10 +303,18 @@ set_indent(size, flags) ml_replace(curwin->w_cursor.lnum, newline, FALSE); if (flags & SIN_CHANGED) changed_bytes(curwin->w_cursor.lnum, 0); - /* Correct saved cursor position if it's after the indent. */ - if (saved_cursor.lnum == curwin->w_cursor.lnum - && saved_cursor.col >= (colnr_T)(p - oldline)) - saved_cursor.col += ind_len - (colnr_T)(p - oldline); + /* Correct saved cursor position if it is in this line. */ + if (saved_cursor.lnum == curwin->w_cursor.lnum) + { + if (saved_cursor.col >= (colnr_T)(p - oldline)) + /* cursor was after the indent, adjust for the number of + * bytes added/removed */ + saved_cursor.col += ind_len - (colnr_T)(p - oldline); + else if (saved_cursor.col >= (colnr_T)(s - newline)) + /* cursor was in the indent, and is now after it, put it back + * at the start of the indent (replacing spaces with TAB) */ + saved_cursor.col = (colnr_T)(s - newline); + } retval = TRUE; } else @@ -1581,9 +1589,9 @@ theend: #if defined(FEAT_COMMENTS) || defined(PROTO) /* - * get_leader_len() returns the length of the prefix of the given string - * which introduces a comment. If this string is not a comment then 0 is - * returned. + * get_leader_len() returns the length in bytes of the prefix of the given + * string which introduces a comment. If this string is not a comment then + * 0 is returned. * When "flags" is not NULL, it is set to point to the flags of the recognized * comment leader. * "backward" must be true for the "O" command. |