Ctrl+ tab to switch between tabs like in any other editor


#1

[I saw many issues like that around, but didn’t find one that describe what I;m looking for exactly. If you know about one, please link to it and I will close my issue.]

this is the one piece of functionality the is really missing for me in atom the it is the one thing that keep it from becoming my go-to editor :smile:

In most editors/IDEs the behavior of switching between tabs is:

  • pressing ctrl + tab the first time -->
  • a switcher window is shown with a list of opened tabs
  • you can toggle between the tabs in the list by holding the ctrl key and pressing the tab key again and again
  • the window stays open as long as you are holding the ctrl key
  • when you leave the ctrl key, the tab you are on in the list is shown
  • pressing `ctrl+shift+tab gives the same functionality the you toggle between the tabs in reverse

is there any package you know or any way to implement the same functionality in atom?

thanks.


#2

enhanced-tabs implements tab switching with Ctrl-Tab. I don’t know if it covers all your points though.


#3

Edit: seems I was slow, the package mentioned in the previous post is probably better suited. Leaving my post here in case anyone finds it useful.

Quickly put a minimal example together, probably much better suited as a package, but hopefully it can help you get started:

Put the following in your init.coffee:

{SelectListView} = require 'atom'

class TabView extends SelectListView

  initialize: ->
    super
    @addClass 'overlay from-top'
    @setItems atom.workspace.getPaneItems()

  getFilterKey: ->
    'name'

  viewForItem: (tab) ->
    element = document.createElement 'li'
    element.textContent = "#{tab.getTitle()}"
    element

  cancelled: ->
    @panel?.destroy()

  confirmed: (tab) ->
    atom.workspace.getActivePane().activateItemAtIndex (index for item, index in @items when item.getTitle() == tab.getTitle())[0]
    @cancel()

  attach: ->
    @panel ?= atom.workspace.addModalPanel(item: this)
    @focusFilterEditor()

atom.commands.add 'atom-text-editor',
  'tabview:show', ->
    new TabView().attach()

Bind tabview:show to your favorite hotkey, or access it via the command palette.

Very minimal and obviously lacking some features you’d like, but I hope it gives you a starting point. You may want to create a custom view instead of the SelectListView. Could possibly provide a preview by rendering the file like the Minimap package does?


#4

wow! this does exactly what I need!
thanks a-lot, and respect for for @js-padavan this amazing package!


#5

thanks for posting the solution.
I’m going with enhanced-tabs for now though :smile: