   CBP: -> @emit 'Cutback',       win: @id; return
   BP: -> # Toggle breakpoint
     for sel in @cm.listSelections()
-      l0 = sel.anchor.line; l1 = sel.head.line; if l0 > l1 then tmp = l0; l0 = l1; l1 = tmp
+      p0 = sel.anchor; p1 = sel.head; if p0.line > p1.line then [p0, p1] = [p1, p0]
+      l0 = p0.line; l1 = p1.line; if l0 < l1 && !p1.ch then l1--
       for l in [l0..l1] by 1
-        if (i = @bp.indexOf l) >= 0 then @bp.splice i, 1; @cm.setGutterMarker l, 'breakpoints', null
-        else @bp.push l; @cm.setGutterMarker l, 'breakpoints', @createBreakpointElement()
-    if @isTracer
-      @emit 'SetLineAttributes', win: @id, nLines: @cm.lineCount(), lineAttributes: stop: @bp[..].sort (x, y) -> x - y
+        @cm.setGutterMarker l, 'breakpoints',
+          if !@cm.getLineHandle(l).gutterMarkers?.breakpoints then @createBreakpointElement() else null
+    @isTracer && @emit 'SetLineAttributes', win: @id, nLines: @cm.lineCount(), lineAttributes: stop: @getBreakpoints()
     return
   RD: (cm) ->
     if cm.somethingSelected()

  createBreakpointElement: ->
    bp = @$e[0].ownerDocument.createElement 'div'; bp.setAttribute 'class', 'breakpoint'; bp.innerHTML = '●'; bp

  cursorActivity: ->
    if @xline != null
      n = @cm.lineCount(); l = @cm.getCursor().line

    v = @cm.getSelection() || @cword(); if v && '\n' !in v then @cmSC.setValue v; @cmRP.setValue v
    @cmRP.focus(); @cmRP.execCommand 'selectAll'; @highlightSearch(); return
  EP: ->
    v = @cm.getValue(); bp = @getBreakpoints()
    if v != @otext || '' + bp != '' + @obp
      for l in bp then @cm.setGutterMarker l, 'breakpoints', null
      @emit 'SaveChanges', win: @id, text: @cm.getValue(), attributes: stop: bp
    else
      @emit 'CloseWindow', win: @id
    return
