Skip to content

Commit c9c7655

Browse files
add the rest of the block opener keywords
1 parent 2b882e2 commit c9c7655

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

plugin/textobj/rubyblock.vim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ call textobj#user#plugin('rubyblock', {
1313

1414
" Misc. "{{{1
1515
let s:comment_escape = '\v^[^#]*'
16-
let s:block_openers = '\zs(<def>|<if>|<do>|<module>|<class>)'
16+
let s:block_openers = '\zs(<def>|<if>|<unless>|<do>|<module>|<class>|<case>'
17+
let s:block_openers .= '|<for>|<while>|<until>|<begin>)'
1718
let s:start_pattern = s:comment_escape . s:block_openers
1819
let s:end_pattern = s:comment_escape . '\zs<end>'
1920
let s:skip_pattern = 'getline(".") =~ "\\v\\S\\s<(if|unless)>\\s\\S"'

t/examples.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,19 @@ def hello
6565
bar
6666
end
6767

68+
def method_with_while
69+
var1 = 1
70+
i = 0
71+
while i < 10
72+
i += 1
73+
end
74+
var2 = 2
75+
end
76+
77+
def method_with_unless
78+
var1 = 1
79+
unless condition
80+
puts 'foo'
81+
end
82+
var2 = 2
83+
end

t/rubyblock_test.vim

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,23 @@ describe '<Plug>(textobj-rubyblock-a)'
8686

8787
end
8888

89+
describe 'nested while and unless blocks'
90+
91+
before
92+
silent tabnew t/examples.rb
93+
end
94+
95+
after
96+
silent tabclose
97+
end
98+
99+
it 'ignores nested while and unless blocks'
100+
Expect SelectAroundFrom(69, '^') ==# [69, 68, 75]
101+
Expect SelectAroundFrom(78, '^') ==# [78, 77, 83]
102+
end
103+
104+
end
105+
89106
describe '<Plug>(textobj-rubyblock-i)'
90107

91108
before

0 commit comments

Comments
 (0)