Add the p mapping to preview a change.
This commit is contained in:
parent
5cd18132a7
commit
09fcef2178
@ -96,6 +96,10 @@ of the change that state made.
|
||||
Pressing enter on a state (or double clicking on it) will revert the contents
|
||||
of the file to match that state.
|
||||
|
||||
You can use p on a state to make the preview window show the diff between
|
||||
your current state and the selected state, instead of a preview of what the
|
||||
selected state changed.
|
||||
|
||||
Pressing P while on a state will initiate "play to" mode targeted at that
|
||||
state. This will replay all the changes between your current state and the
|
||||
target, with a slight pause after each change. It's mostly useless, but can be
|
||||
@ -192,6 +196,8 @@ Development version
|
||||
* Fix movement commands with counts in the graph.
|
||||
* Make GundoToggle close the Gundo windows if they're visible but not the
|
||||
current window, instead of moving to them.
|
||||
* Add the 'p' mapping to preview the result of reverting to the selected
|
||||
state.
|
||||
v1.0.0
|
||||
* Initial stable release.
|
||||
|
||||
|
@ -55,6 +55,8 @@ if !exists('g:gundo_right')"{{{
|
||||
let g:gundo_right = 0
|
||||
endif"}}}
|
||||
|
||||
let s:inline_help_length = 6
|
||||
|
||||
"}}}
|
||||
|
||||
"{{{ Mercurial's graphlog code
|
||||
@ -427,7 +429,8 @@ def _undo_to(n):
|
||||
INLINE_HELP = '''\
|
||||
" Gundo for %s [%d]
|
||||
" j/k - move between undo states
|
||||
" <cr> - revert to that state
|
||||
" p - preview diff of selected and current states
|
||||
" <cr> - revert to selected state
|
||||
|
||||
'''
|
||||
ENDPYTHON
|
||||
@ -518,6 +521,7 @@ function! s:GundoMapGraph()"{{{
|
||||
nnoremap <script> <silent> <buffer> k :call <sid>GundoMove(-1)<CR>
|
||||
nnoremap <script> <silent> <buffer> gg gg:call <sid>GundoMove(1)<CR>
|
||||
nnoremap <script> <silent> <buffer> P :call <sid>GundoPlayTo()<CR>
|
||||
nnoremap <script> <silent> <buffer> p :call <sid>GundoRenderChangePreview()<CR>
|
||||
nnoremap <script> <silent> <buffer> q :call <sid>GundoClose()<CR>
|
||||
cabbrev <script> <silent> <buffer> q call <sid>GundoClose()
|
||||
cabbrev <script> <silent> <buffer> quit call <sid>GundoClose()
|
||||
@ -719,8 +723,8 @@ function! s:GundoMove(direction) range"{{{
|
||||
let target_n = line('.') + (distance * a:direction)
|
||||
|
||||
" Bound the movement to the graph.
|
||||
if target_n <= 4
|
||||
call cursor(5, 0)
|
||||
if target_n <= s:inline_help_length - 1
|
||||
call cursor(s:inline_help_length, 0)
|
||||
else
|
||||
call cursor(target_n, 0)
|
||||
endif
|
||||
@ -794,6 +798,26 @@ def _generate_preview_diff(current, node_before, node_after):
|
||||
|
||||
_undo_to(current)
|
||||
|
||||
return list(difflib.unified_diff(before_lines, after_lines,
|
||||
before_name, after_name,
|
||||
before_time, after_time))
|
||||
|
||||
def _generate_change_preview_diff(current, node_before, node_after):
|
||||
_goto_window_for_buffer(vim.eval('g:gundo_target_n'))
|
||||
|
||||
_undo_to(node_before.n)
|
||||
before_lines = vim.current.buffer[:]
|
||||
|
||||
_undo_to(node_after.n)
|
||||
after_lines = vim.current.buffer[:]
|
||||
|
||||
before_name = node_before.n or 'Original'
|
||||
before_time = node_before.time and _fmt_time(node_before.time) or ''
|
||||
after_name = node_after.n or 'Original'
|
||||
after_time = node_after.time and _fmt_time(node_after.time) or ''
|
||||
|
||||
_undo_to(current)
|
||||
|
||||
return list(difflib.unified_diff(before_lines, after_lines,
|
||||
before_name, after_name,
|
||||
before_time, after_time))
|
||||
@ -880,6 +904,40 @@ GundoRenderPreview()
|
||||
ENDPYTHON
|
||||
endfunction"}}}
|
||||
|
||||
function! s:GundoRenderChangePreview()"{{{
|
||||
python << ENDPYTHON
|
||||
def GundoRenderChangePreview():
|
||||
if not _check_sanity():
|
||||
return
|
||||
|
||||
target_state = vim.eval('s:GundoGetTargetState()')
|
||||
|
||||
# Check that there's an undo state. There may not be if we're talking about
|
||||
# a buffer with no changes yet.
|
||||
if target_state == None:
|
||||
_goto_window_for_buffer_name('__Gundo__')
|
||||
return
|
||||
else:
|
||||
target_state = int(target_state)
|
||||
|
||||
_goto_window_for_buffer(vim.eval('g:gundo_target_n'))
|
||||
|
||||
nodes, nmap = make_nodes()
|
||||
current = changenr(nodes)
|
||||
|
||||
node_after = nmap[target_state]
|
||||
node_before = nmap[current]
|
||||
print node_after, node_before
|
||||
|
||||
vim.command('call s:GundoOpenPreview()')
|
||||
_output_preview_text(_generate_change_preview_diff(current, node_before, node_after))
|
||||
|
||||
_goto_window_for_buffer_name('__Gundo__')
|
||||
|
||||
GundoRenderChangePreview()
|
||||
ENDPYTHON
|
||||
endfunction"}}}
|
||||
|
||||
"}}}
|
||||
|
||||
"{{{ Gundo undo/redo
|
||||
|
@ -202,6 +202,12 @@
|
||||
of the file to match that state.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
You can use p on a state to make the preview window show the diff between
|
||||
your current state and the selected state, instead of a preview of what the
|
||||
selected state changed.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Pressing <code>P</code> while on a state will initiate "play to" mode targeted at that
|
||||
state. This will replay all the changes between your current state and the
|
||||
|
Loading…
Reference in New Issue
Block a user