mirror of
https://github.com/atom/atom.git
synced 2026-01-23 05:48:10 -05:00
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:
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user