Sublime Forum

Shift + Click within Existing Selection to shorten selection

#1

Does anyone here know how to shorten existing selection by mouse clicking?
Usually I can just Shift + Click to the place I want it to be shortened. but in Sublime Text, it just deselect my selection.
I’m a mouse user for coding, really need this, any tweak so I could manage to do that?

0 Likes

#2

You can do this with a plugin. Select Tools > Developer > New Plugin… and paste this:

import sublime
import sublime_plugin


class DragSelectShortenCommand(sublime_plugin.TextCommand):
    def run(self, edit, event, **kwargs):
        view = self.view
        pos = view.window_to_text([event["x"], event["y"]])
        for sel in view.sel():
            if sel.contains(pos):
                reg = sublime.Region(sel.a, pos)
                view.sel().subtract(sel)
                view.sel().add(reg)
                break
        else:
            kwargs = {"event": event, "extend": True}
            view.run_command("drag_select", kwargs)

    def want_event(self):
        return True

Then open the ST console ctrl+` and paste this to open the mouse map:

window.run_command("edit_settings",  {"base_file": "${packages}/Default/Default ($platform).sublime-mousemap", "default": "[\n\t$0\n]\n"})

There you add this mouse binding:

    {
        "button": "button1", "modifiers": ["shift"],
        "press_command": "drag_select_shorten"
    },
2 Likes

#3

Really thank you for your reply.

Sorry, I’m really new on creating new plugin.
after paste the plugin code. need to save right? what filename should I save and to where?

0 Likes

#4

Yes, you need to save it in the User folder (which should be the default) and the file name is not important.

0 Likes

#5

Okay. Actually figured that out just now.

Really appreciate for your tweak.

Thank you very much. :smiley:

0 Likes

#6

No problem, I also like it more this way :slight_smile:

0 Likes