docSwitcher prev/next

azrafe7
2013-05-08
2013-05-08
  • azrafe7
    azrafe7
    2013-05-08

    
    

    Switch to prev/next tab in visual order (not by last active), and wrap around.

    docSwitcherLeft.py:

    from operator import itemgetter
    
    __author__ = "azrafe7"
    
    INDEX = 2
    VIEW = 3
    
    currView = notepad.getCurrentView()
    currIdx = notepad.getCurrentDocIndex(currView)
    tabsInView = filter(lambda item: item[VIEW] == currView, notepad.getFiles())
    tabsInView.sort(key=itemgetter(INDEX))
    nTabs = len(tabsInView)
    
    prevTabIdx = None
    for i, val in enumerate(tabsInView):
        if i == currIdx:
            prevTabIdx = tabsInView[(i + nTabs - 1) % nTabs][INDEX]
            break
    
    notepad.activateIndex(currView, prevTabIdx)
    
    
    

    docSwitcherRight.py:

    from operator import itemgetter
    
    __author__ = "azrafe7"
    
    INDEX = 2
    VIEW = 3
    
    currView = notepad.getCurrentView()
    currIdx = notepad.getCurrentDocIndex(currView)
    tabsInView = filter(lambda item: item[VIEW] == currView, notepad.getFiles())
    tabsInView.sort(key=itemgetter(INDEX))
    nTabs = len(tabsInView)
    
    nextTabIdx = None
    for i, val in enumerate(tabsInView):
        if i == currIdx:
            nextTabIdx = tabsInView[(i + 1) % nTabs][INDEX]
            break
    
    notepad.activateIndex(currView, nextTabIdx)
    
    
    

    EDIT: I've found out that due to what seems to be a bug these scripts won't work properly in the other view.

     
    • azrafe7
      azrafe7
      2013-05-08

      Fixed it by using BufferID instead of Index. Now works on both views:

      docSwitcherLeft.py
      docSwitcherRight.py