Home Download Buy Blog Forum Support

Expand selection to left in OS X

Expand selection to left in OS X

Postby Saxon on Mon Oct 15, 2012 2:56 pm

I'm sorry if this has been covered already; maybe I'm searching with the wrong keywords but I can't find much on this.

Let's say I have this piece of PHP code:

Code: Select all
$foo['bar'] = 1;
$foo['baz'] = 2;
$this->foo = 3;


Sometimes I also want to select "$foo" instead of just "foo" by double clicking the word. This can be changed by adding "$" to the "word_separators" setting. However, I often want to replace all the "foo" occurrences in the text, which can easily be done using CMD + D on the first "foo", and then a few more CMD +D's.

So I don't include "$" in the word_separators, but I still want to be able to select the "$" sign after selecting the word "foo".

On the Mac, when I select "foo" in "$foo" and press SHIFT + arrow left, "$foo" is selected, adding "$" to the selection of "foo". In ST2 on the Mac though, when I press SHIFT + arrow left, the selection doesn't expand to the left, but moves back from the right, resulting in selecting "fo".

I've tried all sorts of combinations of alt, control, etc. when trying to expand the selection to the left, but it doesn't seem to work. Is there some kind of setting or plugin available to use the default OS X selection behavior?
Saxon
 
Posts: 6
Joined: Fri Jul 27, 2012 3:06 pm

Re: Expand selection to left in OS X

Postby Saxon on Sun Jan 19, 2014 11:24 pm

Bump. I've looked every once in a while if this has changed in SublimeText, but haven't found anything yet.

Does anyone know if there is something in ST3 that would make this possible?

I'd really like to use ST3 as my default editor, but this simple thing just completely breaks my workflow.
Saxon
 
Posts: 6
Joined: Fri Jul 27, 2012 3:06 pm

Re: Expand selection to left in OS X

Postby skuroda on Mon Jan 20, 2014 3:22 am

I don't have an OS X machine to test on, but the expansion of selections is based on the cursor position. For example, if it deselecting an "o" in the presented example, the cursor is probably after the last "o". To highlight the "$" I would assume the cursor is before "f". You could probably write a plugin to reverse the cursor position on some condition, though it may not be quite as reliable as you would like. In windows, if I select word (via double clicking or ctrl+d) the cursor is placed at the end of the word. Perhaps it's different in OS X.
skuroda
 
Posts: 689
Joined: Fri Oct 05, 2012 8:11 am

Re: Expand selection to left in OS X

Postby angusyeh on Mon Jan 20, 2014 12:55 pm

I had a go with this, as exactly skuroda described. This plugin swaps the cursor position of all the current selected regions. So it can "grow" to other direction after swapping. Here is the code that you can add as plugin. I have tried it a bit, it seems to work. I am not entirely sure that it will be absolutely problem free though. Do let me know.

Code: Select all
import sublime, sublime_plugin

class ReverseSelectionCursorsCommand(sublime_plugin.TextCommand):
    """ reverse the .a and .b of all selections, this swaps the cursor between
    the front and the end of selected regions, so that the selected region can
    grow to the other direction. """
    def run(self, edit):
        aa, bb = [], []
        for r in self.view.sel():
            aa.append(r.a)
            bb.append(r.b)
        self.view.sel().clear()
        for a, b in zip(aa,bb):
            self.view.sel().add(sublime.Region(b,a))



Then you can add a key binding to trigger the command easily. eg.

Code: Select all
{ "keys": ["ctrl+alt+r"], "command": "reverse_selection_cursors" },
angusyeh
 
Posts: 14
Joined: Thu Jan 09, 2014 10:49 pm


Return to Technical Support

Who is online

Users browsing this forum: Google [Bot] and 26 guests