mirror of
https://github.com/neovim/neovim.git
synced 2025-10-05 17:36:29 +00:00
vim-patch:8.2.3925: diff mode confused by NUL bytes (#18033)
Problem: Diff mode confused by NUL bytes.
Solution: Handle NUL bytes differently. (Christian Brabandt, closes vim/vim#9421,
closes vim/vim#9418)
06f6095623
This commit is contained in:
@@ -743,11 +743,16 @@ static int diff_write_buffer(buf_T *buf, diffin_T *din)
|
||||
for (linenr_T lnum = 1; lnum <= buf->b_ml.ml_line_count; lnum++) {
|
||||
for (char_u *s = ml_get_buf(buf, lnum, false); *s != NUL;) {
|
||||
if (diff_flags & DIFF_ICASE) {
|
||||
int c;
|
||||
char_u cbuf[MB_MAXBYTES + 1];
|
||||
|
||||
// xdiff doesn't support ignoring case, fold-case the text.
|
||||
int c = utf_ptr2char(s);
|
||||
c = utf_fold(c);
|
||||
if (*s == NL) {
|
||||
c = NUL;
|
||||
} else {
|
||||
// xdiff doesn't support ignoring case, fold-case the text.
|
||||
c = utf_ptr2char(s);
|
||||
c = utf_fold(c);
|
||||
}
|
||||
const int orig_len = utfc_ptr2len(s);
|
||||
if (utf_char2bytes(c, cbuf) != orig_len) {
|
||||
// TODO(Bram): handle byte length difference
|
||||
@@ -759,7 +764,8 @@ static int diff_write_buffer(buf_T *buf, diffin_T *din)
|
||||
s += orig_len;
|
||||
len += orig_len;
|
||||
} else {
|
||||
ptr[len++] = *s++;
|
||||
ptr[len++] = *s == NL ? NUL : *s;
|
||||
s++;
|
||||
}
|
||||
}
|
||||
ptr[len++] = NL;
|
||||
|
@@ -1295,4 +1295,41 @@ func Test_diff_filler_cursorcolumn()
|
||||
endfunc
|
||||
|
||||
|
||||
func Test_diff_binary()
|
||||
CheckScreendump
|
||||
|
||||
let content =<< trim END
|
||||
call setline(1, ['a', 'b', "c\n", 'd', 'e', 'f', 'g'])
|
||||
vnew
|
||||
call setline(1, ['A', 'b', 'c', 'd', 'E', 'f', 'g'])
|
||||
windo diffthis
|
||||
wincmd p
|
||||
norm! gg0
|
||||
redraw!
|
||||
END
|
||||
call writefile(content, 'Xtest_diff_bin')
|
||||
let buf = RunVimInTerminal('-S Xtest_diff_bin', {})
|
||||
|
||||
" Test using internal diff
|
||||
call VerifyScreenDump(buf, 'Test_diff_bin_01', {})
|
||||
|
||||
" Test using internal diff and case folding
|
||||
call term_sendkeys(buf, ":set diffopt+=icase\<cr>")
|
||||
call term_sendkeys(buf, "\<C-l>")
|
||||
call VerifyScreenDump(buf, 'Test_diff_bin_02', {})
|
||||
" Test using external diff
|
||||
call term_sendkeys(buf, ":set diffopt=filler\<cr>")
|
||||
call term_sendkeys(buf, "\<C-l>")
|
||||
call VerifyScreenDump(buf, 'Test_diff_bin_03', {})
|
||||
" Test using external diff and case folding
|
||||
call term_sendkeys(buf, ":set diffopt=filler,icase\<cr>")
|
||||
call term_sendkeys(buf, "\<C-l>")
|
||||
call VerifyScreenDump(buf, 'Test_diff_bin_04', {})
|
||||
|
||||
" clean up
|
||||
call StopVimInTerminal(buf)
|
||||
call delete('Xtest_diff_bin')
|
||||
set diffopt&vim
|
||||
endfunc
|
||||
|
||||
" vim: shiftwidth=2 sts=2 expandtab
|
||||
|
Reference in New Issue
Block a user