Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Refollow host when they close last remote editor on guest
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonrudolph authored and Antonio Scandurra committed Dec 7, 2017
1 parent 5712447 commit 0d96a82
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 10 deletions.
27 changes: 17 additions & 10 deletions lib/guest-portal-binding.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,19 @@ class GuestPortalBinding {
removeEditorProxy (editorProxy) {
this.lastEditorProxyChangePromise = this.lastEditorProxyChangePromise.then(async () => {
const editorBinding = this.editorBindingsByEditorProxy.get(editorProxy)
editorBinding.dispose()

await this.toggleEmptyPortalPaneItem()

const isRetracted = this.portal.resolveFollowState() === FollowState.RETRACTED
this.shouldRelayActiveEditorChanges = !isRetracted
editorBinding.editor.destroy()
this.shouldRelayActiveEditorChanges = true
if (editorBinding) {
editorBinding.dispose()
if (this.editorBindingsByEditorProxy.size === 0) {
this.portal.follow(1)
}

await this.toggleEmptyPortalPaneItem()

const isRetracted = this.portal.resolveFollowState() === FollowState.RETRACTED
this.shouldRelayActiveEditorChanges = !isRetracted
editorBinding.editor.destroy()
this.shouldRelayActiveEditorChanges = true
}
})

return this.lastEditorProxyChangePromise
Expand Down Expand Up @@ -137,8 +142,8 @@ class GuestPortalBinding {
this.editorBindingsByEditorProxy.set(editorProxy, editorBinding)
this.editorProxiesByEditor.set(editor, editorProxy)
editorBinding.onDidDispose(() => {
this.editorBindingsByEditorProxy.delete(editorProxy)
this.editorProxiesByEditor.delete(editor)
this.editorBindingsByEditorProxy.delete(editorProxy)
})

this.sitePositionsController.addEditorBinding(editorBinding)
Expand Down Expand Up @@ -243,7 +248,9 @@ class GuestPortalBinding {
this.sitePositionsController.hide()
}

if (this.shouldRelayActiveEditorChanges) this.portal.activateEditorProxy(editorProxy)
if (this.shouldRelayActiveEditorChanges && paneItem !== this.getEmptyPortalPaneItem()) {
this.portal.activateEditorProxy(editorProxy)
}
}

hasPaneItem (paneItem) {
Expand Down
24 changes: 24 additions & 0 deletions test/guest-portal-binding.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,30 @@ suite('GuestPortalBinding', () => {
assert(atomEnv.workspace.getActivePaneItem().getTitle().includes('editor-1'))
})

test('host closing last remote editor on guest workspace', async () => {
const portal = new FakePortal()
const client = {joinPortal: () => portal}
const atomEnv = buildAtomEnvironment()
const portalBinding = buildGuestPortalBinding(client, atomEnv, 'some-portal')

await portalBinding.initialize()
portal.setFollowState(FollowState.RETRACTED)

const editorProxy1 = new FakeEditorProxy('editor-1')
await portalBinding.updateTether(FollowState.RETRACTED, editorProxy1)

const editorProxy2 = new FakeEditorProxy('editor-2')
portal.setFollowState(FollowState.DISCONNECTED)
await portalBinding.updateTether(FollowState.DISCONNECTED)

await portalBinding.removeEditorProxy(editorProxy2)
assert.equal(portal.resolveFollowState(), FollowState.DISCONNECTED)

await portalBinding.removeEditorProxy(editorProxy1)
assert.equal(portal.getFollowedSiteId(), 1)
assert.equal(portal.resolveFollowState(), FollowState.RETRACTED)
})

test('toggling site position components visibility when switching tabs', async () => {
const stubPubSubGateway = {}
const client = new TeletypeClient({pubSubGateway: stubPubSubGateway})
Expand Down

0 comments on commit 0d96a82

Please sign in to comment.