mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2025-01-08 08:07:32 +03:00
Unmount TextEditorComponent when TextEditorElement is detached
Fixes #4381 Fixes #4700
This commit is contained in:
parent
03468e405a
commit
180725799a
@ -42,9 +42,12 @@ describe "TextEditorElement", ->
|
|||||||
|
|
||||||
component = element.component
|
component = element.component
|
||||||
expect(component.isMounted()).toBe true
|
expect(component.isMounted()).toBe true
|
||||||
element.getModel().destroy()
|
element.remove()
|
||||||
expect(component.isMounted()).toBe false
|
expect(component.isMounted()).toBe false
|
||||||
|
|
||||||
|
jasmine.attachToDOM(element)
|
||||||
|
expect(element.component.isMounted()).toBe true
|
||||||
|
|
||||||
describe "when the editor.useShadowDOM config option is false", ->
|
describe "when the editor.useShadowDOM config option is false", ->
|
||||||
it "mounts the react component and unmounts when removed from the dom", ->
|
it "mounts the react component and unmounts when removed from the dom", ->
|
||||||
atom.config.set('editor.useShadowDOM', false)
|
atom.config.set('editor.useShadowDOM', false)
|
||||||
|
@ -67,6 +67,7 @@ class TextEditorElement extends HTMLElement
|
|||||||
@emitter.emit("did-attach")
|
@emitter.emit("did-attach")
|
||||||
|
|
||||||
detachedCallback: ->
|
detachedCallback: ->
|
||||||
|
@unmountComponent()
|
||||||
@emitter.emit("did-detach")
|
@emitter.emit("did-detach")
|
||||||
|
|
||||||
initialize: (model) ->
|
initialize: (model) ->
|
||||||
|
@ -62,6 +62,7 @@ class WorkspaceView extends View
|
|||||||
return atom.views.getView(atom.workspace).__spacePenView
|
return atom.views.getView(atom.workspace).__spacePenView
|
||||||
super
|
super
|
||||||
@deprecateViewEvents()
|
@deprecateViewEvents()
|
||||||
|
@attachedEditorViews = new WeakSet
|
||||||
|
|
||||||
setModel: (@model) ->
|
setModel: (@model) ->
|
||||||
@horizontal = @find('atom-workspace-axis.horizontal')
|
@horizontal = @find('atom-workspace-axis.horizontal')
|
||||||
@ -95,10 +96,17 @@ class WorkspaceView extends View
|
|||||||
# Returns a subscription object with an `.off` method that you can call to
|
# Returns a subscription object with an `.off` method that you can call to
|
||||||
# unregister the callback.
|
# unregister the callback.
|
||||||
eachEditorView: (callback) ->
|
eachEditorView: (callback) ->
|
||||||
callback(editorView) for editorView in @getEditorViews()
|
for editorView in @getEditorViews()
|
||||||
attachedCallback = (e, editorView) ->
|
@attachedEditorViews.add(editorView)
|
||||||
callback(editorView) unless editorView.mini
|
callback(editorView)
|
||||||
|
|
||||||
|
attachedCallback = (e, editorView) =>
|
||||||
|
unless @attachedEditorViews.has(editorView)
|
||||||
|
@attachedEditorViews.add(editorView)
|
||||||
|
callback(editorView) unless editorView.mini
|
||||||
|
|
||||||
@on('editor:attached', attachedCallback)
|
@on('editor:attached', attachedCallback)
|
||||||
|
|
||||||
off: => @off('editor:attached', attachedCallback)
|
off: => @off('editor:attached', attachedCallback)
|
||||||
|
|
||||||
# Essential: Register a function to be called for every current and future
|
# Essential: Register a function to be called for every current and future
|
||||||
|
Loading…
Reference in New Issue
Block a user