Unmount component when EditorView is detached

Fixes #3431

When a pane item is moved to another pane, we *detach* the associated
view but we don’t fully remove it. This was to prevent removing a view
when it was used as the pane item directly. However, this was causing
the editor component not to be unmounted, which caused leaks and
incorrect measurements.

We need to unmount the component, but we don’t want to destroy the
editor. So I’ve moved editor destruction to the wrapper view for now,
and I only do it when the view is actually removed.

Ultimately, we need to have a 1:1 relationship with pane items and their
views and only allow a pane item to appear once in the pane tree. Then
we can recycle the same view and avoid this confusing situation where
the old view is detached and a new view is created.
This commit is contained in:
Nathan Sobo
2014-09-03 10:53:41 -06:00
parent d753a7f38d
commit d3422786c3
2 changed files with 14 additions and 3 deletions

View File

@@ -183,12 +183,13 @@ EditorComponent = React.createClass
@checkForVisibilityChange()
componentWillUnmount: ->
@props.parentView.trigger 'editor:will-be-removed', [@props.parentView]
{editor, parentView} = @props
parentView.trigger 'editor:will-be-removed', [parentView]
@unsubscribe()
window.removeEventListener 'resize', @requestHeightAndWidthMeasurement
clearInterval(@domPollingIntervalId)
@domPollingIntervalId = null
@props.editor.destroy()
componentWillReceiveProps: (newProps) ->
@props.editor.setMini(newProps.mini)

View File

@@ -215,12 +215,22 @@ class EditorView extends View
view.css('z-index', 1)
@find('.lines').prepend(view)
detach: ->
return unless @attached
super
@attached = false
@unmountComponent()
beforeRemove: ->
return unless @attached
@attached = false
React.unmountComponentAtNode(@element) if @component.isMounted()
@unmountComponent()
@editor.destroy()
@trigger 'editor:detached', this
unmountComponent: ->
React.unmountComponentAtNode(@element) if @component.isMounted()
# Public: Split the editor view left.
splitLeft: ->
pane = @getPane()