Sublime Forum

A more obvious indicator when you are in multiple selection mode

#1

It’s not a big issue as it doesn’t happen too often but one that I thought deserved a post nonetheless since it’s been an occasional source of bug in my code: I wish there would be a more obvious indicator when you are in multiple selection mode. Sometimes I’ll hit escape to get back to single selection, for whatever reason, maybe the keystroke didn’t register, but I’m still in multiple selection mode and not aware of it. If there was only one other selection far down in the page, I don’t always notice it and end up with a bug a few minutes later where I have to retrace my steps. Sometimes I lose a line of code somewhere and wonder why. Thanks for your attention!

0 Likes

Alter look of cursors when there's more than one
#2

@koan The statusbar tells you if there are multiple selections (and their total count).

0 Likes

#3

Thanks for the reply. Well I should have specified more obvious than the very discreet gray message in the bottom status bar, like make it stand out more visually so it is harder to miss when you’re working fast. Being in multiple selection mode is kind of an exceptional state, it can be a bit more flashy.

0 Likes

#4

Make a pair of color schemes that differ somehow, maybe background color or highlight color. Write a plugin with an EventListener. Replace Monokai here with your special second color scheme.

on_selection_modified(self, view):
    if len(view.sel()) > 1:
        view.settings().set('color_scheme', 'Packages/Color Scheme - Default/Monokai.tmTheme')
    else:
        view.settings().erase('color_scheme')
1 Like

#5

Great idea!
If changing the cursor appearance is enough visual indication, you don’t have to bother with parallel colour schemes:

Packages/User/visualize_multiselect.py

import sublime, sublime_plugin

class VisualizeMultiselectEventListener(sublime_plugin.EventListener):
    def on_selection_modified(self, view):
        if len(view.sel()) > 1:
            view.settings().set('caret_extra_width', 2)
        else:
            view.settings().erase('caret_extra_width')
0 Likes

#6

Thanks guys for the suggestions, lappri, I’m going to go with yours, it’s essentially what I wanted, a little extra visual cue that I’m in multiselect mode, especially useful when I think I escaped to single select, but actually didn’t.

0 Likes

#7

lappri, just something I noticed, but it doesn’t change the cursor when I’m viewing a file in “new view into file” mode (from the File menu). I frequently use that feature, so if you ever think of a fix (if it’s not a Sublime Text bug), I would definitely appreciate it.

0 Likes

#8

The reason that happens is that many of the events from the EventListener class are triggered on a buffer by buffer basis and not a view by view basis. Since New view into file is just an alternate view into the same buffer, the event doesn’t get triggered for the alternate view(s).

You may be able to achieve the same effect with a ViewEventListener instead, though. The API docs mention a applies_to_primary_view_only method which sounds like you could use it to indicate that the event should trigger for every view and not just a primary view.

0 Likes

#9

Apparently there is a known bug which prevents this from working with “new view into file”:
https://github.com/SublimeTextIssues/Core/issues/1504
https://github.com/SublimeTextIssues/Core/issues/1253

0 Likes

#10

Ahh interesting. A bit after I posted that the thought occurred that something like selection changing is specific to the view (unlike say on_save) so it definitely seemed weird that it didn’t work, but I forgot to follow up on it. Nice catch.

0 Likes