'use babel'

import {CompositeDisposable} from 'atom'
import {rangeKey} from './helpers'

const NUMBER_REGEXP = /\d+/g

export default class Editor {
  constructor(textEditor) {
    this.subscriptions = new CompositeDisposable()
    this.textEditor = textEditor
    this.tokensKeys = []
    this.tokens = {}
  }
  activate() {
    // This callback is invoked immediately on editor creation by Atom
    // so we don't need to call tokenize here
    this.subscriptions.add(this.textEditor.onDidStopChanging(_ => this.tokenize()))
  }
  tokenize() {
    const difference = {added: [], removed: []}
    const oldTokens = this.tokens
    const oldKeys = this.tokensKeys
    const currentKeys = []
    const currentTokens = {}

    this.textEditor.scan(NUMBER_REGEXP, match => {
      const matchRange = match.range
      const key = rangeKey(matchRange)
      currentKeys.push(key)
      currentTokens[key] = matchRange
    })

    for (const key of currentKeys) {
      if (oldKeys.indexOf(key) === -1) {
        difference.added.push(currentTokens[key])
      }
    }

    for (const key of oldKeys) {
      if (currentKeys.indexOf(key) === -1) {
        difference.removed.push(oldTokens[key])
      }
    }

    this.tokens = currentTokens
    this.tokensKeys = currentKeys

    console.log(difference)
    //this.applyDiff(difference)
  }
  dispose() {
    for (let key in this.tokens) {
      this.tokens[key].destroy()
    }
    this.tokensKeys = null
    this.textEditor = null
    this.subscriptions.dispose()
  }
}

@@ -274,39 +274,14 @@
 kens
-Keys
  = %5B%5D%0A
-    this.tokens = %7B%7D%0A
   %7D%0A
@@ -628,20 +628,38 @@
 s.tokens
-Keys
+.map(item =%3E item.key)
 %0A    con
@@ -661,26 +661,24 @@
   const 
-currentKey
+newToken
 s = %5B%5D%0A 
@@ -690,26 +690,20 @@
 nst 
-currentToken
+newKey
 s = 
-%7B%7D
+%5B%5D
 %0A%0A  
@@ -763,22 +763,17 @@
   const 
-matchR
+r
 ange = m
@@ -810,22 +810,17 @@
 angeKey(
-matchR
+r
 ange)%0A  
@@ -827,67 +827,60 @@
     
-currentKey
+newToken
 s.push(
+%7B
 key
-)%0A      currentTokens%5Bkey%5D = matchRange
+, range%7D)%0A      newKeys.push(key)
 %0A   
@@ -903,25 +903,24 @@
 nst 
-key of currentKey
+item of newToken
 s) %7B
@@ -942,32 +942,36 @@
 eys.indexOf(
+item.
 key) ==
-=
  -1) %7B%0A     
@@ -999,26 +999,12 @@
 ush(
-currentTokens%5Bkey%5D
+item
 )%0A  
@@ -1035,21 +1035,24 @@
 nst 
-key
+item
  of old
-Key
+Token
 s) %7B
@@ -1062,23 +1062,19 @@
     if (
-current
+new
 Keys.ind
@@ -1078,16 +1078,21 @@
 indexOf(
+item.
 key) ===
@@ -1134,22 +1134,12 @@
 ush(
-oldTokens%5Bkey%5D
+item
 )%0A  
@@ -1173,54 +1173,16 @@
 s = 
-currentTokens%0A    this.tokensKeys = currentKey
+newToken
 s%0A%0A 
@@ -1214,16 +1214,17 @@
 )%0A    //
+ 
 this.app

Use alternative method of diffing tokens