1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-04-13 15:09:09 +08:00

Add transient state api

This commit is contained in:
wsdjeg 2017-07-22 07:30:17 +08:00
parent b1ebe04d44
commit 5521e64072
3 changed files with 106 additions and 6 deletions

View File

@ -0,0 +1,76 @@
let s:self = {}
let s:self._keys = {}
let s:self._on_syntax = ''
let s:self._title = 'Transient State'
function! s:self.open() abort
noautocmd rightbelow split __transient_state__
let self._bufid = bufnr('%')
setlocal buftype=nofile bufhidden=wipe nobuflisted nolist noswapfile nowrap cursorline nospell nonu norelativenumber
" let save_tve = &t_ve
" setlocal t_ve=
" setlocal nomodifiable
" setf SpaceVimFlyGrep
" let &t_ve = save_tve
if !empty(self._on_syntax) && type(self._on_syntax) ==# 2
call call(self._on_syntax, [])
else
hi def link SpaceVim_Transient_State_Exit Keyword
hi def link SpaceVim_Transient_State_Notexit Number
hi def link SpaceVim_Transient_State_Title Title
endif
call setline(1, self._title)
call append(line('$'), '')
call self.highlight_title()
call self._update_content()
call append(line('$'), '')
call append(line('$'), '[KEY] exits state [KEY] will not exit')
call self.highlight_keys(1, line('$') - 1, 1, 4)
call self.highlight_keys(0, line('$') - 1, 21, 24)
" move to prvious window
wincmd w
redraw!
while 1
let char = getchar()
if char ==# "\<FocusLost>" || char ==# "\<FocusGained>" || char2nr(char) == 128
continue
endif
if !has_key(self._keys, char)
break
endif
endwhile
exe 'bd ' . self._bufid
endfunction
function! s:self.defind_keys(dict) abort
let self._keys = a:dict
endfunction
function! s:self.set_syntax(func) abort
let self._on_syntax = a:func
endfunction
function! s:self.set_title(title) abort
let self._title = a:title
endfunction
function! s:self.highlight_keys(exit, line, begin, end) abort
if a:exit
call nvim_buf_add_highlight(self._bufid, 0, 'SpaceVim_Transient_State_Exit', a:line, a:begin, a:end)
else
call nvim_buf_add_highlight(self._bufid, 0, 'SpaceVim_Transient_State_Notexit', a:line, a:begin, a:end)
endif
endfunction
function! s:self.highlight_title() abort
call nvim_buf_add_highlight(self._bufid, 0, 'SpaceVim_Transient_State_Title', 0, 0, len(self._title))
endfunction
function! s:self._update_content() abort
endfunction
function! SpaceVim#api#transient_state#get() abort
return deepcopy(s:self)
endfunction

View File

@ -124,6 +124,30 @@ function! SpaceVim#layers#edit#config() abort
\ 'insert lorem-ipsum sentence', 1)
let g:_spacevim_mappings_space.x.g = {'name' : '+translate'}
call SpaceVim#mapping#space#def('nnoremap', ['x', 'g', 't'], 'Ydc', 'translate current word', 1)
" move line
call SpaceVim#mapping#space#def('nnoremap', ['x', 'J'], 'call call('
\ . string(s:_function('s:move_text_down_transient_state')) . ', [])',
\ 'move text down(enter transient state)', 1)
call SpaceVim#mapping#space#def('nnoremap', ['x', 'K'], 'call call('
\ . string(s:_function('s:move_text_up_transient_state')) . ', [])',
\ 'move text up(enter transient state)', 1)
endfunction
function! s:move_text_down_transient_state() abort
normal! "_ddp
call s:text_transient_state()
endfunction
function! s:move_text_up_transient_state() abort
normal! "_ddkP
call s:text_transient_state()
endfunction
function! s:text_transient_state() abort
let state = SpaceVim#api#import('transient_state')
call state.set_title('Move Text Transient State')
call state.open()
endfunction
function! s:lowerCamelCase() abort

View File

@ -1189,7 +1189,7 @@ Key Binding | Description
`SPC x c` | cunt the number of chars/words/lines in the selection region
`SPC x d w` | delete trailing whitespaces
`SPC x d SPC` | Delete all spaces and tabs around point, leaving one space
`SPC x g l` | set languages used by translate commands (TODO)
`SPC x g l` | set lanuages used by translate commands (TODO)
`SPC x g t` | translate current word using Google Translate
`SPC x g T` | reverse source and target languages (TODO)
`SPC x i c` | change symbol style to `lowerCamelCase`
@ -1200,11 +1200,11 @@ Key Binding | Description
`SPC x i _` | change symbol style to `under_score`
`SPC x i u` | change symbol style to `under_score`
`SPC x i U` | change symbol style to `UP_CASE`
`SPC x j c` | set the justification to center
`SPC x j f` | set the justification to full
`SPC x j l` | set the justification to left
`SPC x j n` | set the justification to none
`SPC x j r` | set the justification to right
`SPC x j c` | set the justification to center (TODO)
`SPC x j f` | set the justification to full (TODO)
`SPC x j l` | set the justification to left (TODO)
`SPC x j n` | set the justification to none (TODO)
`SPC x j r` | set the justification to right (TODO)
`SPC x J` | move down a line of text (enter transient state)
`SPC x K` | move up a line of text (enter transient state)
`SPC x l d` | duplicate line or region