Skip to content

Commit

Permalink
Upgrade vendored assets to CodeMirror 4.13
Browse files Browse the repository at this point in the history
  • Loading branch information
fixlr committed Feb 28, 2015
1 parent 734b93c commit 49fb55a
Show file tree
Hide file tree
Showing 25 changed files with 1,474 additions and 322 deletions.
2 changes: 1 addition & 1 deletion lib/codemirror/rails/version.rb
@@ -1,6 +1,6 @@
module Codemirror
module Rails
VERSION = '4.12'
CODEMIRROR_VERSION = '4.12'
CODEMIRROR_VERSION = '4.13'
end
end
67 changes: 45 additions & 22 deletions vendor/assets/javascripts/codemirror.js
Expand Up @@ -110,6 +110,7 @@
for (var opt in optionHandlers) if (optionHandlers.hasOwnProperty(opt))
optionHandlers[opt](this, options[opt], Init);
maybeUpdateLineNumberWidth(this);
if (options.finishInit) options.finishInit(this);
for (var i = 0; i < initHooks.length; ++i) initHooks[i](this);
endOperation(this);
// Suppress optimizelegibility in Webkit, since it breaks text
Expand Down Expand Up @@ -649,8 +650,18 @@
this.oldDisplayWidth = displayWidth(cm);
this.force = force;
this.dims = getDimensions(cm);
this.events = [];
}

DisplayUpdate.prototype.signal = function(emitter, type) {
if (hasHandler(emitter, type))
this.events.push(arguments);
};
DisplayUpdate.prototype.finish = function() {
for (var i = 0; i < this.events.length; i++)
signal.apply(null, this.events[i]);
};

function maybeClipScrollbars(cm) {
var display = cm.display;
if (!display.scrollbarsClipped && display.scroller.offsetWidth) {
Expand Down Expand Up @@ -761,9 +772,9 @@
updateScrollbars(cm, barMeasure);
}

signalLater(cm, "update", cm);
update.signal(cm, "update", cm);
if (cm.display.viewFrom != cm.display.reportedViewFrom || cm.display.viewTo != cm.display.reportedViewTo) {
signalLater(cm, "viewportChange", cm, cm.display.viewFrom, cm.display.viewTo);
update.signal(cm, "viewportChange", cm, cm.display.viewFrom, cm.display.viewTo);
cm.display.reportedViewFrom = cm.display.viewFrom; cm.display.reportedViewTo = cm.display.viewTo;
}
}
Expand All @@ -777,6 +788,7 @@
updateSelection(cm);
setDocumentHeight(cm, barMeasure);
updateScrollbars(cm, barMeasure);
update.finish();
}
}

Expand Down Expand Up @@ -2237,6 +2249,8 @@
// Fire change events, and delayed event handlers
if (op.changeObjs)
signal(cm, "changes", cm, op.changeObjs);
if (op.update)
op.update.finish();
}

// Run the given function in an operation
Expand Down Expand Up @@ -2611,8 +2625,10 @@
}

function focusInput(cm) {
if (cm.options.readOnly != "nocursor" && (!mobile || activeElt() != cm.display.input))
cm.display.input.focus();
if (cm.options.readOnly != "nocursor" && (!mobile || activeElt() != cm.display.input)) {
try { cm.display.input.focus(); }
catch (e) {} // IE8 will throw if the textarea is display: none or not in DOM
}
}

function ensureFocus(cm) {
Expand Down Expand Up @@ -5121,7 +5137,7 @@
// FROMTEXTAREA

CodeMirror.fromTextArea = function(textarea, options) {
if (!options) options = {};
options = options ? copyObj(options) : {};
options.value = textarea.value;
if (!options.tabindex && textarea.tabindex)
options.tabindex = textarea.tabindex;
Expand Down Expand Up @@ -5152,23 +5168,26 @@
}
}

