diff --git a/autoload/sideways/textobj.vim b/autoload/sideways/textobj.vim index e34179a..6b00658 100644 --- a/autoload/sideways/textobj.vim +++ b/autoload/sideways/textobj.vim @@ -12,8 +12,15 @@ function! sideways#textobj#Argument(mode) elseif a:mode == 'a' if !empty(previous) if previous[0] < current[0] - " this is a new line, no need to delete till the end of the previous - call s:MarkCols([current[0], current[1]], [current[0], current[2]]) + if !empty(next) && next[0] == current[0] + " this is a new line with a next item on the same line, delete to + " that next item instead + call s:MarkCols([current[0], current[1]], [next[0], next[1] - 1]) + else + " this is a new line with no next, delete till previous, remove + " newline + call s:MarkCols([previous[0], previous[1] + 1], [current[0], current[2]]) + endif else " there are other things on the line call s:MarkCols([previous[0], previous[2] + 1], [current[0], current[2]]) diff --git a/spec/plugin/textobj_spec.rb b/spec/plugin/textobj_spec.rb index a3a52ae..a7f7413 100644 --- a/spec/plugin/textobj_spec.rb +++ b/spec/plugin/textobj_spec.rb @@ -1,72 +1,109 @@ require 'spec_helper' describe "textobj mapping" do - let(:filename) { 'test.py' } + describe "single-line" do + let(:filename) { 'test.py' } - before :each do - set_file_contents <<-EOF - def func(one, two, three): - pass - EOF - end + before :each do + set_file_contents <<-EOF + def func(one, two, three): + pass + EOF + end - specify "first argument" do - vim.search('one') - vim.feedkeys 'daa' - vim.write + specify "first argument" do + vim.search('one') + vim.feedkeys 'daa' + vim.write - assert_file_contents <<-EOF - def func(two, three): - pass - EOF + assert_file_contents <<-EOF + def func(two, three): + pass + EOF - vim.feedkeys 'ciachanged' - vim.write + vim.feedkeys 'ciachanged' + vim.write - assert_file_contents <<-EOF - def func(changed, three): - pass - EOF - end + assert_file_contents <<-EOF + def func(changed, three): + pass + EOF + end - specify "delete middle argument" do - vim.search('two') - vim.feedkeys 'daa' - vim.write + specify "delete middle argument" do + vim.search('two') + vim.feedkeys 'daa' + vim.write - assert_file_contents <<-EOF - def func(one, three): - pass - EOF - end + assert_file_contents <<-EOF + def func(one, three): + pass + EOF + end + + specify "change middle argument" do + vim.search('two') + vim.feedkeys 'ciachanged' + vim.write + + assert_file_contents <<-EOF + def func(one, changed, three): + pass + EOF + end - specify "change middle argument" do - vim.search('two') - vim.feedkeys 'ciachanged' - vim.write + specify "last argument" do + vim.search('three') + vim.feedkeys 'daa' + vim.write - assert_file_contents <<-EOF - def func(one, changed, three): - pass - EOF + assert_file_contents <<-EOF + def func(one, two): + pass + EOF + + vim.feedkeys 'ciachanged' + vim.write + + assert_file_contents <<-EOF + def func(one, changed): + pass + EOF + end end - specify "last argument" do - vim.search('three') - vim.feedkeys 'daa' - vim.write + describe "multiline" do + let(:filename) { 'test.js' } + + specify "outer argument, with two items on second line" do + set_file_contents <<-EOF + function(a, b, + c, d) { } + EOF + + vim.search('c,') + vim.feedkeys 'daa' + vim.write + + assert_file_contents <<-EOF + function(a, b, + d) { } + EOF + end - assert_file_contents <<-EOF - def func(one, two): - pass - EOF + specify "outer argument, with one item on second line" do + set_file_contents <<-EOF + function(a, b, + c) { } + EOF - vim.feedkeys 'ciachanged' - vim.write + vim.search('c)') + vim.feedkeys 'daa' + vim.write - assert_file_contents <<-EOF - def func(one, changed): - pass - EOF + assert_file_contents <<-EOF + function(a, b) { } + EOF + end end end