       result.invalidate()
 
   @forLines: (ed, start, end, type = 'any') ->
-    ed.findMarkers().filter((m) -> m.result? &&
-                                   m.getBufferRange().intersectsRowRange(start, end) &&
-                                  (m.result.type == type || type == 'any'))
-                    .map((m) -> m.result)
+    layers[ed.id]?.findMarkers(intersectsBufferRowRange: [start, end])
+                  .filter((m) -> (m.result.type == type || type == 'any'))
+                  .map((m) -> m.result)
 
   @removeLines: (ed, start, end, type = 'any') ->
     rs = @forLines(ed, start, end, type)
+    return unless rs?
     rs.map (r) -> r.remove()
     rs.length > 0
 
   @removeAll: (ed = atom.workspace.getActiveTextEditor()) ->
-    ed?.findMarkers().filter((m) -> m.result?).map((m) -> m.result.remove())
+    layers[ed.id]?.getMarkers().map((m) -> m.result.remove())
 
   @removeCurrent: (e) ->
     if (ed = atom.workspace.getActiveTextEditor())


metrics = throttle metrics, 60*60*1000

resultEditorRegistry = {}

module.exports =
class Result

  @all: -> # TODO: scope selector
    results = []
    for item in atom.workspace.getPaneItems() when atom.workspace.isTextEditor item
      layers[item.id]?.getMarkers().forEach (m) ->
        results.push m.result
    results