options.finishInit = function(cm) {
cm.save = save;
cm.getTextArea = function() { return textarea; };
cm.toTextArea = function() {
cm.toTextArea = isNaN; // Prevent this from being ran twice
save();
textarea.parentNode.removeChild(cm.getWrapperElement());
textarea.style.display = "";
if (textarea.form) {
off(textarea.form, "submit", save);
if (typeof textarea.form.submit == "function")
textarea.form.submit = realSubmit;
}
};
};

textarea.style.display = "none";
var cm = CodeMirror(function(node) {
textarea.parentNode.insertBefore(node, textarea.nextSibling);
}, options);
cm.save = save;
cm.getTextArea = function() { return textarea; };
cm.toTextArea = function() {
cm.toTextArea = isNaN; // Prevent this from being ran twice
save();
textarea.parentNode.removeChild(cm.getWrapperElement());
textarea.style.display = "";
if (textarea.form) {
off(textarea.form, "submit", save);
if (typeof textarea.form.submit == "function")
textarea.form.submit = realSubmit;
}
};
return cm;
};

Expand Down Expand Up @@ -6179,6 +6198,7 @@
function defaultSpecialCharPlaceholder(ch) {
var token = elt("span", "\u2022", "cm-invalidchar");
token.title = "\\u" + ch.charCodeAt(0).toString(16);
token.setAttribute("aria-label", token.title);
return token;
}

Expand Down Expand Up @@ -6212,6 +6232,7 @@
if (m[0] == "\t") {
var tabSize = builder.cm.options.tabSize, tabWidth = tabSize - builder.col % tabSize;
var txt = content.appendChild(elt("span", spaceStr(tabWidth), "cm-tab"));
txt.setAttribute("role", "presentation");
builder.col += tabWidth;
} else {
var txt = builder.cm.options.specialCharPlaceholder(m[0]);
Expand Down Expand Up @@ -7576,12 +7597,14 @@
return removeChildren(parent).appendChild(e);
}

function contains(parent, child) {
var contains = CodeMirror.contains = function(parent, child) {
if (parent.contains)
return parent.contains(child);
while (child = child.parentNode)
while (child = child.parentNode) {
if (child.nodeType == 11) child = child.host;
if (child == parent) return true;
}
}
};

function activeElt() { return document.activeElement; }
// Older versions of IE throws unspecified error when touching
Expand Down Expand Up @@ -8039,7 +8062,7 @@

// THE END

CodeMirror.version = "4.12.0";
CodeMirror.version = "4.13.0";

return CodeMirror;
});
Expand Up @@ -10,6 +10,7 @@
mod(CodeMirror);
})(function(CodeMirror) {
var DEFAULT_BRACKETS = "()[]{}''\"\"";
var DEFAULT_TRIPLES = "'\"";
var DEFAULT_EXPLODE_ON_ENTER = "[]{}";
var SPACE_CHAR_REGEX = /\s/;

Expand All @@ -19,13 +20,14 @@
if (old != CodeMirror.Init && old)
cm.removeKeyMap("autoCloseBrackets");
if (!val) return;
var pairs = DEFAULT_BRACKETS, explode = DEFAULT_EXPLODE_ON_ENTER;
var pairs = DEFAULT_BRACKETS, triples = DEFAULT_TRIPLES, explode = DEFAULT_EXPLODE_ON_ENTER;
if (typeof val == "string") pairs = val;
else if (typeof val == "object") {
if (val.pairs != null) pairs = val.pairs;
if (val.triples != null) triples = val.triples;
if (val.explode != null) explode = val.explode;
}
var map = buildKeymap(pairs);
var map = buildKeymap(pairs, triples);
if (explode) map.Enter = buildExplodeHandler(explode);
cm.addKeyMap(map);
});
Expand All @@ -52,7 +54,7 @@
}
}

