From 0d96a82e167a78f362ca06c4ddf3d9d8469c502e Mon Sep 17 00:00:00 2001 From: Jason Rudolph Date: Thu, 7 Dec 2017 11:18:35 -0500 Subject: [PATCH] Refollow host when they close last remote editor on guest --- lib/guest-portal-binding.js | 27 +++++++++++++++++---------- test/guest-portal-binding.test.js | 24 ++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/lib/guest-portal-binding.js b/lib/guest-portal-binding.js index f2ab4f5b..5458f2f4 100644 --- a/lib/guest-portal-binding.js +++ b/lib/guest-portal-binding.js @@ -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 @@ -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) @@ -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) { diff --git a/test/guest-portal-binding.test.js b/test/guest-portal-binding.test.js index 06867675..cbed2ff6 100644 --- a/test/guest-portal-binding.test.js +++ b/test/guest-portal-binding.test.js @@ -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})