Skip to content

Commit 30dff84

Browse files
committed
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.
1 parent f18be56 commit 30dff84

File tree

5 files changed

+56
-9
lines changed

5 files changed

+56
-9
lines changed

src/misc1.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,18 @@ set_indent(size, flags)
303303
ml_replace(curwin->w_cursor.lnum, newline, FALSE);
304304
if (flags & SIN_CHANGED)
305305
changed_bytes(curwin->w_cursor.lnum, 0);
306-
/* Correct saved cursor position if it's after the indent. */
307-
if (saved_cursor.lnum == curwin->w_cursor.lnum
308-
&& saved_cursor.col >= (colnr_T)(p - oldline))
309-
saved_cursor.col += ind_len - (colnr_T)(p - oldline);
306+
/* Correct saved cursor position if it is in this line. */
307+
if (saved_cursor.lnum == curwin->w_cursor.lnum)
308+
{
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+
}
310318
retval = TRUE;
311319
}
312320
else
@@ -1581,9 +1589,9 @@ open_line(dir, flags, second_line_indent)
15811589

15821590
#if defined(FEAT_COMMENTS) || defined(PROTO)
15831591
/*
1584-
* get_leader_len() returns the length of the prefix of the given string
1585-
* which introduces a comment. If this string is not a comment then 0 is
1586-
* returned.
1592+
* get_leader_len() returns the length in bytes of the prefix of the given
1593+
* string which introduces a comment. If this string is not a comment then
1594+
* 0 is returned.
15871595
* When "flags" is not NULL, it is set to point to the flags of the recognized
15881596
* comment leader.
15891597
* "backward" must be true for the "O" command.

src/ops.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4989,7 +4989,7 @@ format_lines(line_count, avoid_fex)
49894989

49904990
/*
49914991
* When still in same paragraph, join the lines together. But
4992-
* first delete the comment leader from the second line.
4992+
* first delete the leader from the second line.
49934993
*/
49944994
if (!is_end_par)
49954995
{
@@ -4999,11 +4999,25 @@ format_lines(line_count, avoid_fex)
49994999
if (line_count < 0 && u_save_cursor() == FAIL)
50005000
break;
50015001
#ifdef FEAT_COMMENTS
5002-
(void)del_bytes((long)next_leader_len, FALSE, FALSE);
50035002
if (next_leader_len > 0)
5003+
{
5004+
(void)del_bytes((long)next_leader_len, FALSE, FALSE);
50045005
mark_col_adjust(curwin->w_cursor.lnum, (colnr_T)0, 0L,
50055006
(long)-next_leader_len);
5007+
} else
50065008
#endif
5009+
if (second_indent > 0) /* the "leader" for FO_Q_SECOND */
5010+
{
5011+
char_u *p = ml_get_curline();
5012+
int indent = skipwhite(p) - p;
5013+
5014+
if (indent > 0)
5015+
{
5016+
(void)del_bytes(indent, FALSE, FALSE);
5017+
mark_col_adjust(curwin->w_cursor.lnum,
5018+
(colnr_T)0, 0L, (long)-indent);
5019+
}
5020+
}
50075021
curwin->w_cursor.lnum--;
50085022
if (do_join(2, TRUE, FALSE, FALSE) == FAIL)
50095023
{

src/testdir/test68.in

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,20 @@ ENDTEST
6161
# 1 a
6262
}
6363

64+
STARTTEST
65+
/^{/+3
66+
:set tw=5 fo=t2a si
67+
i A_
68+
ENDTEST
69+
70+
{
71+
72+
x a
73+
b
74+
c
75+
76+
}
77+
6478
STARTTEST
6579
/^{/+1
6680
:set tw=5 fo=qn comments=:#

src/testdir/test68.ok

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ a b
4242
}
4343

4444

45+
{
46+
47+
x a
48+
b_
49+
c
50+
51+
}
52+
53+
4554
{
4655
# 1 a
4756
# b

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,8 @@ static char *(features[]) =
738738

739739
static int included_patches[] =
740740
{ /* Add new patch number below this line */
741+
/**/
742+
52,
741743
/**/
742744
51,
743745
/**/

0 commit comments

Comments
 (0)