Home Download Buy Blog Forum Support

NavigateSelections

NavigateSelections

Postby bizoo on Wed Jan 23, 2013 5:15 pm

A small but surprisingly useful (for me) plugin for navigating between selections:
It scroll the view up/down to show the next selections.

Very useful after a Find All to check if the selections is what you have expected.
Enjoy!

Code: Select all
import sublime, sublime_plugin


class NavigateSelectionsCommand(sublime_plugin.WindowCommand):
    def run(self, forward=True):
        sels = self.window.active_view().sel()
        if len(sels) == 0:
            return

        visible_region = self.window.active_view().visible_region()
        if forward:
            iterator = reversed(sels)
        else:
            iterator = sels
        next_sel = None
        for s in iterator:
            if visible_region.contains(s):
                break
            next_sel = s

        if next_sel is None:
            if forward:
                next_sel = sels[0]
            else:
                next_sel = sels[-1]
        self.window.active_view().show(next_sel, True)


Code: Select all
    //Navigate Selections
    { "keys": ["super+alt+down"], "command": "navigate_selections", "args": {"forward": true} },
    { "keys": ["super+alt+up"], "command": "navigate_selections", "args": {"forward": false} }
bizoo
 
Posts: 870
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland

Re: NavigateSelections

Postby vitaLee on Wed Jan 23, 2013 7:50 pm

this is useful.
thanks.
vitaLee
 
Posts: 150
Joined: Tue Dec 27, 2011 11:10 pm

Re: NavigateSelections

Postby bizoo on Wed Feb 20, 2013 3:51 pm

A small fix and ST3 compatible:
Code: Select all
import sublime_plugin

class NavigateSelectionsCommand(sublime_plugin.WindowCommand):
    """Scroll the view up/down to the next selections"""
    def run(self, forward=True, wrap=True):
        if not self.window.active_view():
            return

        sels = self.window.active_view().sel()
        if len(sels) == 0:
            return

        visible_region = self.window.active_view().visible_region()
        if forward:
            iterator = reversed(sels)
        else:
            iterator = sels

        next_sel = None
        for s in iterator:
            if visible_region.intersects(s):
                break
            next_sel = s

        if next_sel is None and wrap:
            if forward:
                next_sel = sels[0]
            else:
                next_sel = sels[len(sels) - 1]

        if next_sel is not None:
            self.window.active_view().show(next_sel, True)
bizoo
 
Posts: 870
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland


Return to Plugin Announcements

Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 10 guests