diff options
author | Bram Moolenaar <Bram@vim.org> | 2019-05-17 22:57:26 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2019-05-17 22:57:26 +0200 |
commit | 8055d17388736421d875dd4933c4c93d49a2ab58 (patch) | |
tree | 81ebca77b3ed10b02f42f8513c29b838ac7952fb /src | |
parent | 787880a86dbcb79cdf6e8241b1d99ac4a7acbc09 (diff) |
patch 8.1.1343: text properties not adjusted for Visual block mode deletev8.1.1343
Problem: Text properties not adjusted for Visual block mode delete.
Solution: Call adjust_prop_columns(). (closes #4384)
Diffstat (limited to 'src')
-rw-r--r-- | src/misc1.c | 11 | ||||
-rw-r--r-- | src/ops.c | 12 | ||||
-rw-r--r-- | src/testdir/dumps/Test_textprop_vis_01.dump | 12 | ||||
-rw-r--r-- | src/testdir/dumps/Test_textprop_vis_02.dump | 12 | ||||
-rw-r--r-- | src/testdir/test_textprop.vim | 51 | ||||
-rw-r--r-- | src/textprop.c | 19 | ||||
-rw-r--r-- | src/version.c | 2 |
7 files changed, 109 insertions, 10 deletions
diff --git a/src/misc1.c b/src/misc1.c index 5dcf268481..f83e807954 100644 --- a/src/misc1.c +++ b/src/misc1.c @@ -434,8 +434,15 @@ set_indent( saved_cursor.col = (colnr_T)(s - newline); } #ifdef FEAT_TEXT_PROP - adjust_prop_columns(curwin->w_cursor.lnum, (colnr_T)(p - oldline), - ind_len - (colnr_T)(p - oldline)); + { + int added = ind_len - (colnr_T)(p - oldline); + + // When increasing indent this behaves like spaces were inserted at + // the old indent, when decreasing indent it behaves like spaces + // were deleted at the new indent. + adjust_prop_columns(curwin->w_cursor.lnum, + (colnr_T)(added > 0 ? (p - oldline) : ind_len), added); + } #endif retval = TRUE; } @@ -1916,10 +1916,9 @@ op_delete(oparg_T *oap) curwin->w_cursor.coladd = 0; } - /* n == number of chars deleted - * If we delete a TAB, it may be replaced by several characters. - * Thus the number of characters may increase! - */ + // "n" == number of chars deleted + // If we delete a TAB, it may be replaced by several characters. + // Thus the number of characters may increase! n = bd.textlen - bd.startspaces - bd.endspaces; oldp = ml_get(lnum); newp = alloc_check((unsigned)STRLEN(oldp) + 1 - n); @@ -1935,6 +1934,11 @@ op_delete(oparg_T *oap) STRMOVE(newp + bd.textcol + bd.startspaces + bd.endspaces, oldp); /* replace the line */ ml_replace(lnum, newp, FALSE); + +#ifdef FEAT_TEXT_PROP + if (curbuf->b_has_textprop && n != 0) + adjust_prop_columns(lnum, bd.textcol, -n); +#endif } check_cursor_col(); diff --git a/src/testdir/dumps/Test_textprop_vis_01.dump b/src/testdir/dumps/Test_textprop_vis_01.dump new file mode 100644 index 0000000000..f411d304bc --- /dev/null +++ b/src/testdir/dumps/Test_textprop_vis_01.dump @@ -0,0 +1,12 @@ +|x+0&#ffffff0@4>x@1| |1+0&#ffff4012|2|3| +0&#ffffff0|x| @61 +|x@5| |1+0&#ffff4012|2|3| +0&#ffffff0|x| @62 +|x@4| |1+0&#ffff4012|2|3| +0&#ffffff0|x| @63 +|x@4|1+0&#ffff4012|2|3| +0&#ffffff0|x| @64 +|x@4|2+0&#ffff4012|3| +0&#ffffff0|x| @65 +|x@3| |3+0&#ffff4012| +0&#ffffff0|x@1| @65 +|x@2| |1+0&#ffff4012| +0&#ffffff0|x@2| @65 +|x@1| |1+0&#ffff4012|2|x+0&#ffffff0@3| @65 +|x| |1+0&#ffff4012|2|3|x+0&#ffffff0@3| @65 +@1|1+0&#ffff4012|2|3| +0&#ffffff0|x@3| @65 +|~+0#4040ff13&| @73 +| +0#0000000&@56|1|,|6| @10|A|l@1| diff --git a/src/testdir/dumps/Test_textprop_vis_02.dump b/src/testdir/dumps/Test_textprop_vis_02.dump new file mode 100644 index 0000000000..d999ae1d69 --- /dev/null +++ b/src/testdir/dumps/Test_textprop_vis_02.dump @@ -0,0 +1,12 @@ +|x+0&#ffffff0@4> |1+0&#ffff4012|2|3| +0&#ffffff0|x| @63 +|x@4|1+0&#ffff4012|2|3| +0&#ffffff0|x| @64 +|x@4|2+0&#ffff4012|3| +0&#ffffff0|x| @65 +|x@4|3+0&#ffff4012| +0&#ffffff0|x| @66 +|x@4| |x| @67 +|x@3| |x@1| @67 +|x@2| |1+0&#ffff4012|x+0&#ffffff0@1| @67 +|x@1| |1+0&#ffff4012|2|x+0&#ffffff0@1| @67 +|x| |1+0&#ffff4012|2|3|x+0&#ffffff0@1| @67 +@1|1+0&#ffff4012|2|3| +0&#ffffff0|x@1| @67 +|~+0#4040ff13&| @73 +| +0#0000000&@56|1|,|6| @10|A|l@1| diff --git a/src/testdir/test_textprop.vim b/src/testdir/test_textprop.vim index 635902c7e9..d1897a236e 100644 --- a/src/testdir/test_textprop.vim +++ b/src/testdir/test_textprop.vim @@ -613,7 +613,7 @@ func Test_prop_undo() endfunc " screenshot test with textprop highlighting -funct Test_textprop_screenshots() +func Test_textprop_screenshot_various() " The Vim running in the terminal needs to use utf-8. if !CanRunVimInTerminal() || g:orig_encoding != 'utf-8' return @@ -671,3 +671,52 @@ funct Test_textprop_screenshots() call StopVimInTerminal(buf) call delete('XtestProp') endfunc + +func RunTestVisualBlock(width, dump) + call writefile([ + \ "call setline(1, [" + \ .. "'xxxxxxxxx 123 x'," + \ .. "'xxxxxxxx 123 x'," + \ .. "'xxxxxxx 123 x'," + \ .. "'xxxxxx 123 x'," + \ .. "'xxxxx 123 x'," + \ .. "'xxxx 123 xx'," + \ .. "'xxx 123 xxx'," + \ .. "'xx 123 xxxx'," + \ .. "'x 123 xxxxx'," + \ .. "' 123 xxxxxx'," + \ .. "])", + \ "hi SearchProp ctermbg=yellow", + \ "call prop_type_add('search', {'highlight': 'SearchProp'})", + \ "call prop_add(1, 11, {'length': 3, 'type': 'search'})", + \ "call prop_add(2, 10, {'length': 3, 'type': 'search'})", + \ "call prop_add(3, 9, {'length': 3, 'type': 'search'})", + \ "call prop_add(4, 8, {'length': 3, 'type': 'search'})", + \ "call prop_add(5, 7, {'length': 3, 'type': 'search'})", + \ "call prop_add(6, 6, {'length': 3, 'type': 'search'})", + \ "call prop_add(7, 5, {'length': 3, 'type': 'search'})", + \ "call prop_add(8, 4, {'length': 3, 'type': 'search'})", + \ "call prop_add(9, 3, {'length': 3, 'type': 'search'})", + \ "call prop_add(10, 2, {'length': 3, 'type': 'search'})", + \ "normal 1G6|\<C-V>" .. repeat('l', a:width - 1) .. "10jx", + \], 'XtestPropVis') + let buf = RunVimInTerminal('-S XtestPropVis', {'rows': 12}) + call VerifyScreenDump(buf, 'Test_textprop_vis_' .. a:dump, {}) + + " clean up + call StopVimInTerminal(buf) + call delete('XtestPropVis') +endfunc + +" screenshot test with Visual block mode operations +func Test_textprop_screenshot_visual() + if !CanRunVimInTerminal() + return + endif + + " Delete two columns while text props are three chars wide. + call RunTestVisualBlock(2, '01') + + " Same, but delete four columns + call RunTestVisualBlock(4, '02') +endfunc diff --git a/src/textprop.c b/src/textprop.c index 8c86d01433..94b4d6b82b 100644 --- a/src/textprop.c +++ b/src/textprop.c @@ -957,7 +957,7 @@ clear_buf_prop_types(buf_T *buf) * shift by "bytes_added" (can be negative). * Note that "col" is zero-based, while tp_col is one-based. * Only for the current buffer. - * Called is expected to check b_has_textprop and "bytes_added" being non-zero. + * Caller is expected to check b_has_textprop and "bytes_added" being non-zero. */ void adjust_prop_columns( @@ -994,15 +994,28 @@ adjust_prop_columns( ? 2 : 1)) : (tmp_prop.tp_col > col + 1)) { - tmp_prop.tp_col += bytes_added; + if (tmp_prop.tp_col + bytes_added < col + 1) + { + tmp_prop.tp_len += (tmp_prop.tp_col - 1 - col) + bytes_added; + tmp_prop.tp_col = col + 1; + } + else + tmp_prop.tp_col += bytes_added; dirty = TRUE; + if (tmp_prop.tp_len <= 0) + continue; // drop this text property } else if (tmp_prop.tp_len > 0 && tmp_prop.tp_col + tmp_prop.tp_len > col + ((pt != NULL && (pt->pt_flags & PT_FLAG_INS_END_INCL)) ? 0 : 1)) { - tmp_prop.tp_len += bytes_added; + int after = col - bytes_added + - (tmp_prop.tp_col - 1 + tmp_prop.tp_len); + if (after > 0) + tmp_prop.tp_len += bytes_added + after; + else + tmp_prop.tp_len += bytes_added; dirty = TRUE; if (tmp_prop.tp_len <= 0) continue; // drop this text property diff --git a/src/version.c b/src/version.c index 07db364bf3..f32cd286f7 100644 --- a/src/version.c +++ b/src/version.c @@ -768,6 +768,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1343, +/**/ 1342, /**/ 1341, |