Permalink
Browse files

Merge branch 'cooperate-with-visual-block-insert'

Close gh-44.
  • Loading branch information...
2 parents 6a15f33 + 34bbaa0 commit 468a20aa3062527f25ddf0d4aedf8aee0b69cabc @kana committed Apr 9, 2012
Showing with 29 additions and 3 deletions.
  1. +13 −3 autoload/smartinput.vim
  2. +16 −0 t/api.vim
@@ -73,22 +73,22 @@ function! smartinput#define_default_rules() "{{{2
endfunction
call urules.add('()', [
\ {'at': '\%#', 'char': '(', 'input': '()<Left>'},
- \ {'at': '\%#\_s*)', 'char': ')', 'input': '<Char-0x1C><C-o>:call search('')'', ''cW'')<Enter><Right>'},
+ \ {'at': '\%#\_s*)', 'char': ')', 'input': '<C-r>=smartinput#_leave_block('')'')<Enter><Right>'},
\ {'at': '(\%#)', 'char': '<BS>', 'input': '<BS><Del>'},
\ {'at': '()\%#', 'char': '<BS>', 'input': '<BS><BS>'},
\ {'at': '\\\%#', 'char': '(', 'input': '('},
\ {'at': '(\%#)', 'char': '<Enter>', 'input': '<Enter><Enter><Up><C-o>S'},
\ ])
call urules.add('[]', [
\ {'at': '\%#', 'char': '[', 'input': '[]<Left>'},
- \ {'at': '\%#\_s*\]', 'char': ']', 'input': '<Char-0x1C><C-o>:call search('']'', ''cW'')<Enter><Right>'},
+ \ {'at': '\%#\_s*\]', 'char': ']', 'input': '<C-r>=smartinput#_leave_block('']'')<Enter><Right>'},
\ {'at': '\[\%#\]', 'char': '<BS>', 'input': '<BS><Del>'},
\ {'at': '\[\]\%#', 'char': '<BS>', 'input': '<BS><BS>'},
\ {'at': '\\\%#', 'char': '[', 'input': '['},
\ ])
call urules.add('{}', [
\ {'at': '\%#', 'char': '{', 'input': '{}<Left>'},
- \ {'at': '\%#\_s*}', 'char': '}', 'input': '<Char-0x1C><C-o>:call search(''}'', ''cW'')<Enter><Right>'},
+ \ {'at': '\%#\_s*}', 'char': '}', 'input': '<C-r>=smartinput#_leave_block(''}'')<Enter><Right>'},
\ {'at': '{\%#}', 'char': '<BS>', 'input': '<BS><Del>'},
\ {'at': '{}\%#', 'char': '<BS>', 'input': '<BS><BS>'},
\ {'at': '\\\%#', 'char': '{', 'input': '{'},
@@ -258,6 +258,16 @@ function! s:_operator_pattern_from(operator_name)
return k
endfunction
+function! smartinput#_leave_block(end_char)
+ " NB: Originally <C-o> was used to execute search(), but <C-o> in
+ " Visual-block Insert acts as if <Esc>a, so visually selected lines will be
+ " updated and the current mode will be shifted to Insert mode. It means
+ " that there is no timing to execute a Normal mode command. Therefore we
+ " have to use <C-r>= instead.
+ call search(a:end_char, 'cW')
+ return ''
+endfunction
+
View
@@ -1162,4 +1162,20 @@ describe 'The default configuration'
call b:.test_rules(test_set_table)
end
+
+ it 'should be cooperative with Visual-block Insert'
+ for input in ['(foo)bar:', '[foo]bar', '{foo}bar:']
+ % delete _
+ put =['a', 'b', 'c', 'd']
+ 1 delete _
+ execute 'normal' "gg0\<C-v>GI".input."\<Esc>"
+ Expect getline(1, '$') ==# [
+ \ input . 'a',
+ \ input . 'b',
+ \ input . 'c',
+ \ input . 'd',
+ \ ]
+ Expect [line('.'), col('.')] ==# [1, 0 + 1]
+ endfor
+ end
end

0 comments on commit 468a20a

Please sign in to comment.