Skip to content

Commit 1f1bd0e

Browse files
committed
Fix plugin break in PASTE mode. This fixes terryma#44.
1 parent 2cd396f commit 1f1bd0e

File tree

3 files changed

+46
-16
lines changed

3 files changed

+46
-16
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.2 (06/10/2013)
2+
Bugfixes:
3+
- Fix plugin break in PASTE mode. This fixes #44.
4+
15
## 2.1 (04/26/2013)
26

37
Bugfixes:

autoload/multiple_cursors.vim

+27-16
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ endif
5050
" Internal Mappings
5151
"===============================================================================
5252

53-
inoremap <silent> <Plug>(i) <C-o>:call <SID>process_user_inut()<CR>
54-
nnoremap <silent> <Plug>(i) :call <SID>process_user_inut()<CR>
55-
xnoremap <silent> <Plug>(i) :<C-u>call <SID>process_user_inut()<CR>
53+
inoremap <silent> <Plug>(i) <C-o>:call <SID>process_user_input()<CR>
54+
nnoremap <silent> <Plug>(i) :call <SID>process_user_input()<CR>
55+
xnoremap <silent> <Plug>(i) :<C-u>call <SID>process_user_input()<CR>
5656
5757
inoremap <silent> <Plug>(a) <C-o>:call <SID>apply_user_input_next('i')<CR>
5858
nnoremap <silent> <Plug>(a) :call <SID>apply_user_input_next('n')<CR>
@@ -97,8 +97,8 @@ endfunction
9797
" attempted to be created at the next occurrence of the visual selection
9898
function! multiple_cursors#new(mode)
9999
if a:mode ==# 'n'
100-
" Reset all existing cursors, don't restore view
101-
call s:cm.reset(0)
100+
" Reset all existing cursors, don't restore view and setting
101+
call s:cm.reset(0, 0)
102102

103103
" Select the word under cursor to set the '< and '> marks
104104
exec "normal! viw"
@@ -113,7 +113,7 @@ function! multiple_cursors#new(mode)
113113
let start = line("'<")
114114
let finish = line("'>")
115115
if start != finish
116-
call s:cm.reset(0)
116+
call s:cm.reset(0, 0)
117117
let col = col("'<")
118118
for line in range(line("'<"), line("'>"))
119119
let pos = [line, col]
@@ -124,7 +124,7 @@ function! multiple_cursors#new(mode)
124124
else
125125
" Came directly from visual mode
126126
if s:cm.is_empty()
127-
call s:cm.reset(0)
127+
call s:cm.reset(0, 0)
128128

129129
if visualmode() ==# 'V'
130130
let left = [line('.'), 1]
@@ -133,7 +133,7 @@ function! multiple_cursors#new(mode)
133133
return
134134
endif
135135
call s:cm.add(right, [left, right])
136-
else
136+
else
137137
call s:cm.add(s:pos("'>"), s:region("'<", "'>"))
138138
endif
139139
endif
@@ -219,7 +219,7 @@ function! multiple_cursors#find(start, end, pattern)
219219
call winrestview(s:cm.saved_winview)
220220
echohl ErrorMsg | echo 'No match found' | echohl None
221221
return
222-
else
222+
else
223223
echohl Normal | echo 'Added '.s:cm.size().' cursor'.(s:cm.size()>1?'s':'') | echohl None
224224
call s:wait_for_user_input('v')
225225
endif
@@ -318,6 +318,7 @@ function! s:CursorManager.new()
318318
\ 'virtualedit': &virtualedit,
319319
\ 'cursorline': &cursorline,
320320
\ 'lazyredraw': &lazyredraw,
321+
\ 'paste': &paste,
321322
\ }
322323
" We save the window view when multicursor mode is entered
323324
let obj.saved_winview = []
@@ -327,7 +328,7 @@ function! s:CursorManager.new()
327328
endfunction
328329

