         sessionKey : drawing.sessionKey
         indexKey   : indexKey
 
+    @registerPaneRemoveListener_ pane
+
+  registerPaneRemoveListener_: (pane) ->
+    pane.on "KDObjectWillBeDestroyed", =>
+      paneIndexKey = pane.getOptions().indexKey
+
+      @keysRef.once "value", (snapshot) =>
+        data = snapshot.val()
+        return unless data
+
+        for key, value of data
+          if value.indexKey is paneIndexKey
+            @keysRef.child(key).remove()
 
   createEditor: (file, content = "", sessionKey, indexKey) ->
     isLocal  = not file

        indexKey  : indexKey

    @workspace.addToHistory "$0 opened a new browser"

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

            vmName   : KD.getSingleton("vmController").defaultVmName

    @workspace.addToHistory "$0 opened a new terminal"
    @registerPaneRemoveListener_ pane

  createPreview: (sessionKey, indexKey) ->
    indexKey = indexKey or @createSessionKey()