function buildKeymap(pairs) {
function buildKeymap(pairs, triples) {
var map = {
name : "autoCloseBrackets",
Backspace: function(cm) {
Expand Down Expand Up @@ -85,7 +87,7 @@
curType = "skipThree";
else
curType = "skip";
} else if (left == right && cur.ch > 1 &&
} else if (left == right && cur.ch > 1 && triples.indexOf(left) >= 0 &&
cm.getRange(Pos(cur.line, cur.ch - 2), cur) == left + left &&
(cur.ch <= 2 || cm.getRange(Pos(cur.line, cur.ch - 3), Pos(cur.line, cur.ch - 2)) != left)) {
curType = "addFour";
Expand Down
Expand Up @@ -131,7 +131,7 @@

function autoCloseSlash(cm) {
if (cm.getOption("disableInput")) return CodeMirror.Pass;
autoCloseCurrent(cm, true);
return autoCloseCurrent(cm, true);
}

CodeMirror.commands.closeTag = function(cm) { return autoCloseCurrent(cm); };
Expand Down
16 changes: 12 additions & 4 deletions vendor/assets/javascripts/codemirror/addons/fold/foldgutter.js
Expand Up @@ -94,20 +94,26 @@
}

function onGutterClick(cm, line, gutter) {
var opts = cm.state.foldGutter.options;
var state = cm.state.foldGutter;
if (!state) return;
var opts = state.options;
if (gutter != opts.gutter) return;
cm.foldCode(Pos(line, 0), opts.rangeFinder);
}

function onChange(cm) {
var state = cm.state.foldGutter, opts = cm.state.foldGutter.options;
var state = cm.state.foldGutter;
if (!state) return;
var opts = state.options;
state.from = state.to = 0;
clearTimeout(state.changeUpdate);
state.changeUpdate = setTimeout(function() { updateInViewport(cm); }, opts.foldOnChangeTimeSpan || 600);
}

function onViewportChange(cm) {
var state = cm.state.foldGutter, opts = cm.state.foldGutter.options;
var state = cm.state.foldGutter;
if (!state) return;
var opts = state.options;
clearTimeout(state.changeUpdate);
state.changeUpdate = setTimeout(function() {
var vp = cm.getViewport();
Expand All @@ -129,7 +135,9 @@
}

function onFold(cm, from) {
var state = cm.state.foldGutter, line = from.line;
var state = cm.state.foldGutter;
if (!state) return;
var line = from.line;
if (line >= state.from && line < state.to)
updateFoldInfo(cm, line, line + 1);
}
Expand Down
23 changes: 14 additions & 9 deletions vendor/assets/javascripts/codemirror/addons/hint/show-hint.js
Expand Up @@ -24,6 +24,18 @@
return cm.showHint(newOpts);
};

var asyncRunID = 0;
function retrieveHints(getter, cm, options, then) {
if (getter.async) {
var id = ++asyncRunID;
getter(cm, function(hints) {
if (asyncRunID == id) then(hints);
}, options);
} else {
then(getter(cm, options));
}
}

CodeMirror.defineExtension("showHint", function(options) {
// We want a single cursor position.
if (this.listSelections().length > 1 || this.somethingSelected()) return;
Expand All @@ -34,10 +46,7 @@
if (!getHints) return;

CodeMirror.signal(this, "startCompletion", this);
if (getHints.async)
getHints(this, function(hints) { completion.showHints(hints); }, completion.options);
else
return completion.showHints(getHints(this, completion.options));
return retrieveHints(getHints, this, completion.options, function(hints) { completion.showHints(hints); });
});

function Completion(cm, options) {
Expand Down Expand Up @@ -102,11 +111,7 @@
function update() {
if (finished) return;
CodeMirror.signal(data, "update");
var getHints = completion.options.hint;
if (getHints.async)
getHints(completion.cm, finishUpdate, completion.options);
else
finishUpdate(getHints(completion.cm, completion.options));
retrieveHints(completion.options.hint, completion.cm, completion.options, finishUpdate);
}
function finishUpdate(data_) {
data = data_;
Expand Down

0 comments on commit 49fb55a

Please sign in to comment.