329330
" Clear all cursors and their highlights
330-
function! s:CursorManager.reset(restore_view) dict
331+
function! s:CursorManager.reset(restore_view, restore_setting) dict
331332
if a:restore_view
332333
" Return the view back to the beginning
333334
if !empty(self.saved_winview)
@@ -357,7 +358,9 @@ function! s:CursorManager.reset(restore_view) dict
357358
let self.saved_winview = []
358359
let self.start_from_find = 0
359360
let s:char = ''
360-
call self.restore_user_settings()
361+
if a:restore_setting
362+
call self.restore_user_settings()
363+
endif
361364
endfunction
362365

363366
" Returns 0 if it's not managing any cursors at the moment
@@ -513,10 +516,17 @@ endfunction
513516
" where the real vim cursor is
514517
" lazyredraw needs to be turned on to prevent jerky screen behavior with many
515518
" cursors on screen
519+
" paste mode needs to be switched off since it turns off a bunch of features
520+
" that's critical for the plugin to function
516521
function! s:CursorManager.initialize() dict
522+
let self.saved_settings['virtualedit'] = &virtualedit
523+
let self.saved_settings['cursorline'] = &cursorline
524+
let self.saved_settings['lazyredraw'] = &lazyredraw
525+
let self.saved_settings['paste'] = &paste
517526
let &virtualedit = "onemore"
518527
let &cursorline = 0
519528
let &lazyredraw = 1
529+
let &paste = 0
520530
" We could have already saved the view from multiple_cursors#find
521531
if !self.start_from_find
522532
let self.saved_winview = winsaveview()
@@ -529,6 +539,7 @@ function! s:CursorManager.restore_user_settings() dict
529539
let &virtualedit = self.saved_settings['virtualedit']
530540
let &cursorline = self.saved_settings['cursorline']
531541
let &lazyredraw = self.saved_settings['lazyredraw']
542+
let &paste = self.saved_settings['paste']
532543
endif
533544
endfunction
534545

@@ -742,7 +753,7 @@ function! s:feedkeys(keys)
742753
endfunction
743754

744755
" Take the user input and apply it at every cursor
745-
function! s:process_user_inut()
756+
function! s:process_user_input()
746757
" Grr this is frustrating. In Insert mode, between the feedkey call and here,
747758
" the current position could actually CHANGE for some odd reason. Forcing a
748759
" position reset here
@@ -876,7 +887,7 @@ function! s:exit()
876887
let exit = 1
877888
endif
878889
if exit
879-
call s:cm.reset(1)
890+
call s:cm.reset(1, 1)
880891
return 1
881892
endif
882893
return 0
@@ -923,7 +934,7 @@ function! s:revert_highlight_fix()
923934
if type(s:saved_line) == 1
924935
if s:from_mode ==# 'i'
925936
silent! undojoin | call setline('.', s:saved_line)
926-
else
937+
else
927938
call setline('.', s:saved_line)
928939
endif
929940
endif
@@ -961,7 +972,7 @@ function! s:end_latency_measure()
961972
silent! echom "Starting latency debug at ".reltimestr(reltime())
962973
redir END
963974
endif
964-
975+
965976
if !s:skip_latency_measure
966977
exec 'redir >> '.s:latency_debug_file
967978
silent! echom "Processing '".s:char."' took ".string(str2float(reltimestr(reltime(s:start_time)))*1000).' ms in '.s:cm.size().' cursors. mode = '.s:from_mode
@@ -1000,7 +1011,7 @@ function! s:wait_for_user_input(mode)
10001011
if s:exit()
10011012
return
10021013
endif
1003-
1014+
10041015
" If the key is a special key and we're in the right mode, handle it
10051016
if index(get(s:special_keys, s:from_mode, []), s:char) != -1
10061017
call s:handle_special_key(s:char, s:from_mode)

spec/multiple_cursors_spec.rb

+15
Original file line numberDiff line numberDiff line change
@@ -270,4 +270,19 @@ def type(string)
270270
hello world
271271
EOF
272272
end
273+
274+
specify "#set paste mode" do
275+
before <<-EOF
276+
hello
277+
hello
278+
EOF
279+
280+
type ':set paste<CR><C-n><C-n>cworld<Esc>:set nopaste<CR>'
281+
282+
after <<-EOF
283+
world
284+
world
285+
EOF
286+
end
287+
273288
end

0 commit comments

Comments
 (0)