';
9 | return dialog;
10 | }
11 |
12 | CodeMirror.defineExtension("openDialog", function(template, callback) {
13 | var dialog = dialogDiv(this, template);
14 | var closed = false, me = this;
15 | function close() {
16 | if (closed) return;
17 | closed = true;
18 | dialog.parentNode.removeChild(dialog);
19 | }
20 | var inp = dialog.getElementsByTagName("input")[0], button;
21 | if (inp) {
22 | CodeMirror.connect(inp, "keydown", function(e) {
23 | if (e.keyCode == 13 || e.keyCode == 27) {
24 | CodeMirror.e_stop(e);
25 | close();
26 | me.focus();
27 | if (e.keyCode == 13) callback(inp.value);
28 | }
29 | });
30 | inp.focus();
31 | CodeMirror.connect(inp, "blur", close);
32 | } else if (button = dialog.getElementsByTagName("button")[0]) {
33 | CodeMirror.connect(button, "click", function() {
34 | close();
35 | me.focus();
36 | });
37 | button.focus();
38 | CodeMirror.connect(button, "blur", close);
39 | }
40 | return close;
41 | });
42 |
43 | CodeMirror.defineExtension("openConfirm", function(template, callbacks) {
44 | var dialog = dialogDiv(this, template);
45 | var buttons = dialog.getElementsByTagName("button");
46 | var closed = false, me = this, blurring = 1;
47 | function close() {
48 | if (closed) return;
49 | closed = true;
50 | dialog.parentNode.removeChild(dialog);
51 | me.focus();
52 | }
53 | buttons[0].focus();
54 | for (var i = 0; i < buttons.length; ++i) {
55 | var b = buttons[i];
56 | (function(callback) {
57 | CodeMirror.connect(b, "click", function(e) {
58 | CodeMirror.e_preventDefault(e);
59 | close();
60 | if (callback) callback(me);
61 | });
62 | })(callbacks[i]);
63 | CodeMirror.connect(b, "blur", function() {
64 | --blurring;
65 | setTimeout(function() { if (blurring <= 0) close(); }, 200);
66 | });
67 | CodeMirror.connect(b, "focus", function() { ++blurring; });
68 | }
69 | });
70 | })();
--------------------------------------------------------------------------------
/talks/jsconfeu2012/codemirror/lib/util/loadmode.js:
--------------------------------------------------------------------------------
1 | (function() {
2 | if (!CodeMirror.modeURL) CodeMirror.modeURL = "../mode/%N/%N.js";
3 |
4 | var loading = {};
5 | function splitCallback(cont, n) {
6 | var countDown = n;
7 | return function() { if (--countDown == 0) cont(); };
8 | }
9 | function ensureDeps(mode, cont) {
10 | var deps = CodeMirror.modes[mode].dependencies;
11 | if (!deps) return cont();
12 | var missing = [];
13 | for (var i = 0; i < deps.length; ++i) {
14 | if (!CodeMirror.modes.hasOwnProperty(deps[i]))
15 | missing.push(deps[i]);
16 | }
17 | if (!missing.length) return cont();
18 | var split = splitCallback(cont, missing.length);
19 | for (var i = 0; i < missing.length; ++i)
20 | CodeMirror.requireMode(missing[i], split);
21 | }
22 |
23 | CodeMirror.requireMode = function(mode, cont) {
24 | if (typeof mode != "string") mode = mode.name;
25 | if (CodeMirror.modes.hasOwnProperty(mode)) return ensureDeps(mode, cont);
26 | if (loading.hasOwnProperty(mode)) return loading[mode].push(cont);
27 |
28 | var script = document.createElement("script");
29 | script.src = CodeMirror.modeURL.replace(/%N/g, mode);
30 | var others = document.getElementsByTagName("script")[0];
31 | others.parentNode.insertBefore(script, others);
32 | var list = loading[mode] = [cont];
33 | var count = 0, poll = setInterval(function() {
34 | if (++count > 100) return clearInterval(poll);
35 | if (CodeMirror.modes.hasOwnProperty(mode)) {
36 | clearInterval(poll);
37 | loading[mode] = null;
38 | ensureDeps(mode, function() {
39 | for (var i = 0; i < list.length; ++i) list[i]();
40 | });
41 | }
42 | }, 200);
43 | };
44 |
45 | CodeMirror.autoLoadMode = function(instance, mode) {
46 | if (!CodeMirror.modes.hasOwnProperty(mode))
47 | CodeMirror.requireMode(mode, function() {
48 | instance.setOption("mode", instance.getOption("mode"));
49 | });
50 | };
51 | }());
52 |
--------------------------------------------------------------------------------
/talks/jsconfeu2012/codemirror/lib/util/match-highlighter.js:
--------------------------------------------------------------------------------
1 | // Define match-highlighter commands. Depends on searchcursor.js
2 | // Use by attaching the following function call to the onCursorActivity event:
3 | //myCodeMirror.matchHighlight(minChars);
4 | // And including a special span.CodeMirror-matchhighlight css class (also optionally a separate one for .CodeMirror-focused -- see demo matchhighlighter.html)
5 |
6 | (function() {
7 | var DEFAULT_MIN_CHARS = 2;
8 |
9 | function MatchHighlightState() {
10 | this.marked = [];
11 | }
12 | function getMatchHighlightState(cm) {
13 | return cm._matchHighlightState || (cm._matchHighlightState = new MatchHighlightState());
14 | }
15 |
16 | function clearMarks(cm) {
17 | var state = getMatchHighlightState(cm);
18 | for (var i = 0; i < state.marked.length; ++i)
19 | state.marked[i].clear();
20 | state.marked = [];
21 | }
22 |
23 | function markDocument(cm, className, minChars) {
24 | clearMarks(cm);
25 | minChars = (typeof minChars !== 'undefined' ? minChars : DEFAULT_MIN_CHARS);
26 | if (cm.somethingSelected() && cm.getSelection().replace(/^\s+|\s+$/g, "").length >= minChars) {
27 | var state = getMatchHighlightState(cm);
28 | var query = cm.getSelection();
29 | cm.operation(function() {
30 | if (cm.lineCount() < 2000) { // This is too expensive on big documents.
31 | for (var cursor = cm.getSearchCursor(query); cursor.findNext();) {
32 | //Only apply matchhighlight to the matches other than the one actually selected
33 | if (!(cursor.from().line === cm.getCursor(true).line && cursor.from().ch === cm.getCursor(true).ch))
34 | state.marked.push(cm.markText(cursor.from(), cursor.to(), className));
35 | }
36 | }
37 | });
38 | }
39 | }
40 |
41 | CodeMirror.defineExtension("matchHighlight", function(className, minChars) {
42 | markDocument(this, className, minChars);
43 | });
44 | })();
45 |
--------------------------------------------------------------------------------
/talks/jsconfeu2012/codemirror/lib/util/multiplex.js:
--------------------------------------------------------------------------------
1 | CodeMirror.multiplexingMode = function(outer /*, others */) {
2 | // Others should be {open, close, mode [, delimStyle]} objects
3 | var others = Array.prototype.slice.call(arguments, 1);
4 | var n_others = others.length;
5 |
6 | function indexOf(string, pattern, from) {
7 | if (typeof pattern == "string") return string.indexOf(pattern, from);
8 | var m = pattern.exec(from ? string.slice(from) : string);
9 | return m ? m.index + from : -1;
10 | }
11 |
12 | return {
13 | startState: function() {
14 | return {
15 | outer: CodeMirror.startState(outer),
16 | innerActive: null,
17 | inner: null
18 | };
19 | },
20 |
21 | copyState: function(state) {
22 | return {
23 | outer: CodeMirror.copyState(outer, state.outer),
24 | innerActive: state.innerActive,
25 | inner: state.innerActive && CodeMirror.copyState(state.innerActive.mode, state.inner)
26 | };
27 | },
28 |
29 | token: function(stream, state) {
30 | if (!state.innerActive) {
31 | var cutOff = Infinity, oldContent = stream.string;
32 | for (var i = 0; i < n_others; ++i) {
33 | var other = others[i];
34 | var found = indexOf(oldContent, other.open, stream.pos);
35 | if (found == stream.pos) {
36 | stream.match(other.open);
37 | state.innerActive = other;
38 | state.inner = CodeMirror.startState(other.mode, outer.indent ? outer.indent(state.outer, "") : 0);
39 | return other.delimStyle;
40 | } else if (found != -1 && found < cutOff) {
41 | cutOff = found;
42 | }
43 | }
44 | if (cutOff != Infinity) stream.string = oldContent.slice(0, cutOff);
45 | var outerToken = outer.token(stream, state.outer);
46 | if (cutOff != Infinity) stream.string = oldContent;
47 | return outerToken;
48 | } else {
49 | var curInner = state.innerActive, oldContent = stream.string;
50 | var found = indexOf(oldContent, curInner.close, stream.pos);
51 | if (found == stream.pos) {
52 | stream.match(curInner.close);
53 | state.innerActive = state.inner = null;
54 | return curInner.delimStyle;
55 | }
56 | if (found > -1) stream.string = oldContent.slice(0, found);
57 | var innerToken = curInner.mode.token(stream, state.inner);
58 | if (found > -1) stream.string = oldContent;
59 | var cur = stream.current(), found = cur.indexOf(curInner.close);
60 | if (found > -1) stream.backUp(cur.length - found);
61 | return innerToken;
62 | }
63 | },
64 |
65 | indent: function(state, textAfter) {
66 | var mode = state.innerActive ? state.innerActive.mode : outer;
67 | if (!mode.indent) return CodeMirror.Pass;
68 | return mode.indent(state.innerActive ? state.inner : state.outer, textAfter);
69 | },
70 |
71 | electricChars: outer.electricChars,
72 |
73 | innerMode: function(state) {
74 | return state.inner ? {state: state.inner, mode: state.innerActive.mode} : {state: state.outer, mode: outer};
75 | }
76 | };
77 | };
78 |
--------------------------------------------------------------------------------
/talks/jsconfeu2012/codemirror/lib/util/overlay.js:
--------------------------------------------------------------------------------
1 | // Utility function that allows modes to be combined. The mode given
2 | // as the base argument takes care of most of the normal mode
3 | // functionality, but a second (typically simple) mode is used, which
4 | // can override the style of text. Both modes get to parse all of the
5 | // text, but when both assign a non-null style to a piece of code, the
6 | // overlay wins, unless the combine argument was true, in which case
7 | // the styles are combined.
8 |
9 | // overlayParser is the old, deprecated name
10 | CodeMirror.overlayMode = CodeMirror.overlayParser = function(base, overlay, combine) {
11 | return {
12 | startState: function() {
13 | return {
14 | base: CodeMirror.startState(base),
15 | overlay: CodeMirror.startState(overlay),
16 | basePos: 0, baseCur: null,
17 | overlayPos: 0, overlayCur: null
18 | };
19 | },
20 | copyState: function(state) {
21 | return {
22 | base: CodeMirror.copyState(base, state.base),
23 | overlay: CodeMirror.copyState(overlay, state.overlay),
24 | basePos: state.basePos, baseCur: null,
25 | overlayPos: state.overlayPos, overlayCur: null
26 | };
27 | },
28 |
29 | token: function(stream, state) {
30 | if (stream.start == state.basePos) {
31 | state.baseCur = base.token(stream, state.base);
32 | state.basePos = stream.pos;
33 | }
34 | if (stream.start == state.overlayPos) {
35 | stream.pos = stream.start;
36 | state.overlayCur = overlay.token(stream, state.overlay);
37 | state.overlayPos = stream.pos;
38 | }
39 | stream.pos = Math.min(state.basePos, state.overlayPos);
40 | if (stream.eol()) state.basePos = state.overlayPos = 0;
41 |
42 | if (state.overlayCur == null) return state.baseCur;
43 | if (state.baseCur != null && combine) return state.baseCur + " " + state.overlayCur;
44 | else return state.overlayCur;
45 | },
46 |
47 | indent: base.indent && function(state, textAfter) {
48 | return base.indent(state.base, textAfter);
49 | },
50 | electricChars: base.electricChars,
51 |
52 | innerMode: function(state) { return {state: state.base, mode: base}; }
53 | };
54 | };
55 |
--------------------------------------------------------------------------------
/talks/jsconfeu2012/codemirror/lib/util/runmode-standalone.js:
--------------------------------------------------------------------------------
1 | /* Just enough of CodeMirror to run runMode under node.js */
2 |
3 | function splitLines(string){ return string.split(/\r?\n|\r/); };
4 |
5 | function StringStream(string) {
6 | this.pos = this.start = 0;
7 | this.string = string;
8 | }
9 | StringStream.prototype = {
10 | eol: function() {return this.pos >= this.string.length;},
11 | sol: function() {return this.pos == 0;},
12 | peek: function() {return this.string.charAt(this.pos) || null;},
13 | next: function() {
14 | if (this.pos < this.string.length)
15 | return this.string.charAt(this.pos++);
16 | },
17 | eat: function(match) {
18 | var ch = this.string.charAt(this.pos);
19 | if (typeof match == "string") var ok = ch == match;
20 | else var ok = ch && (match.test ? match.test(ch) : match(ch));
21 | if (ok) {++this.pos; return ch;}
22 | },
23 | eatWhile: function(match) {
24 | var start = this.pos;
25 | while (this.eat(match)){}
26 | return this.pos > start;
27 | },
28 | eatSpace: function() {
29 | var start = this.pos;
30 | while (/[\s\u00a0]/.test(this.string.charAt(this.pos))) ++this.pos;
31 | return this.pos > start;
32 | },
33 | skipToEnd: function() {this.pos = this.string.length;},
34 | skipTo: function(ch) {
35 | var found = this.string.indexOf(ch, this.pos);
36 | if (found > -1) {this.pos = found; return true;}
37 | },
38 | backUp: function(n) {this.pos -= n;},
39 | column: function() {return this.start;},
40 | indentation: function() {return 0;},
41 | match: function(pattern, consume, caseInsensitive) {
42 | if (typeof pattern == "string") {
43 | function cased(str) {return caseInsensitive ? str.toLowerCase() : str;}
44 | if (cased(this.string).indexOf(cased(pattern), this.pos) == this.pos) {
45 | if (consume !== false) this.pos += pattern.length;
46 | return true;
47 | }
48 | }
49 | else {
50 | var match = this.string.slice(this.pos).match(pattern);
51 | if (match && consume !== false) this.pos += match[0].length;
52 | return match;
53 | }
54 | },
55 | current: function(){return this.string.slice(this.start, this.pos);}
56 | };
57 | exports.StringStream = StringStream;
58 |
59 | exports.startState = function(mode, a1, a2) {
60 | return mode.startState ? mode.startState(a1, a2) : true;
61 | };
62 |
63 | var modes = exports.modes = {}, mimeModes = exports.mimeModes = {};
64 | exports.defineMode = function(name, mode) { modes[name] = mode; };
65 | exports.defineMIME = function(mime, spec) { mimeModes[mime] = spec; };
66 | exports.getMode = function(options, spec) {
67 | if (typeof spec == "string" && mimeModes.hasOwnProperty(spec))
68 | spec = mimeModes[spec];
69 | if (typeof spec == "string")
70 | var mname = spec, config = {};
71 | else if (spec != null)
72 | var mname = spec.name, config = spec;
73 | var mfactory = modes[mname];
74 | if (!mfactory) throw new Error("Unknown mode: " + spec);
75 | return mfactory(options, config || {});
76 | };
77 |
78 | exports.runMode = function(string, modespec, callback) {
79 | var mode = exports.getMode({indentUnit: 2}, modespec);
80 | var lines = splitLines(string), state = exports.startState(mode);
81 | for (var i = 0, e = lines.length; i < e; ++i) {
82 | if (i) callback("\n");
83 | var stream = new exports.StringStream(lines[i]);
84 | while (!stream.eol()) {
85 | var style = mode.token(stream, state);
86 | callback(stream.current(), style, i, stream.start);
87 | stream.start = stream.pos;
88 | }
89 | }
90 | };
91 |
--------------------------------------------------------------------------------
/talks/jsconfeu2012/codemirror/lib/util/runmode.js:
--------------------------------------------------------------------------------
1 | CodeMirror.runMode = function(string, modespec, callback, options) {
2 | function esc(str) {
3 | return str.replace(/[<&]/, function(ch) { return ch == "<" ? "<" : "&"; });
4 | }
5 |
6 | var mode = CodeMirror.getMode(CodeMirror.defaults, modespec);
7 | var isNode = callback.nodeType == 1;
8 | var tabSize = (options && options.tabSize) || CodeMirror.defaults.tabSize;
9 | if (isNode) {
10 | var node = callback, accum = [], col = 0;
11 | callback = function(text, style) {
12 | if (text == "\n") {
13 | accum.push(" ");
14 | col = 0;
15 | return;
16 | }
17 | var escaped = "";
18 | // HTML-escape and replace tabs
19 | for (var pos = 0;;) {
20 | var idx = text.indexOf("\t", pos);
21 | if (idx == -1) {
22 | escaped += esc(text.slice(pos));
23 | col += text.length - pos;
24 | break;
25 | } else {
26 | col += idx - pos;
27 | escaped += esc(text.slice(pos, idx));
28 | var size = tabSize - col % tabSize;
29 | col += size;
30 | for (var i = 0; i < size; ++i) escaped += " ";
31 | pos = idx + 1;
32 | }
33 | }
34 |
35 | if (style)
36 | accum.push("" + escaped + "");
37 | else
38 | accum.push(escaped);
39 | };
40 | }
41 | var lines = CodeMirror.splitLines(string), state = CodeMirror.startState(mode);
42 | for (var i = 0, e = lines.length; i < e; ++i) {
43 | if (i) callback("\n");
44 | var stream = new CodeMirror.StringStream(lines[i]);
45 | while (!stream.eol()) {
46 | var style = mode.token(stream, state);
47 | callback(stream.current(), style, i, stream.start);
48 | stream.start = stream.pos;
49 | }
50 | }
51 | if (isNode)
52 | node.innerHTML = accum.join("");
53 | };
54 |
--------------------------------------------------------------------------------
/talks/jsconfeu2012/codemirror/lib/util/simple-hint.css:
--------------------------------------------------------------------------------
1 | .CodeMirror-completions {
2 | position: absolute;
3 | z-index: 10;
4 | overflow: hidden;
5 | -webkit-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
6 | -moz-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
7 | box-shadow: 2px 3px 5px rgba(0,0,0,.2);
8 | }
9 | .CodeMirror-completions select {
10 | background: #fafafa;
11 | outline: none;
12 | border: none;
13 | padding: 0;
14 | margin: 0;
15 | font-family: monospace;
16 | }
17 |
--------------------------------------------------------------------------------
/talks/jsconfeu2012/codemirror/lib/util/simple-hint.js:
--------------------------------------------------------------------------------
1 | (function() {
2 | CodeMirror.simpleHint = function(editor, getHints, givenOptions) {
3 | // Determine effective options based on given values and defaults.
4 | var options = {}, defaults = CodeMirror.simpleHint.defaults;
5 | for (var opt in defaults)
6 | if (defaults.hasOwnProperty(opt))
7 | options[opt] = (givenOptions && givenOptions.hasOwnProperty(opt) ? givenOptions : defaults)[opt];
8 |
9 | function collectHints(previousToken) {
10 | // We want a single cursor position.
11 | if (editor.somethingSelected()) return;
12 |
13 | var tempToken = editor.getTokenAt(editor.getCursor());
14 |
15 | // Don't show completions if token has changed and the option is set.
16 | if (options.closeOnTokenChange && previousToken != null &&
17 | (tempToken.start != previousToken.start || tempToken.className != previousToken.className)) {
18 | return;
19 | }
20 |
21 | var result = getHints(editor);
22 | if (!result || !result.list.length) return;
23 | var completions = result.list;
24 | function insert(str) {
25 | editor.replaceRange(str, result.from, result.to);
26 | }
27 | // When there is only one completion, use it directly.
28 | if (completions.length == 1) {insert(completions[0]); return true;}
29 |
30 | // Build the select widget
31 | var complete = document.createElement("div");
32 | complete.className = "CodeMirror-completions";
33 | var sel = complete.appendChild(document.createElement("select"));
34 | // Opera doesn't move the selection when pressing up/down in a
35 | // multi-select, but it does properly support the size property on
36 | // single-selects, so no multi-select is necessary.
37 | if (!window.opera) sel.multiple = true;
38 | for (var i = 0; i < completions.length; ++i) {
39 | var opt = sel.appendChild(document.createElement("option"));
40 | opt.appendChild(document.createTextNode(completions[i]));
41 | }
42 | sel.firstChild.selected = true;
43 | sel.size = Math.min(10, completions.length);
44 | var pos = editor.cursorCoords();
45 | complete.style.left = pos.x + "px";
46 | complete.style.top = pos.yBot + "px";
47 | document.body.appendChild(complete);
48 | // If we're at the edge of the screen, then we want the menu to appear on the left of the cursor.
49 | var winW = window.innerWidth || Math.max(document.body.offsetWidth, document.documentElement.offsetWidth);
50 | if(winW - pos.x < sel.clientWidth)
51 | complete.style.left = (pos.x - sel.clientWidth) + "px";
52 | // Hack to hide the scrollbar.
53 | if (completions.length <= 10)
54 | complete.style.width = (sel.clientWidth - 1) + "px";
55 |
56 | var done = false;
57 | function close() {
58 | if (done) return;
59 | done = true;
60 | complete.parentNode.removeChild(complete);
61 | }
62 | function pick() {
63 | insert(completions[sel.selectedIndex]);
64 | close();
65 | setTimeout(function(){editor.focus();}, 50);
66 | }
67 | CodeMirror.connect(sel, "blur", close);
68 | CodeMirror.connect(sel, "keydown", function(event) {
69 | var code = event.keyCode;
70 | // Enter
71 | if (code == 13) {CodeMirror.e_stop(event); pick();}
72 | // Escape
73 | else if (code == 27) {CodeMirror.e_stop(event); close(); editor.focus();}
74 | else if (code != 38 && code != 40 && code != 33 && code != 34) {
75 | close(); editor.focus();
76 | // Pass the event to the CodeMirror instance so that it can handle things like backspace properly.
77 | editor.triggerOnKeyDown(event);
78 | // Don't show completions if the code is backspace and the option is set.
79 | if (!options.closeOnBackspace || code != 8) {
80 | setTimeout(function(){collectHints(tempToken);}, 50);
81 | }
82 | }
83 | });
84 | CodeMirror.connect(sel, "dblclick", pick);
85 |
86 | sel.focus();
87 | // Opera sometimes ignores focusing a freshly created node
88 | if (window.opera) setTimeout(function(){if (!done) sel.focus();}, 100);
89 | return true;
90 | }
91 | return collectHints();
92 | };
93 | CodeMirror.simpleHint.defaults = {
94 | closeOnBackspace: true,
95 | closeOnTokenChange: false
96 | };
97 | })();
98 |
--------------------------------------------------------------------------------
/talks/jsconfeu2012/codemirror/lib/util/xml-hint.js:
--------------------------------------------------------------------------------
1 |
2 | (function() {
3 |
4 | CodeMirror.xmlHints = [];
5 |
6 | CodeMirror.xmlHint = function(cm, simbol) {
7 |
8 | if(simbol.length > 0) {
9 | var cursor = cm.getCursor();
10 | cm.replaceSelection(simbol);
11 | cursor = {line: cursor.line, ch: cursor.ch + 1};
12 | cm.setCursor(cursor);
13 | }
14 |
15 | // dirty hack for simple-hint to receive getHint event on space
16 | var getTokenAt = editor.getTokenAt;
17 |
18 | editor.getTokenAt = function() { return 'disabled'; };
19 | CodeMirror.simpleHint(cm, getHint);
20 |
21 | editor.getTokenAt = getTokenAt;
22 | };
23 |
24 | var getHint = function(cm) {
25 |
26 | var cursor = cm.getCursor();
27 |
28 | if (cursor.ch > 0) {
29 |
30 | var text = cm.getRange({line: 0, ch: 0}, cursor);
31 | var typed = '';
32 | var simbol = '';
33 | for(var i = text.length - 1; i >= 0; i--) {
34 | if(text[i] == ' ' || text[i] == '<') {
35 | simbol = text[i];
36 | break;
37 | }
38 | else {
39 | typed = text[i] + typed;
40 | }
41 | }
42 |
43 | text = text.slice(0, text.length - typed.length);
44 |
45 | var path = getActiveElement(cm, text) + simbol;
46 | var hints = CodeMirror.xmlHints[path];
47 |
48 | if(typeof hints === 'undefined')
49 | hints = [''];
50 | else {
51 | hints = hints.slice(0);
52 | for (var i = hints.length - 1; i >= 0; i--) {
53 | if(hints[i].indexOf(typed) != 0)
54 | hints.splice(i, 1);
55 | }
56 | }
57 |
58 | return {
59 | list: hints,
60 | from: { line: cursor.line, ch: cursor.ch - typed.length },
61 | to: cursor
62 | };
63 | };
64 | };
65 |
66 | var getActiveElement = function(codeMirror, text) {
67 |
68 | var element = '';
69 |
70 | if(text.length >= 0) {
71 |
72 | var regex = new RegExp('<([^!?][^\\s/>]*).*?>', 'g');
73 |
74 | var matches = [];
75 | var match;
76 | while ((match = regex.exec(text)) != null) {
77 | matches.push({
78 | tag: match[1],
79 | selfclose: (match[0].slice(match[0].length - 2) === '/>')
80 | });
81 | }
82 |
83 | for (var i = matches.length - 1, skip = 0; i >= 0; i--) {
84 |
85 | var item = matches[i];
86 |
87 | if (item.tag[0] == '/')
88 | {
89 | skip++;
90 | }
91 | else if (item.selfclose == false)
92 | {
93 | if (skip > 0)
94 | {
95 | skip--;
96 | }
97 | else
98 | {
99 | element = '<' + item.tag + '>' + element;
100 | }
101 | }
102 | }
103 |
104 | element += getOpenTag(text);
105 | }
106 |
107 | return element;
108 | };
109 |
110 | var getOpenTag = function(text) {
111 |
112 | var open = text.lastIndexOf('<');
113 | var close = text.lastIndexOf('>');
114 |
115 | if (close < open)
116 | {
117 | text = text.slice(open);
118 |
119 | if(text != '<') {
120 |
121 | var space = text.indexOf(' ');
122 | if(space < 0)
123 | space = text.indexOf('\t');
124 | if(space < 0)
125 | space = text.indexOf('\n');
126 |
127 | if (space < 0)
128 | space = text.length;
129 |
130 | return text.slice(0, space);
131 | }
132 | }
133 |
134 | return '';
135 | };
136 |
137 | })();
138 |
--------------------------------------------------------------------------------
/talks/jsconfeu2012/codemirror/mode/clike/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CodeMirror: C-like mode
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
CodeMirror: C-like mode
14 |
15 |
82 |
83 |
90 |
91 |
Simple mode that tries to handle C-like languages as well as it
92 | can. Takes two configuration parameters: keywords, an
93 | object whose property names are the keywords in the language,
94 | and useCPP, which determines whether C preprocessor
95 | directives are recognized.