   editInNewTab: (cutSelection) ->
     return unless editor = atom.workspace.getActiveTextEditor()
 
-    selection = editor.getLastSelection()
+    parentEditor = editor.id
+    parentSelection = editor.getLastSelection()
 
     target =
       scope: editor.getGrammar().scopeName
-      text: selection.getText()
+      text: parentSelection.getText()
 
     unless target.text.length > 0
       return atom.beep()
 
+    # Move to new Tab?
     if cutSelection is true
-      selection.delete()
+      parentSelection.delete()
 
     atom.workspace.open()
       .then (newTab) ->


module.exports = EditInNewTab =
  config:
    ignoreScope:
      title: "Ignore Scope"
      description: "Don't set the current scope in target tab"
      type: "boolean"
      default: false
      order: 1
    outputFormat:
      title: "Output Format"
      type: 'object'
      properties:
        select:
          title: "Select"
          description: "Selects the newly added text"
          type: "boolean"
          default: false
          order: 2
        autoIndent:
          title: "Auto-indent"
          description: "Indents all inserted text appropriately"
          type: "boolean"
          default: true
          order: 3
        autoIndentNewline:
          title: "Auto-indent New Line"
          description: "Indent newline appropriately"
          type: "boolean"
          default: true
          order: 4
        autoDecreaseIndent:
          title: "Auto-decreate Indent"
          description: "Decreases indent level appropriately (for example, when a closing bracket is inserted)"
          type: "boolean"
          default: true
          order: 5
        normalizeLineEndings:
          title: "Normalize Line Endings"
          type: "boolean"
          default: true
          order: 6
  subscriptions: null

  activate: (state) ->

          normalizeLineEndings: atom.config.get('edit-in-new-tab.outputFormat.normalizeLineEndings')

        newTab.insertText(target.text, options)

        unless atom.config.get('edit-in-new-tab.ignoreScope') is true
          newTab.setGrammar(atom.grammars.grammarForScopeName(target.scope))

        if atom.config.get('edit-in-new-tab.synchronizeChanges') is true and cutSelection is false
          childEditor = atom.workspace.getActiveTextEditor().id

          atom.workspace.observeTextEditors (editor) =>
            return unless editor.id is childEditor

            editor.onDidStopChanging =>
              parentSelection.insertText(editor.getText(), { select: true })

      .catch (error) ->
        atom.notifications.addError(error, dismissable: true)
