Remove event listeners from orphaned gutters

This commit is contained in:
Antonio Scandurra
2015-06-19 10:24:48 +02:00
parent 26b1d166fd
commit d7156ff387
4 changed files with 29 additions and 1 deletions

View File

@@ -743,6 +743,16 @@ describe "TextEditorComponent", ->
beforeEach ->
gutterNode = componentNode.querySelector('.gutter')
describe "when the component is destroyed", ->
it "stops listening for folding events", ->
component.destroy()
lineNumber = component.lineNumberNodeForScreenRow(1)
target = lineNumber.querySelector('.icon-right')
target.dispatchEvent(buildClickEvent(target))
expect(nextAnimationFrame).toBe(noAnimationFrame)
it "folds and unfolds the block represented by the fold indicator when clicked", ->
expect(lineNumberHasClass(1, 'folded')).toBe false
@@ -1727,6 +1737,14 @@ describe "TextEditorComponent", ->
beforeEach ->
gutterNode = componentNode.querySelector('.gutter')
describe "when the component is destroyed", ->
it "stops listening for selection events", ->
component.destroy()
gutterNode.dispatchEvent(buildMouseEvent('mousedown', clientCoordinatesForScreenRowInGutter(1)))
expect(editor.getSelectedScreenRange()).toEqual [[0, 0], [0, 0]]
describe "when the gutter is clicked", ->
it "selects the clicked row", ->
gutterNode.dispatchEvent(buildMouseEvent('mousedown', clientCoordinatesForScreenRowInGutter(4)))

View File

@@ -16,7 +16,12 @@ class GutterContainerComponent
@domNode = document.createElement('div')
@domNode.classList.add('gutter-container')
@domNode.style.display = 'flex';
@domNode.style.display = 'flex'
destroy: ->
for {name, component} in @gutterComponents
component.destroy?()
return
getDomNode: ->
@domNode

View File

@@ -18,6 +18,10 @@ class LineNumberGutterComponent
@domNode.addEventListener 'click', @onClick
@domNode.addEventListener 'mousedown', @onMouseDown
destroy: ->
@domNode.removeEventListener 'click', @onClick
@domNode.removeEventListener 'mousedown', @onMouseDown
getDomNode: ->
@domNode

View File

@@ -106,6 +106,7 @@ class TextEditorComponent
@mounted = false
@disposables.dispose()
@presenter.destroy()
@gutterContainerComponent?.destroy()
window.removeEventListener 'resize', @requestHeightAndWidthMeasurement
getDomNode: ->