Skip to content
This repository has been archived by the owner on Apr 6, 2021. It is now read-only.

Allow plugins that modify Ace to extend session state #377

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions plugins/c9.ide.ace/ace.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -1639,7 +1655,7 @@ define(function(require, exports, module) {
* @readonly
*/
get gutterContextMenu(){ draw(); return mnuGutter },

/**
* Ace Themes
* @property {Object} themese
Expand Down Expand Up @@ -1953,7 +1969,7 @@ define(function(require, exports, module) {
renderer.$updateSizeAsync();
}
}

function getState(doc, state, filter) {
if (filter) return;

Expand Down Expand Up @@ -2001,6 +2017,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 serializerExtensions) {
state.extensionData[key] = serializerExtensions[key](session, doc);
}
}

function setState(doc, state) {
Expand Down Expand Up @@ -2087,6 +2110,13 @@ define(function(require, exports, module) {
ace.on("changeSession", listen);
session.on("unload", clean);
}

// Any additional state given by ace extensions
for (key in deserializerExtensions) {
if ('extensionData' in state && key in state.extensionData) {
deserializerExtensions[key](state.extensionData[key], doc.getSession().session);
}
}
}

function scrollTo(row, column, select, session) {
Expand Down Expand Up @@ -2739,6 +2769,7 @@ define(function(require, exports, module) {
* @param {Number} [state.jump.select.column] The column to select to (0 based)
*/
plugin.freezePublicAPI({

/**
* @ignore
*/
Expand Down