Correct "Add Next/Previous Line" behaviour

Vitaliy Berov 5 years ago • updated 5 years ago 1

I'll admit i've discovered this 'inconsistent' behaviour of Add Next/Prev line after some playtime with macros and multiple selections. 

As such my feature request might seem quite exotic and not worth implementing. OK, i warned you. :)

What i discovered is when adding next/prev line, Sublime is not that smart where it places the new caret in case there's been non-empty selection.

Consider the following example:

foo bar baz

foo bar| baz

foo bar baz

having the empty selection in the center right after bar when we add previous/next line we end up with multiple selections like this

foo bar| baz

foo bar| baz

foo bar| baz.

Everything's ok here.

Next one is with non-empty selection where [] is the actual region and region.begin() < region.end():

  start                 add prev/next line         expected

foo bar baz           foo |bar baz            foo  bar| baz

foo [bar]| baz        foo [bar]| baz          foo [bar]| baz

foo bar baz           foo  bar| baz           foo  bar| baz

What i'd like is Sublime to take into consideration where the end of the region is  and place the next region above/below it. 

The following exmaple is with reversed regions where region.begin() > region.end()

   before                 after                   expected

foo bar baz         foo |bar baz       foo |bar baz

foo |[bar] baz      foo |[bar] baz     foo |[bar] baz

foo bar baz         foo bar| baz       foo |bar baz

i solved my problem by writing custom command and overwriting default keybindings.

if anybody is interested https://gist.github.com/4338959