From 87f56e078cbc5a20a3b708efd986cd1c696fb2c4 Mon Sep 17 00:00:00 2001 From: David Anthony Bau Date: Fri, 14 Oct 2016 21:28:13 +0000 Subject: [PATCH 1/2] Extensions --- plugins/c9.ide.ace/ace.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/plugins/c9.ide.ace/ace.js b/plugins/c9.ide.ace/ace.js index da0506947..a5171fa78 100644 --- a/plugins/c9.ide.ace/ace.js +++ b/plugins/c9.ide.ace/ace.js @@ -2001,6 +2001,13 @@ define(function(require, exports, module) { state: session.bgTokenizer.states[row - 1], mode: session.$mode.$id }; + + state.extensionData = {}; + + // Any additional state given by ace extensions + for (key in dataExtensionHandlers) { + state.extensionData[key] = dataExtensionHandlers[key].getState(session, doc); + } } function setState(doc, state) { @@ -2087,6 +2094,11 @@ define(function(require, exports, module) { ace.on("changeSession", listen); session.on("unload", clean); } + + // Any additional state given by ace extensions + for (key in dataExtensionHandlers) { + dataExtensionHandlers[key].setState(state.extensionData[key]); + } } function scrollTo(row, column, select, session) { @@ -2739,6 +2751,24 @@ define(function(require, exports, module) { * @param {Number} [state.jump.select.column] The column to select to (0 based) */ plugin.freezePublicAPI({ + /* + * Register a data extension handler, which will add + * extra information to a serialized Ace editor session, + * for plugins that modify the Ace editor. + */ + addDataExtensionHandler: function(name, getState, setState) { + if (name in dataExtensionHandlers) { + return false; + } + else { + dataExtensionHandlers[name] = { + getState: getState, + setState: setState + } + return true; + } + }, + /** * @ignore */ From de372dc68b7bbf4417a84d5cb2fd3ae7479b9db1 Mon Sep 17 00:00:00 2001 From: David Anthony Bau Date: Fri, 21 Oct 2016 19:56:35 +0000 Subject: [PATCH 2/2] Rework extension structure --- plugins/c9.ide.ace/ace.js | 47 ++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/plugins/c9.ide.ace/ace.js b/plugins/c9.ide.ace/ace.js index a5171fa78..aa184a1b9 100644 --- a/plugins/c9.ide.ace/ace.js +++ b/plugins/c9.ide.ace/ace.js @@ -1623,7 +1623,23 @@ define(function(require, exports, module) { * @extends Plugin * @singleton */ + + var extensionID = 0, + serializerExtensions = {}, + deserializerExtensions = {}; + handle.freezePublicAPI({ + /* + * Register a data extension handler, which will add + * extra information to a serialized Ace editor session, + * for plugins that modify the Ace editor. + */ + extendSerializedState: function(serialize, deserialize) { + var id = extensionID++; + serializerExtensions[id] = serialize; + deserializerExtensions[id] = deserialize; + }, + /** * The context menu that is displayed when right clicked in the ace * editing area. @@ -1639,7 +1655,7 @@ define(function(require, exports, module) { * @readonly */ get gutterContextMenu(){ draw(); return mnuGutter }, - + /** * Ace Themes * @property {Object} themese @@ -1953,7 +1969,7 @@ define(function(require, exports, module) { renderer.$updateSizeAsync(); } } - + function getState(doc, state, filter) { if (filter) return; @@ -2005,8 +2021,8 @@ define(function(require, exports, module) { state.extensionData = {}; // Any additional state given by ace extensions - for (key in dataExtensionHandlers) { - state.extensionData[key] = dataExtensionHandlers[key].getState(session, doc); + for (key in serializerExtensions) { + state.extensionData[key] = serializerExtensions[key](session, doc); } } @@ -2096,8 +2112,10 @@ define(function(require, exports, module) { } // Any additional state given by ace extensions - for (key in dataExtensionHandlers) { - dataExtensionHandlers[key].setState(state.extensionData[key]); + for (key in deserializerExtensions) { + if ('extensionData' in state && key in state.extensionData) { + deserializerExtensions[key](state.extensionData[key], doc.getSession().session); + } } } @@ -2751,23 +2769,6 @@ define(function(require, exports, module) { * @param {Number} [state.jump.select.column] The column to select to (0 based) */ plugin.freezePublicAPI({ - /* - * Register a data extension handler, which will add - * extra information to a serialized Ace editor session, - * for plugins that modify the Ace editor. - */ - addDataExtensionHandler: function(name, getState, setState) { - if (name in dataExtensionHandlers) { - return false; - } - else { - dataExtensionHandlers[name] = { - getState: getState, - setState: setState - } - return true; - } - }, /** * @ignore