vim-patch:9.1.1758: Diff mode crashes when adding text property in autocommand (#35760)

Problem:  Diff mode crashes when adding text property in autocommand
          (after 9.1.1557).
Solution: Only restore ML_EMPTY memline flag, ignore the others
          (zeertzjq).

fixes: vim/vim#18288
closes: vim/vim#18291

46e22fd2f7
This commit is contained in:
zeertzjq
2025-09-15 07:17:37 +08:00
committed by GitHub
parent fbb1caf5f8
commit 7b8b9d270f
2 changed files with 26 additions and 1 deletions

View File

@@ -874,7 +874,7 @@ static int diff_write(buf_T *buf, diffin_T *din, linenr_T start, linenr_T end)
cmdmod.cmod_flags = save_cmod_flags; cmdmod.cmod_flags = save_cmod_flags;
free_string_option(buf->b_p_ff); free_string_option(buf->b_p_ff);
buf->b_p_ff = save_ff; buf->b_p_ff = save_ff;
buf->b_ml.ml_flags = save_ml_flags; buf->b_ml.ml_flags = (buf->b_ml.ml_flags & ~ML_EMPTY) | (save_ml_flags & ML_EMPTY);
return r; return r;
} }

View File

@@ -3286,4 +3286,29 @@ func Test_diffget_diffput_diffanchors()
%bw! %bw!
set diffopt& set diffopt&
set diffanchors&
endfunc
func Test_diff_add_prop_in_autocmd()
CheckScreendump
let lines =<< trim END
func MyDiff() abort
let f1 = readfile(v:fname_in)
let f2 = readfile(v:fname_new)
let f0 = diff(f1, f2)
call writefile(split(f0, "\n"), v:fname_out)
endfunc
call prop_type_add('myprop', #{highlight: 'Search', override: 1})
autocmd OptionSet diff call prop_add(1, 1, #{type: 'myprop', length: 100})
set diffexpr=MyDiff()
END
call writefile(lines, 'Xtest_diff_add_prop_in_autocmd', 'D')
call writefile(['foo', 'bar', 'baz'], 'Xdiffsplit_file', 'D')
let buf = RunVimInTerminal('-S Xtest_diff_add_prop_in_autocmd', {})
call term_sendkeys(buf, ":diffsplit Xdiffsplit_file\<CR>")
call VerifyScreenDump(buf, 'Test_diff_add_prop_in_autocmd_01', {})
call StopVimInTerminal(buf) call StopVimInTerminal(buf)