From 0841961fc7f43bca7bd360fdc7a69caef7de2fe2 Mon Sep 17 00:00:00 2001 From: nightwing Date: Sun, 19 Feb 2017 15:52:14 +0400 Subject: [PATCH] handle misformed tabstate --- plugins/c9.ide.editors/tabmanager.js | 9 ++++++-- plugins/c9.ide.editors/tabmanager_test.js | 25 ++++++++++++++--------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/plugins/c9.ide.editors/tabmanager.js b/plugins/c9.ide.editors/tabmanager.js index 73b8d27d..2a974f48 100644 --- a/plugins/c9.ide.editors/tabmanager.js +++ b/plugins/c9.ide.editors/tabmanager.js @@ -498,8 +498,13 @@ define(function(require, module, exports) { state.pane = panes[i]; } if (!state.pane) { - throw new Error("Called open too early. Please wait until " - + "a pane is available. Use the ready event."); + if (isReady) { + state.pane = createPane({}); + container.appendChild(state.pane.aml); + } else { + throw new Error("Called open too early. Please wait until " + + "a pane is available. Use the ready event."); + } } } diff --git a/plugins/c9.ide.editors/tabmanager_test.js b/plugins/c9.ide.editors/tabmanager_test.js index 8c3d8b62..6f08e9f8 100644 --- a/plugins/c9.ide.editors/tabmanager_test.js +++ b/plugins/c9.ide.editors/tabmanager_test.js @@ -54,16 +54,6 @@ require(["lib/architect/architect", "lib/chai/chai"], }, "plugins/c9.fs/fs.cache.xml", - // Mock plugins - { - consumes: ["apf", "ui", "Plugin"], - provides: [ - "commands", "menus", "commands", "layout", "watcher", "proc", - "save", "anims", "clipboard", "dialog.alert", "auth.bootstrap", - "info", "dialog.error" - ], - setup: expect.html.mocked - }, { consumes: ["tabManager", "ui", "fs.cache", "fs"], provides: [], @@ -112,6 +102,21 @@ require(["lib/architect/architect", "lib/chai/chai"], var text; describe("open(), openFile(), openEditor() and reload()", function() { + it('should recover from state with no panes', function(done) { + var oldState = tabs.getState(); + tabs.setState({ + "nodes": [], + "type": "hsplitbox" + }, function() {}); + tabs.openEditor("timeview", function(err, tab) { + expect(tabs.getTabs()).length(1); + + expect(tabs.focussedTab) + .to.exist + .to.equal(tab); + tabs.setState(oldState, done); + }); + }); it('should open a pane from a path', function(done) { var vpath = "/file.txt"; tabs.openFile(vpath, function(err, tab) {