mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-patch:8.2.4120: block insert goes over the end of the line
Problem: Block insert goes over the end of the line.
Solution: Handle invalid byte better. Fix inserting the wrong text.
9f8c304c8a
This commit is contained in:
parent
f8b75e5822
commit
e662d86e8d
@ -573,19 +573,24 @@ static void block_insert(oparg_T *oap, char_u *s, int b_insert, struct block_def
|
||||
// Avoid starting halfway through a multi-byte character.
|
||||
if (b_insert) {
|
||||
off = utf_head_off(oldp, oldp + offset + spaces);
|
||||
} else {
|
||||
off = mb_off_next(oldp, oldp + offset);
|
||||
offset += off;
|
||||
}
|
||||
spaces -= off;
|
||||
count -= off;
|
||||
} else {
|
||||
// spaces fill the gap, the character that's at the edge moves
|
||||
// right
|
||||
off = utf_head_off(oldp, oldp + offset);
|
||||
offset -= off;
|
||||
}
|
||||
}
|
||||
if (spaces < 0) { // can happen when the cursor was moved
|
||||
spaces = 0;
|
||||
}
|
||||
|
||||
assert(count >= 0);
|
||||
newp = (char_u *)xmalloc(STRLEN(oldp) + s_len + (size_t)count + 1);
|
||||
// Make sure the allocated size matches what is actually copied below.
|
||||
newp = xmalloc(STRLEN(oldp) + (size_t)spaces + s_len
|
||||
+ (spaces > 0 && !bdp->is_short ? (size_t)p_ts - (size_t)spaces : 0)
|
||||
+ (size_t)count + 1);
|
||||
|
||||
// copy up to shifted part
|
||||
memmove(newp, oldp, (size_t)offset);
|
||||
@ -600,7 +605,8 @@ static void block_insert(oparg_T *oap, char_u *s, int b_insert, struct block_def
|
||||
offset += (int)s_len;
|
||||
|
||||
int skipped = 0;
|
||||
if (spaces && !bdp->is_short) {
|
||||
if (spaces > 0 && !bdp->is_short) {
|
||||
if (*oldp == TAB) {
|
||||
// insert post-padding
|
||||
memset(newp + offset + spaces, ' ', (size_t)(p_ts - spaces));
|
||||
// We're splitting a TAB, don't copy it.
|
||||
@ -608,6 +614,10 @@ static void block_insert(oparg_T *oap, char_u *s, int b_insert, struct block_def
|
||||
// We allowed for that TAB, remember this now
|
||||
count++;
|
||||
skipped = 1;
|
||||
} else {
|
||||
// Not a TAB, no extra spaces
|
||||
count = spaces;
|
||||
}
|
||||
}
|
||||
|
||||
if (spaces > 0) {
|
||||
@ -2329,7 +2339,7 @@ void op_insert(oparg_T *oap, long count1)
|
||||
pre_textlen -= t - oap->start_vcol;
|
||||
oap->start_vcol = t;
|
||||
} else if (oap->op_type == OP_APPEND
|
||||
&& oap->end.col + oap->end.coladd
|
||||
&& oap->start.col + oap->start.coladd
|
||||
>= curbuf->b_op_start_orig.col
|
||||
+ curbuf->b_op_start_orig.coladd) {
|
||||
oap->start.col = curbuf->b_op_start_orig.col;
|
||||
|
@ -1242,6 +1242,15 @@ func Test_visual_block_ctrl_w_f()
|
||||
au! BufNew
|
||||
endfunc
|
||||
|
||||
func Test_visual_block_append_invalid_char()
|
||||
" this was going over the end of the line
|
||||
new
|
||||
call setline(1, [' let xxx', 'xxxxx', 'xxxxxxxxxxx'])
|
||||
exe "normal 0\<C-V>jjA-\<Esc>"
|
||||
call assert_equal([' - let xxx', 'xxxxx -', 'xxxxxxxx-xxx'], getline(1, 3))
|
||||
bwipe!
|
||||
endfunc
|
||||
|
||||
func Test_visual_reselect_with_count()
|
||||
" this was causing an illegal memory access
|
||||
let lines =<< trim END
|
||||
|
Loading…
Reference in New Issue
Block a user