mirror of
https://github.com/tpope/vim-fugitive.git
synced 2025-11-12 21:33:53 -05:00
Refactor :Gstatus reload cursor positioning
This commit is contained in:
@@ -1759,7 +1759,7 @@ function! fugitive#reload_status() abort
|
|||||||
return fugitive#ReloadStatus()
|
return fugitive#ReloadStatus()
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:stage_info(lnum) abort
|
function! s:StageFileSection(lnum) abort
|
||||||
let filename = matchstr(getline(a:lnum),'^.\=\t\zs.\{-\}\ze\%( ([^()[:digit:]]\+)\)\=$')
|
let filename = matchstr(getline(a:lnum),'^.\=\t\zs.\{-\}\ze\%( ([^()[:digit:]]\+)\)\=$')
|
||||||
let lnum = a:lnum
|
let lnum = a:lnum
|
||||||
if has('multi_byte_encoding')
|
if has('multi_byte_encoding')
|
||||||
@@ -1805,18 +1805,21 @@ endfunction
|
|||||||
|
|
||||||
function! s:StageReloadSeek(target,lnum1,lnum2) abort
|
function! s:StageReloadSeek(target,lnum1,lnum2) abort
|
||||||
let jump = a:target
|
let jump = a:target
|
||||||
let f = matchstr(getline(a:lnum1-1),'^.\=\t\%([[:alpha:] ]\+: *\|.*\%uff1a *\)\=\zs.*')
|
let target = s:StageFileSection(a:lnum2 + 1)
|
||||||
if f !=# '' | let jump = f | endif
|
if empty(target[0])
|
||||||
let f = matchstr(getline(a:lnum2+1),'^.\=\t\%([[:alpha:] ]\+: *\|.*\%uff1a *\)\=\zs.*')
|
let target = s:StageFileSection(a:lnum1 - 1)
|
||||||
if f !=# '' | let jump = f | endif
|
endif
|
||||||
|
if empty(target[0])
|
||||||
|
let target = a:target
|
||||||
|
endif
|
||||||
silent! edit!
|
silent! edit!
|
||||||
1
|
1
|
||||||
redraw
|
redraw
|
||||||
call search('^.\=\t\%([[:alpha:] ]\+: *\|.*\%uff1a *\)\=\V'.jump.'\%( ([^()[:digit:]]\+)\)\=\$','W')
|
call search('^.\=\t\%([[:alpha:] ]\+: *\|.*\%uff1a *\)\=\V'.target[0].'\%( ([^()[:digit:]]\+)\)\=\$','W')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:StageUndo() abort
|
function! s:StageUndo() abort
|
||||||
let [filename, section] = s:stage_info(line('.'))
|
let [filename, section] = s:StageFileSection(line('.'))
|
||||||
if empty(filename)
|
if empty(filename)
|
||||||
return ''
|
return ''
|
||||||
endif
|
endif
|
||||||
@@ -1831,7 +1834,7 @@ function! s:StageUndo() abort
|
|||||||
else
|
else
|
||||||
call s:TreeChomp('checkout', 'HEAD^{}', './' . filename)
|
call s:TreeChomp('checkout', 'HEAD^{}', './' . filename)
|
||||||
endif
|
endif
|
||||||
call s:StageReloadSeek(filename, line('.'), line('.'))
|
call s:StageReloadSeek([filename, ''], line('.'), line('.'))
|
||||||
let @" = hash
|
let @" = hash
|
||||||
return 'checktime|redraw|echomsg ' .
|
return 'checktime|redraw|echomsg ' .
|
||||||
\ string('To restore, :Git cat-file blob '.hash[0:6].' > '.filename)
|
\ string('To restore, :Git cat-file blob '.hash[0:6].' > '.filename)
|
||||||
@@ -1839,7 +1842,7 @@ function! s:StageUndo() abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:StageDiff(diff) abort
|
function! s:StageDiff(diff) abort
|
||||||
let [filename, section] = s:stage_info(line('.'))
|
let [filename, section] = s:StageFileSection(line('.'))
|
||||||
if filename ==# '' && section ==# 'staged'
|
if filename ==# '' && section ==# 'staged'
|
||||||
return 'Git! diff --no-ext-diff --cached'
|
return 'Git! diff --no-ext-diff --cached'
|
||||||
elseif filename ==# ''
|
elseif filename ==# ''
|
||||||
@@ -1858,7 +1861,7 @@ function! s:StageDiff(diff) abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:StageDiffEdit() abort
|
function! s:StageDiffEdit() abort
|
||||||
let [filename, section] = s:stage_info(line('.'))
|
let [filename, section] = s:StageFileSection(line('.'))
|
||||||
let arg = (filename ==# '' ? '.' : filename)
|
let arg = (filename ==# '' ? '.' : filename)
|
||||||
if section ==# 'staged'
|
if section ==# 'staged'
|
||||||
return 'Git! diff --no-ext-diff --cached '.s:shellesc(arg)
|
return 'Git! diff --no-ext-diff --cached '.s:shellesc(arg)
|
||||||
@@ -1871,7 +1874,7 @@ function! s:StageDiffEdit() abort
|
|||||||
call search(':$','W')
|
call search(':$','W')
|
||||||
endif
|
endif
|
||||||
else
|
else
|
||||||
call s:StageReloadSeek(arg,line('.'),line('.'))
|
call s:StageReloadSeek([filename, 'staged'], line('.'), line('.'))
|
||||||
endif
|
endif
|
||||||
return ''
|
return ''
|
||||||
else
|
else
|
||||||
@@ -1886,7 +1889,7 @@ function! s:StageToggle(lnum1,lnum2) abort
|
|||||||
try
|
try
|
||||||
let output = ''
|
let output = ''
|
||||||
for lnum in range(a:lnum1,a:lnum2)
|
for lnum in range(a:lnum1,a:lnum2)
|
||||||
let [filename, section] = s:stage_info(lnum)
|
let [filename, section] = s:StageFileSection(lnum)
|
||||||
if getline('.') =~# ':$'
|
if getline('.') =~# ':$'
|
||||||
if section ==# 'staged'
|
if section ==# 'staged'
|
||||||
call s:TreeChomp('reset','-q')
|
call s:TreeChomp('reset','-q')
|
||||||
@@ -1927,13 +1930,13 @@ function! s:StageToggle(lnum1,lnum2) abort
|
|||||||
else
|
else
|
||||||
let cmd = ['add','-A', './' . filename]
|
let cmd = ['add','-A', './' . filename]
|
||||||
endif
|
endif
|
||||||
if !exists('first_filename')
|
if !exists('target')
|
||||||
let first_filename = filename
|
let target = [filename, section ==# 'staged' ? '' : 'staged']
|
||||||
endif
|
endif
|
||||||
let output .= call('s:TreeChomp', cmd)."\n"
|
let output .= call('s:TreeChomp', cmd)."\n"
|
||||||
endfor
|
endfor
|
||||||
if exists('first_filename')
|
if exists('target')
|
||||||
call s:StageReloadSeek(first_filename,a:lnum1,a:lnum2)
|
call s:StageReloadSeek(target, a:lnum1, a:lnum2)
|
||||||
endif
|
endif
|
||||||
echo s:sub(s:gsub(output,'\n+','\n'),'\n$','')
|
echo s:sub(s:gsub(output,'\n+','\n'),'\n$','')
|
||||||
catch /^fugitive:/
|
catch /^fugitive:/
|
||||||
@@ -1947,7 +1950,7 @@ function! s:StagePatch(lnum1,lnum2) abort
|
|||||||
let reset = []
|
let reset = []
|
||||||
|
|
||||||
for lnum in range(a:lnum1,a:lnum2)
|
for lnum in range(a:lnum1,a:lnum2)
|
||||||
let [filename, section] = s:stage_info(lnum)
|
let [filename, section] = s:StageFileSection(lnum)
|
||||||
if getline('.') =~# ':$' && section ==# 'staged'
|
if getline('.') =~# ':$' && section ==# 'staged'
|
||||||
return 'Git reset --patch'
|
return 'Git reset --patch'
|
||||||
elseif getline('.') =~# ':$' && section ==# 'unstaged'
|
elseif getline('.') =~# ':$' && section ==# 'unstaged'
|
||||||
|
|||||||
Reference in New Issue
Block a user