Skip to content

Commit ac15fd8

Browse files
committed
patch 8.2.0109: corrupted text properties when expanding spaces
Problem: Corrupted text properties when expanding spaces. Solution: Reallocate the line. (Nobuhiro Takasaki, closes #5457)
1 parent bf0acff commit ac15fd8

3 files changed

Lines changed: 86 additions & 13 deletions

File tree

src/edit.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5604,9 +5604,25 @@ ins_tab(void)
56045604
#ifdef FEAT_PROP_POPUP
56055605
if (!(State & VREPLACE_FLAG))
56065606
{
5607-
mch_memmove(ptr, ptr + i, curbuf->b_ml.ml_line_len - i
5608-
- (ptr - curbuf->b_ml.ml_line_ptr));
5607+
char_u *newp;
5608+
int col;
5609+
5610+
newp = alloc(curbuf->b_ml.ml_line_len - i);
5611+
if (newp == NULL)
5612+
return FALSE;
5613+
5614+
col = ptr - curbuf->b_ml.ml_line_ptr;
5615+
if (col > 0)
5616+
mch_memmove(newp, ptr - col, col);
5617+
mch_memmove(newp + col, ptr + i,
5618+
curbuf->b_ml.ml_line_len - col - i);
5619+
5620+
if (curbuf->b_ml.ml_flags & ML_LINE_DIRTY)
5621+
vim_free(curbuf->b_ml.ml_line_ptr);
5622+
curbuf->b_ml.ml_line_ptr = newp;
56095623
curbuf->b_ml.ml_line_len -= i;
5624+
curbuf->b_ml.ml_flags =
5625+
(curbuf->b_ml.ml_flags | ML_LINE_DIRTY) & ~ML_EMPTY;
56105626
}
56115627
else
56125628
#endif

src/testdir/test_textprop.vim

Lines changed: 66 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -926,19 +926,32 @@ func Test_proptype_substitute2()
926926
bwipe!
927927
endfunc
928928

929+
func SaveOptions()
930+
let d = #{tabstop: &tabstop,
931+
\ softtabstop: &softtabstop,
932+
\ shiftwidth: &shiftwidth,
933+
\ expandtab: &expandtab,
934+
\ foldmethod: '"' .. &foldmethod .. '"',
935+
\ }
936+
return d
937+
endfunc
938+
939+
func RestoreOptions(dict)
940+
for name in keys(a:dict)
941+
exe 'let &' .. name .. ' = ' .. a:dict[name]
942+
endfor
943+
endfunc
944+
929945
func Test_textprop_noexpandtab()
930-
%bwipe!
931946
new
932-
let save_ts = &tabstop
947+
let save_dict = SaveOptions()
948+
933949
set tabstop=8
934-
let save_sts = &softtabstop
935950
set softtabstop=4
936-
let save_sw = &shiftwidth
937951
set shiftwidth=4
938-
let save_et = &expandtab
939952
set noexpandtab
940-
let save_fdm = &foldmethod
941953
set foldmethod=marker
954+
942955
call feedkeys("\<esc>\<esc>0Ca\<cr>\<esc>\<up>", "tx")
943956
call prop_type_add('test', {'highlight': 'ErrorMsg'})
944957
call prop_add(1, 1, {'end_col': 2, 'type': 'test'})
@@ -955,9 +968,51 @@ func Test_textprop_noexpandtab()
955968
catch /^Vim\%((\a\+)\)\=:E964/
956969
endtry
957970
call prop_remove({'type': 'test'})
958-
let &foldmethod = save_fdm
959-
let &expandtab = save_et
960-
let &shiftwidth = save_sw
961-
let &softtabstop = save_sts
962-
let &tabstop = save_ts
971+
call prop_type_delete('test')
972+
973+
call RestoreOptions(save_dict)
974+
bwipe!
975+
endfunc
976+
977+
func Test_textprop_noexpandtab_redraw()
978+
new
979+
let save_dict = SaveOptions()
980+
981+
set tabstop=8
982+
set softtabstop=4
983+
set shiftwidth=4
984+
set noexpandtab
985+
set foldmethod=marker
986+
987+
call feedkeys("\<esc>\<esc>0Ca\<cr>\<space>\<esc>\<up>", "tx")
988+
call prop_type_add('test', {'highlight': 'ErrorMsg'})
989+
call prop_add(1, 1, {'end_col': 2, 'type': 'test'})
990+
call feedkeys("0i\<tab>", "tx")
991+
" Internally broken at the next line
992+
call feedkeys("A\<left>\<tab>", "tx")
993+
redraw
994+
" Index calculation failed internally on next line
995+
call prop_add(1, 1, {'end_col': 2, 'type': 'test'})
996+
call prop_remove({'type': 'test', 'all': v:true})
997+
call prop_type_delete('test')
998+
call prop_type_delete('test')
999+
1000+
call RestoreOptions(save_dict)
1001+
bwipe!
1002+
endfunc
1003+
1004+
func Test_textprop_ins_str()
1005+
new
1006+
call setline(1, 'just some text')
1007+
call prop_type_add('test', {'highlight': 'ErrorMsg'})
1008+
call prop_add(1, 1, {'end_col': 2, 'type': 'test'})
1009+
call assert_equal([{'id': 0, 'col': 1, 'end': 1, 'type': 'test', 'length': 1, 'start': 1}], prop_list(1))
1010+
1011+
call feedkeys("foi\<F8>\<Esc>", "tx")
1012+
call assert_equal('just s<F8>ome text', getline(1))
1013+
call assert_equal([{'id': 0, 'col': 1, 'end': 1, 'type': 'test', 'length': 1, 'start': 1}], prop_list(1))
1014+
1015+
bwipe!
1016+
call prop_remove({'type': 'test'})
1017+
call prop_type_delete('test')
9631018
endfunc

src/version.c

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

743743
static int included_patches[] =
744744
{ /* Add new patch number below this line */
745+
/**/
746+
109,
745747
/**/
746748
108,
747749
/**/

0 commit comments

Comments
 (0)