   groupThangs: (thangs) ->
     # array of thangs -> foldered thangs
     grouped = {}
-    for thang in thangs
+    for thang, index in thangs
       path = @folderForThang(thang)
       obj = grouped
       for key in path
         obj[key] ?= {}
         obj = obj[key]
       obj[thang.id] = thang
+      thang.index = index
     grouped
     
   folderForThang: (thang) ->

      format: 'thangs-folder'
      additionalProperties: {
        anyOf: [
          Level.schema.properties.thangs.items
          { $ref: '#' }
        ]
      }


  onThangsChanged: =>
    return if @hush

    # keep the thangs in the same order as before, roughly
    thangs = @flattenThangs(@thangsTreema.data)
    thangs = $.extend true, [], thangs
    thangs = _.sortBy thangs, 'index'
    delete thang.index for thang in thangs

    @level.set 'thangs', thangs
    return if @editThangView
    serializedLevel = @level.serialize @supermodel, null, true
    try
