@@ -174,6 +174,38 @@ function! s:SearchUpForPattern(pattern) abort
174174endfunction
175175
176176
177+ function ! s: AngularRunSpecBlock () abort
178+ " save cursor position so we can go back
179+ let b: angular_pos = getpos (' .' )
180+
181+ cal s: SearchUpForPattern (' describe(' )
182+
183+ let l: wordundercursor = expand (' <cword>' )
184+
185+ if l: wordundercursor == " describe"
186+ " if there was a spec (anywhere in the file) highlighted with "ddescribe" before, revert it to "describe"
187+ let l: positionofspectorun = getpos (' .' )
188+
189+ " this can move the cursor, hence setting the cursor back
190+ % s /ddescribe/ describe/ge
191+ % s /iit/ it/ge
192+
193+ " move cursor back to the spec we want to run
194+ call setpos (' .' , l: positionofspectorun )
195+
196+ " change the current spec to "ddescribe"
197+ execute ' silent normal! cwddescribe'
198+ elseif l: wordundercursor == " ddescribe"
199+ " delete the second d in "ddescribe"
200+ execute ' silent normal! x'
201+ endif
202+
203+ update " write the file if modified
204+
205+ " Reset cursor to previous position.
206+ call setpos (' .' , b: angular_pos )
207+ endfunction
208+
177209function ! s: AngularRunSpec () abort
178210 " save cursor position so we can go back
179211 let b: angular_pos = getpos (' .' )
@@ -230,5 +262,7 @@ augroup END
230262augroup angular_run_spec
231263 autocmd !
232264 autocmd FileType javascript command ! - buffer AngularRunSpec :call s: AngularRunSpec ()
265+ autocmd FileType javascript command ! - buffer AngularRunSpecBlock :call s: AngularRunSpecBlock ()
233266 autocmd FileType javascript nnoremap <silent> <buffer> <Leader> rs :AngularRunSpec<CR>
267+ autocmd FileType javascript nnoremap <silent> <buffer> <Leader> rb :AngularRunSpecBlock<CR>
234268augroup END
0 commit comments