1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
To: vim_dev@googlegroups.com
Subject: Patch 8.1.0125
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
------------
Patch 8.1.0125
Problem: Virtual edit replace with multi-byte fails at end of line. (Lukas
Werling)
Solution: use ins_char() to add the character. (Christian Brabandt,
closes #3114) Rename PCHAR() to PBYTE() to avoid mistakes like
this.
Files: src/ops.c, src/testdir/test_virtualedit.vim, src/macros.h
*** ../vim-8.1.0124/src/ops.c 2018-06-27 20:49:40.567862384 +0200
--- src/ops.c 2018-06-28 19:20:39.671555865 +0200
***************
*** 2146,2151 ****
--- 2146,2170 ----
#endif
#if defined(FEAT_VISUALEXTRA) || defined(PROTO)
+
+ # ifdef FEAT_MBYTE
+ /*
+ * Replace the character under the cursor with "c".
+ * This takes care of multi-byte characters.
+ */
+ static void
+ replace_character(int c)
+ {
+ int n = State;
+
+ State = REPLACE;
+ ins_char(c);
+ State = n;
+ /* Backup to the replaced character. */
+ dec_cursor();
+ }
+
+ # endif
/*
* Replace a whole area with one character.
*/
***************
*** 2331,2342 ****
* with a multi-byte and the other way around. */
if (curwin->w_cursor.lnum == oap->end.lnum)
oap->end.col += (*mb_char2len)(c) - (*mb_char2len)(n);
! n = State;
! State = REPLACE;
! ins_char(c);
! State = n;
! /* Backup to the replaced character. */
! dec_cursor();
}
else
#endif
--- 2350,2356 ----
* with a multi-byte and the other way around. */
if (curwin->w_cursor.lnum == oap->end.lnum)
oap->end.col += (*mb_char2len)(c) - (*mb_char2len)(n);
! replace_character(c);
}
else
#endif
***************
*** 2358,2364 ****
getvpos(&oap->end, end_vcol);
}
#endif
! PCHAR(curwin->w_cursor, c);
}
}
#ifdef FEAT_VIRTUALEDIT
--- 2372,2378 ----
getvpos(&oap->end, end_vcol);
}
#endif
! PBYTE(curwin->w_cursor, c);
}
}
#ifdef FEAT_VIRTUALEDIT
***************
*** 2377,2385 ****
curwin->w_cursor.col -= (virtcols + 1);
for (; virtcols >= 0; virtcols--)
{
! PCHAR(curwin->w_cursor, c);
! if (inc(&curwin->w_cursor) == -1)
! break;
}
}
#endif
--- 2391,2404 ----
curwin->w_cursor.col -= (virtcols + 1);
for (; virtcols >= 0; virtcols--)
{
! #ifdef FEAT_MBYTE
! if ((*mb_char2len)(c) > 1)
! replace_character(c);
! else
! #endif
! PBYTE(curwin->w_cursor, c);
! if (inc(&curwin->w_cursor) == -1)
! break;
}
}
#endif
***************
*** 2619,2625 ****
}
else
#endif
! PCHAR(*pos, nc);
return TRUE;
}
return FALSE;
--- 2638,2644 ----
}
else
#endif
! PBYTE(*pos, nc);
return TRUE;
}
return FALSE;
*** ../vim-8.1.0124/src/testdir/test_virtualedit.vim 2018-04-25 21:58:46.000000000 +0200
--- src/testdir/test_virtualedit.vim 2018-06-28 19:12:57.486074037 +0200
***************
*** 42,47 ****
--- 42,63 ----
set virtualedit=
endfunc
+ func Test_replace_end_of_line()
+ new
+ set virtualedit=all
+ call setline(1, range(20))
+ exe "normal! gg2jv10lr-"
+ call assert_equal(["1", "-----------", "3"], getline(2,4))
+ if has('multi_byte')
+ call setline(1, range(20))
+ exe "normal! gg2jv10lr\<c-k>hh"
+ call assert_equal(["1", "───────────", "3"], getline(2,4))
+ endif
+
+ bwipe!
+ set virtualedit=
+ endfunc
+
func Test_edit_CTRL_G()
new
set virtualedit=insert
*** ../vim-8.1.0124/src/macros.h 2018-04-10 18:37:19.000000000 +0200
--- src/macros.h 2018-06-28 19:15:50.801135759 +0200
***************
*** 14,22 ****
*/
/*
! * PCHAR(lp, c) - put character 'c' at position 'lp'
*/
! #define PCHAR(lp, c) (*(ml_get_buf(curbuf, (lp).lnum, TRUE) + (lp).col) = (c))
/*
* Position comparisons
--- 14,22 ----
*/
/*
! * PBYTE(lp, c) - put byte 'c' at position 'lp'
*/
! #define PBYTE(lp, c) (*(ml_get_buf(curbuf, (lp).lnum, TRUE) + (lp).col) = (c))
/*
* Position comparisons
*** ../vim-8.1.0124/src/version.c 2018-06-28 15:50:23.178568297 +0200
--- src/version.c 2018-06-28 19:11:53.922415636 +0200
***************
*** 791,792 ****
--- 791,794 ----
{ /* Add new patch number below this line */
+ /**/
+ 125,
/**/
--
The coffee just wasn't strong enough to defend itself -- Tom Waits
/// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
|