On Mo, 30 Apr 2018, Bram Moolenaar wrote:
> It also adds bd.textlen next. Maybe that also goes over the end of the
> line? How about this:
>
> firstline = ml_get(oap->start.lnum) + bd.textcol;
> len = STRLEN(firstline);
> add = bd.textcol;
> if (oap->op_type == OP_APPEND)
> add += bd.textlen;
> if ((size_t)add > len)
> firstline += len; // short line, point to the NUL
> else
> firstline += add;
>
> We should also have a test for this.
How about the attached patch? It includes a test and should fail with
the current behaviour. I struggled a bit to reproduce the issue with an
automatic test, but I think I finally got a version that works.
Best,
Christian
--
Der Mensch kann nicht leben ohne das sittlich Große, ja, wenn es ihm
entzogen wird, verlangt er danach mit heftigerem Hunger als nach jedem
anderen Ding dieser Erde.
-- Adalbert Stifter
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.
From 86b37d84cfafdd144443a0b9cebd50797472f85b Mon Sep 17 00:00:00 2001
From: Christian Brabandt <[email protected]>
Date: Mon, 30 Apr 2018 14:34:25 +0200
Subject: [PATCH] Fix #2825
---
src/ops.c | 16 ++++++++++++++--
src/testdir/test_blockedit.vim | 13 +++++++++++++
2 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/src/ops.c b/src/ops.c
index c59e39a4a..c9cff3b10 100644
--- a/src/ops.c
+++ b/src/ops.c
@@ -2703,6 +2703,7 @@ op_insert(oparg_T *oap, long count1)
{
struct block_def bd2;
int did_indent = FALSE;
+ int len;
/* If indent kicked in, the firstline might have changed
* but only do that, if the indent actually increased. */
@@ -2781,9 +2782,20 @@ op_insert(oparg_T *oap, long count1)
* Subsequent calls to ml_get() flush the firstline data - take a
* copy of the required string.
*/
- firstline = ml_get(oap->start.lnum) + bd.textcol;
+ firstline = ml_get(oap->start.lnum);
+ len = STRLEN(firstline);
+
+ if ((colnr_T)len < bd.textcol)
+ bd.textcol = (colnr_T)len;
+ firstline +=bd.textcol;
+
if (oap->op_type == OP_APPEND)
- firstline += bd.textlen;
+ {
+ if (bd.textcol + bd.textlen <= len)
+ firstline += bd.textlen;
+ else
+ firstline += (len - bd.textcol);
+ }
if (pre_textlen >= 0
&& (ins_len = (long)STRLEN(firstline) - pre_textlen) > 0)
{
diff --git a/src/testdir/test_blockedit.vim b/src/testdir/test_blockedit.vim
index 4a8d59952..16b9ff02d 100644
--- a/src/testdir/test_blockedit.vim
+++ b/src/testdir/test_blockedit.vim
@@ -16,5 +16,18 @@ func Test_blockinsert_indent()
bwipe!
endfunc
+func Test_blockinsert_delete()
+ new
+ let _bs=&bs
+ set bs=2
+ call setline(1, ['case Arg is ', ' when Name_Async,', ' when Name_Num_Gangs,', 'end if;'])
+ exe "norm! ggjVj\<c-v>$o$A\<bs>\<esc>"
+ "call feedkeys("Vj\<c-v>$o$A\<bs>\<esc>", 'ti')
+ call assert_equal(["case Arg is ", " when Name_Async", " when Name_Num_Gangs,", "end if;"],
+ \ getline(1,'$'))
+ " reset to sane state
+ let &bs=_bs
+ bwipe!
+endfunc
" vim: shiftwidth=2 sts=2 expandtab
--
2.17.0