Permalink
Browse files

Fix for unintentionally "nested" Insert mode

  • Loading branch information...
1 parent 468a20a commit e4bd6e80cbfb6f1b6b5e657a9291c2a848075e3d @kana committed Apr 11, 2012
Showing with 30 additions and 2 deletions.
  1. +2 −2 autoload/smartinput.vim
  2. +28 −0 t/api.vim
View
@@ -77,7 +77,7 @@ function! smartinput#define_default_rules() "{{{2
\ {'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'},
+ \ {'at': '(\%#)', 'char': '<Enter>', 'input': '<Enter><Enter><Up><Esc>S'},
\ ])
call urules.add('[]', [
\ {'at': '\%#', 'char': '[', 'input': '[]<Left>'},
@@ -92,7 +92,7 @@ function! smartinput#define_default_rules() "{{{2
\ {'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'},
+ \ {'at': '{\%#}', 'char': '<Enter>', 'input': '<Enter><Enter><Up><Esc>S'},
\ ])
call urules.add('''''', [
\ {'at': '\%#', 'char': '''', 'input': '''''<Left>'},
View
@@ -1178,4 +1178,32 @@ describe 'The default configuration'
Expect [line('.'), col('.')] ==# [1, 0 + 1]
endfor
end
+
+ it 'should be escaped immediately after expanding a block'
+ " Insert mode will never be nested if keys are typed interactively. But
+ " some key sequences (such as i<C-o>S) typed via :normal or :map cause
+ " "nested" Insert mode, so that <Esc> must be typed twice to return to
+ " Normal mode. We have to avoid using such key sequences at the moment.
+ " See also: http://groups.google.com/group/vim_dev/browse_thread/thread/a1948a72bb919900
+
+ % delete _
+ execute 'normal' "ifoo\<Esc>I{\<Return>\<Esc>/o\<Return>"
+ Expect getline(1, '$') ==# [
+ \ '{',
+ \ '',
+ \ '}foo',
+ \ ]
+ " or ['{', '/o', '', '}foo'] if Insert mode is nested.
+ Expect [line('.'), col('.')] ==# [3, 3]
+
+ % delete _
+ execute 'normal' "ifoo\<Esc>I(\<Return>\<Esc>/o\<Return>"
+ Expect getline(1, '$') ==# [
+ \ '(',
+ \ '',
+ \ ')foo',
+ \ ]
+ " or ['(', '/o', '', ')foo'] if Insert mode is nested.
+ Expect [line('.'), col('.')] ==# [3, 3]
+ end
end

0 comments on commit e4bd6e8

Please sign in to comment.