Skip to content

Commit

Permalink
Remove CodeMirror-related code from Moonchild core module.
Browse files Browse the repository at this point in the history
  • Loading branch information
pdubroy committed Sep 16, 2014
1 parent a807fdc commit a8e2f77
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 24 deletions.
9 changes: 7 additions & 2 deletions editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ function $(sel) { return document.querySelector(sel); }
function $$(sel) { return document.querySelectorAll(sel); }

var nodes = {};
var codeMirror = Moonchild.createEditor($('textarea'));
var codeMirror = CodeMirror.fromTextArea($('textarea'));
codeMirror.on('change', _.debounce(editorOnChange, 250));

var moonchild = Moonchild.registerExtension();
var options = {};

function editorOnChange(cm, changeObj) {
Moonchild.onChange(cm.getValue());
}

function render(node) {
var widgetInfo = moonchild.getWidget(node);
if (widgetInfo)
Expand Down Expand Up @@ -55,6 +60,6 @@ for (var i = 0; i < controls.length; i++) {
for (var j = 0; j < controls.length; j++)
toggle(controls[j], this.classList.contains('on'));
}
Moonchild.onChange(codeMirror);
Moonchild.onChange(codeMirror.getValue());
});
}
2 changes: 1 addition & 1 deletion editor/plugins/metadata.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

codeMirror.on('cursorActivity', function triggerReparse() {
if (!containsCursor(codeMirror, node.metadata)) {
Moonchild.onChange(codeMirror);
Moonchild.onChange(codeMirror.getValue());
codeMirror.off('cursorActivity', triggerReparse);
}
});
Expand Down
15 changes: 3 additions & 12 deletions lib/moonchild-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
},{"FWaASH":4,"esprima":21,"estraverse":22,"fs":3,"underscore":24}],2:[function(_dereq_,module,exports){
// Generated by CoffeeScript 1.7.1
(function() {
var Extension, addHook, applySafely, createEditor, estraverse, expanders, exportsExpander, getHookArgs, globalExtensions, globalHooks, hooksDo, initializeExtension, onChange, parse, parser, registerExtension, widgetExpander, _;
var Extension, addHook, applySafely, estraverse, expanders, exportsExpander, getHookArgs, globalExtensions, globalHooks, hooksDo, initializeExtension, onChange, parse, parser, registerExtension, widgetExpander, _;

parser = _dereq_('./metadata');

Expand Down Expand Up @@ -223,14 +223,6 @@
return tree;
};

createEditor = function(el) {
var editor;
editor = CodeMirror.fromTextArea(el);
editor.on('change', _.debounce(onChange, 250));
editor.setValue(editor.getValue() + ' ');
return editor;
};

getHookArgs = function(ast) {
var nodes;
nodes = [];
Expand All @@ -252,10 +244,10 @@
}
};

onChange = function(cm, changeObj) {
onChange = function(newValue) {
var e, hookArgs, tree;
try {
tree = parse(globalHooks, cm.getValue());
tree = parse(globalHooks, newValue);
} catch (_error) {
e = _error;
console.log(e);
Expand All @@ -271,7 +263,6 @@
};

module.exports = {
createEditor: createEditor,
on: _.partial(addHook, null, globalHooks),
onChange: onChange,
parse: parse,
Expand Down
11 changes: 2 additions & 9 deletions moonchild.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,6 @@ parse = (hooks, source) ->
applySafely(func, hookArgs)
tree

createEditor = (el) ->
editor = CodeMirror.fromTextArea(el)
editor.on('change', _.debounce(onChange, 250))
editor.setValue(editor.getValue() + ' ') # Trigger onChange.
editor

getHookArgs = (ast) ->
# For API convenience, the tree is currently passed as an
# Underscore-wrapped list of nodes, but this should change.
Expand All @@ -118,9 +112,9 @@ applySafely = (func, args) ->
catch e
console.log e.stack || e

onChange = (cm, changeObj) ->
onChange = (newValue) ->
try
tree = parse(globalHooks, cm.getValue())
tree = parse(globalHooks, newValue)
catch e
console.log e
return
Expand All @@ -137,7 +131,6 @@ onChange = (cm, changeObj) ->
applySafely(func, hookArgs)

module.exports = {
createEditor,
on: _.partial(addHook, null, globalHooks)
onChange, # TODO: Get rid of this.
parse,
Expand Down

0 comments on commit a8e2f77

Please sign in to comment.