         indexKey  : indexKey
 
     @registerPaneRemoveListener_ pane
+    @openIndexes[FSHelper.plainPath file.path] = indexKey
 
     KD.mixpanel "Teamwork tab editor, click"
 
+  handlePaneHandleClicked: (paneOptions) ->
+    {title, indexKey} = paneOptions
+    @workspace.addToHistory
+      message    : "$0 switched to #{title}"
+      by         : KD.nick()
+      data       :
+        title    : title
+        indexKey : indexKey
+
+    @indexRef.set { indexKey, by: KD.nick() }
+
   openFile: (file, content) ->
-    @createEditor file, content
+    plainPath    = FSHelper.plainPath file.path
+    paneIndexKey = @openIndexes[plainPath]
+
+    if paneIndexKey
+      for pane in @tabView.panes
+        paneOptions = pane.getOptions()
+        if paneOptions.indexKey is paneIndexKey
+          @handlePaneHandleClicked paneOptions
+    else
+      @createEditor file, content
 
   createTerminal: (sessionKey, indexKey) ->
     indexKey = indexKey or @createSessionKey()


    KD.mixpanel "Teamwork tab browser, click"

  createChat: ->
    pane = new KDTabPaneView title: "Chat"
    chat = new ChatPane


    @tabView.on "PaneAdded", (pane) =>
      pane.getHandle().on "click", =>
        @handlePaneHandleClicked pane.getOptions()

  addNewTab: ->
    @createPlusHandleDropDown()
