mirror of
https://github.com/airblade/vim-gitgutter.git
synced 2025-11-10 04:23:46 -05:00
Preserve '[ and '] marks, and &modified, during realtime diff.
See #242.
This commit is contained in:
@@ -30,7 +30,19 @@ function! gitgutter#diff#run_diff(realtime, use_external_grep)
|
|||||||
let buff_file .= '.'.extension
|
let buff_file .= '.'.extension
|
||||||
endif
|
endif
|
||||||
let cmd .= 'git show '.blob_name.' > '.blob_file.' && '
|
let cmd .= 'git show '.blob_name.' > '.blob_file.' && '
|
||||||
|
|
||||||
|
" Writing the whole buffer resets the '[ and '] marks and also the
|
||||||
|
" 'modified' flag (if &cpoptions includes '+'). These are unwanted
|
||||||
|
" side-effects so we save and restore the values ourselves.
|
||||||
|
let modified = getbufvar(bufnr, "&mod")
|
||||||
|
let op_mark_start = getpos("'[")
|
||||||
|
let op_mark_end = getpos("']")
|
||||||
|
|
||||||
execute 'keepalt silent write' buff_file
|
execute 'keepalt silent write' buff_file
|
||||||
|
|
||||||
|
call setbufvar(bufnr, "&mod", modified)
|
||||||
|
call setpos("'[", op_mark_start)
|
||||||
|
call setpos("']", op_mark_end)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let cmd .= 'git diff --no-ext-diff --no-color -U0 '.g:gitgutter_diff_args.' -- '
|
let cmd .= 'git diff --no-ext-diff --no-color -U0 '.g:gitgutter_diff_args.' -- '
|
||||||
|
|||||||
2
test/keepModified.expected
Normal file
2
test/keepModified.expected
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
modified: 1
|
||||||
|
modified: 1
|
||||||
4
test/keepOpMarks.expected
Normal file
4
test/keepOpMarks.expected
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
'[ mark: 0,6,1,0
|
||||||
|
'] mark: 0,6,2,0
|
||||||
|
'[ mark: 0,6,1,0
|
||||||
|
'] mark: 0,6,2,0
|
||||||
8
test/testKeepModified.vim
Normal file
8
test/testKeepModified.vim
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
source helper.vim
|
||||||
|
call Setup()
|
||||||
|
|
||||||
|
normal 5Go*
|
||||||
|
call Dump("modified: ".getbufvar('', '&modified'), 'keepModified')
|
||||||
|
doautocmd CursorHold
|
||||||
|
call Dump("modified: ".getbufvar('', '&modified'), 'keepModified')
|
||||||
|
|
||||||
10
test/testKeepOpMarks.vim
Normal file
10
test/testKeepOpMarks.vim
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
source helper.vim
|
||||||
|
call Setup()
|
||||||
|
|
||||||
|
normal 5Go*
|
||||||
|
call Dump("'[ mark: ".join(getpos("'["), ','), 'keepOpMarks')
|
||||||
|
call Dump("'] mark: ".join(getpos("']"), ','), 'keepOpMarks')
|
||||||
|
doautocmd CursorHold
|
||||||
|
call Dump("'[ mark: ".join(getpos("'["), ','), 'keepOpMarks')
|
||||||
|
call Dump("'] mark: ".join(getpos("']"), ','), 'keepOpMarks')
|
||||||
|
|
||||||
Reference in New Issue
Block a user