Shift selection by column?


#1

Is it possible to move a selection left or right by one column? I haven’t found anything for this yet, but I’m wondering if I’ve missed something.


#2

There’s Selection.selectLeft and Selection.selectRight:

Is that what you’re looking for?


#3

Nope, I’m looking more for the column equivalent of editor:move-line-up / editor:move-line-down – basically, take an already existing selection and move it by one column left or right.


#4

Sounds like you could do:

range = selection.getBufferRange().translate([1, 0])   # To move it right
selection.setBufferRange(range)

I haven’t tested it because I’m on my way out the door to the Avengers movie. But the docs make it sound like it’ll work.


#5

Close! I don’t think I explained what I meant very well though – rather than move the Selection, I want to move the text in the Selection left or right by one column.


#6

Oh … I don’t know what I thought the commands you mentioned said, but I missed it. Sorry :blush: Being too literal minded. That does sound a bit tougher. Actually, what I would do is rather than moving the selection and its contents, I would move the one character on the right to the left or vice versa. An example:

In the example the left and right brackets [ and ] signify the extent of the selection.

blahblahblah[foofoofoo]blahblahblah

If moving the selection right, just delete the b to the right of the end of the selection and place it after the h at the beginning:

blahblahblahb[foofoofoo]lahblahblah

This technique should work just fine for a selection spanning multiple lines or for multiple selections too.

I think this approach would be easier …


#7

:+1: Yeah this sounds great! Should be way more performant too since it’ll only ever be modifying one character per selection per line (instead of deleting and reinserting the whole selection).


#8

Got it working! This is actually quite useful. Gonna make a PR once I add specs :smile: – thanks @leedohm!


#9

@mnquintana Is this available as a package / instructions how I can do this? This would be most useful.


#10

It looks like it was never merged:

I found this by looking through the list of Pull Requests by @mnquintana on Atom Core.


#11

@leedohm Hey thanks! That’s awesome. I’ve never created an Atom package before. Is it possible to make one that accomplishes what this PR would have? Not sure what the limitations of packages are. Thanks again.


#12

Yes, it definitely would be possible to do this in a package. There are tutorials in the Atom Flight Manual on how to write packages.


#13

Ah yeah, I’m still planning on finishing this up and getting it merged - just been a bit too busy lately :sweat_smile:. Hopefully I’ll get to it sometime this week.