From f8989a9269b450fadc9ceef4f40f065d69b4aec5 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Sun, 23 Jul 2017 05:35:49 +0800 Subject: [PATCH] Add keys for buffer transient state --- autoload/SpaceVim/api/transient_state.vim | 13 ++++- autoload/SpaceVim/layers/default.vim | 64 +++++++++++++++++++++-- 2 files changed, 72 insertions(+), 5 deletions(-) diff --git a/autoload/SpaceVim/api/transient_state.vim b/autoload/SpaceVim/api/transient_state.vim index 9acb98f84..1e039944f 100644 --- a/autoload/SpaceVim/api/transient_state.vim +++ b/autoload/SpaceVim/api/transient_state.vim @@ -35,7 +35,7 @@ function! s:self.open() abort exe 'resize ' . line('$') endif " move to prvious window - wincmd w + wincmd p while 1 redraw! let char = self._getchar() @@ -94,7 +94,7 @@ function! s:self._update_content() abort let right = get(self._keys.right, i) let line = '' if !empty(left) - if type(left.key) ==# type('') + if type(left.key) == 1 let line .= '[' . left.key . '] ' . left.desc call self.highlight_keys(left.exit, i + 2, 1, 1 + len(left.key)) if !empty(left.cmd) @@ -102,6 +102,15 @@ function! s:self._update_content() abort elseif !empty(left.func) call extend(self._handle_inputs, {left.key : left.func}) endif + elseif type(left.key) == 3 + elseif type(left.key) == 4 + let line .= '[' . left.key.name . '] ' . left.desc + for pos in left.key.pos + call self.highlight_keys(left.exit, i + 2, pos[0], pos[1]) + endfor + for handles in left.key.handles + call extend(self._handle_inputs, {handles[0] : handles[1]}) + endfor endif endif let line .= repeat(' ', 40 - len(line)) diff --git a/autoload/SpaceVim/layers/default.vim b/autoload/SpaceVim/layers/default.vim index af9767089..7fad6179d 100644 --- a/autoload/SpaceVim/layers/default.vim +++ b/autoload/SpaceVim/layers/default.vim @@ -289,6 +289,29 @@ function! s:delete_current_buffer_file() abort endfunction +function! s:swap_buffer_with_nth_win(nr) abort + if a:nr <= winnr('$') && a:nr != winnr() + let cb = bufnr('%') + let tb = winbufnr(a:nr) + if cb != tb + exe a:nr . 'wincmd w' + exe 'b' . cb + wincmd p + exe 'b' . tb + endif + endif +endfunction + +function! s:move_buffer_to_nth_win(nr) abort + if a:nr <= winnr('$') && a:nr != winnr() + let cb = bufnr('%') + bp + exe a:nr . 'wincmd w' + exe 'b' . cb + wincmd p + endif +endfunction + function! s:buffer_transient_state() abort let state = SpaceVim#api#import('transient_state') call state.set_title('Buffer Selection Transient State') @@ -297,10 +320,45 @@ function! s:buffer_transient_state() abort \ 'layout' : 'vertical split', \ 'left' : [ \ { - \ 'key' : 'J', - \ 'desc' : 'move text down', + \ 'key' : { + \ 'name' : 'C-1..C-9', + \ 'pos' : [[1,4], [6,9]], + \ 'handles' : [ + \ ["\" , ''], + \ ["\" , ''], + \ ["\" , ''], + \ ["\" , ''], + \ ["\" , ''], + \ ["\" , ''], + \ ["\" , ''], + \ ["\" , ''], + \ ["\" , ''], + \ ], + \ }, + \ 'desc' : 'goto nth window', \ 'func' : '', - \ 'cmd' : 'normal! "_ddp', + \ 'cmd' : '', + \ 'exit' : 0, + \ }, + \ { + \ 'key' : { + \ 'name' : '1..9', + \ 'pos' : [[1,2], [4,5]], + \ 'handles' : [ + \ ['1' , 'call call(' . string(s:_function('s:move_buffer_to_nth_win')) . ', [1])'], + \ ['2' , 'call call(' . string(s:_function('s:move_buffer_to_nth_win')) . ', [2])'], + \ ['3' , 'call call(' . string(s:_function('s:move_buffer_to_nth_win')) . ', [3])'], + \ ['4' , 'call call(' . string(s:_function('s:move_buffer_to_nth_win')) . ', [4])'], + \ ['5' , 'call call(' . string(s:_function('s:move_buffer_to_nth_win')) . ', [5])'], + \ ['6' , 'call call(' . string(s:_function('s:move_buffer_to_nth_win')) . ', [6])'], + \ ['7' , 'call call(' . string(s:_function('s:move_buffer_to_nth_win')) . ', [7])'], + \ ['8' , 'call call(' . string(s:_function('s:move_buffer_to_nth_win')) . ', [8])'], + \ ['9' , 'call call(' . string(s:_function('s:move_buffer_to_nth_win')) . ', [9])'], + \ ], + \ }, + \ 'desc' : 'move buffer to nth window', + \ 'func' : '', + \ 'cmd' : '', \ 'exit' : 0, \ }, \ ],