summaryrefslogtreecommitdiff
path: root/public/vendor/codemirror/addon/hint
diff options
context:
space:
mode:
Diffstat (limited to 'public/vendor/codemirror/addon/hint')
-rw-r--r--[-rwxr-xr-x]public/vendor/codemirror/addon/hint/anyword-hint.js2
-rw-r--r--[-rwxr-xr-x]public/vendor/codemirror/addon/hint/css-hint.js0
-rw-r--r--[-rwxr-xr-x]public/vendor/codemirror/addon/hint/html-hint.js0
-rw-r--r--[-rwxr-xr-x]public/vendor/codemirror/addon/hint/javascript-hint.js0
-rw-r--r--[-rwxr-xr-x]public/vendor/codemirror/addon/hint/show-hint.css0
-rw-r--r--[-rwxr-xr-x]public/vendor/codemirror/addon/hint/show-hint.js119
-rw-r--r--[-rwxr-xr-x]public/vendor/codemirror/addon/hint/sql-hint.js0
-rw-r--r--[-rwxr-xr-x]public/vendor/codemirror/addon/hint/xml-hint.js0
8 files changed, 89 insertions, 32 deletions
diff --git a/public/vendor/codemirror/addon/hint/anyword-hint.js b/public/vendor/codemirror/addon/hint/anyword-hint.js
index 8e74a920..dae78e2e 100755..100644
--- a/public/vendor/codemirror/addon/hint/anyword-hint.js
+++ b/public/vendor/codemirror/addon/hint/anyword-hint.js
@@ -21,7 +21,7 @@
while (start && word.test(curLine.charAt(start - 1))) --start;
var curWord = start != end && curLine.slice(start, end);
- var list = [], seen = {};
+ var list = options && options.list || [], seen = {};
var re = new RegExp(word.source, "g");
for (var dir = -1; dir <= 1; dir += 2) {
var line = cur.line, endLine = Math.min(Math.max(line + dir * range, editor.firstLine()), editor.lastLine()) + dir;
diff --git a/public/vendor/codemirror/addon/hint/css-hint.js b/public/vendor/codemirror/addon/hint/css-hint.js
index 22642727..22642727 100755..100644
--- a/public/vendor/codemirror/addon/hint/css-hint.js
+++ b/public/vendor/codemirror/addon/hint/css-hint.js
diff --git a/public/vendor/codemirror/addon/hint/html-hint.js b/public/vendor/codemirror/addon/hint/html-hint.js
index c6769bca..c6769bca 100755..100644
--- a/public/vendor/codemirror/addon/hint/html-hint.js
+++ b/public/vendor/codemirror/addon/hint/html-hint.js
diff --git a/public/vendor/codemirror/addon/hint/javascript-hint.js b/public/vendor/codemirror/addon/hint/javascript-hint.js
index 7bcbf4a0..7bcbf4a0 100755..100644
--- a/public/vendor/codemirror/addon/hint/javascript-hint.js
+++ b/public/vendor/codemirror/addon/hint/javascript-hint.js
diff --git a/public/vendor/codemirror/addon/hint/show-hint.css b/public/vendor/codemirror/addon/hint/show-hint.css
index 924e638f..924e638f 100755..100644
--- a/public/vendor/codemirror/addon/hint/show-hint.css
+++ b/public/vendor/codemirror/addon/hint/show-hint.css
diff --git a/public/vendor/codemirror/addon/hint/show-hint.js b/public/vendor/codemirror/addon/hint/show-hint.js
index d228fc88..cbe3b39a 100755..100644
--- a/public/vendor/codemirror/addon/hint/show-hint.js
+++ b/public/vendor/codemirror/addon/hint/show-hint.js
@@ -25,8 +25,18 @@
};
CodeMirror.defineExtension("showHint", function(options) {
- // We want a single cursor position.
- if (this.listSelections().length > 1 || this.somethingSelected()) return;
+ options = parseOptions(this, this.getCursor("start"), options);
+ var selections = this.listSelections()
+ if (selections.length > 1) return;
+ // By default, don't allow completion when something is selected.
+ // A hint function can have a `supportsSelection` property to
+ // indicate that it can handle selections.
+ if (this.somethingSelected()) {
+ if (!options.hint.supportsSelection) return;
+ // Don't try with cross-line selections
+ for (var i = 0; i < selections.length; i++)
+ if (selections[i].head.line != selections[i].anchor.line) return;
+ }
if (this.state.completionActive) this.state.completionActive.close();
var completion = this.state.completionActive = new Completion(this, options);
@@ -38,12 +48,12 @@
function Completion(cm, options) {
this.cm = cm;
- this.options = this.buildOptions(options);
+ this.options = options;
this.widget = null;
this.debounce = 0;
this.tick = 0;
- this.startPos = this.cm.getCursor();
- this.startLen = this.cm.getLine(this.startPos.line).length;
+ this.startPos = this.cm.getCursor("start");
+ this.startLen = this.cm.getLine(this.startPos.line).length - this.cm.getSelection().length;
var self = this;
cm.on("cursorActivity", this.activityFunc = function() { self.cursorActivity(); });
@@ -99,7 +109,6 @@
update: function(first) {
if (this.tick == null) return;
- if (this.data) CodeMirror.signal(this.data, "update");
if (!this.options.hint.async) {
this.finishUpdate(this.options.hint(this.cm, this.options), first);
} else {
@@ -111,6 +120,8 @@
},
finishUpdate: function(data, first) {
+ if (this.data) CodeMirror.signal(this.data, "update");
+ if (data && this.data && CodeMirror.cmpPos(data.from, this.data.from)) data = null;
this.data = data;
var picked = (this.widget && this.widget.picked) || (first && this.options.completeSingle);
@@ -123,20 +134,21 @@
CodeMirror.signal(data, "shown");
}
}
- },
-
- buildOptions: function(options) {
- var editor = this.cm.options.hintOptions;
- var out = {};
- for (var prop in defaultOptions) out[prop] = defaultOptions[prop];
- if (editor) for (var prop in editor)
- if (editor[prop] !== undefined) out[prop] = editor[prop];
- if (options) for (var prop in options)
- if (options[prop] !== undefined) out[prop] = options[prop];
- return out;
}
};
+ function parseOptions(cm, pos, options) {
+ var editor = cm.options.hintOptions;
+ var out = {};
+ for (var prop in defaultOptions) out[prop] = defaultOptions[prop];
+ if (editor) for (var prop in editor)
+ if (editor[prop] !== undefined) out[prop] = editor[prop];
+ if (options) for (var prop in options)
+ if (options[prop] !== undefined) out[prop] = options[prop];
+ if (out.hint.resolve) out.hint = out.hint.resolve(cm, pos)
+ return out;
+ }
+
function getText(completion) {
if (typeof completion == "string") return completion;
else return completion.text;
@@ -335,34 +347,79 @@
}
};
- CodeMirror.registerHelper("hint", "auto", function(cm, options) {
- var helpers = cm.getHelpers(cm.getCursor(), "hint"), words;
+ function applicableHelpers(cm, helpers) {
+ if (!cm.somethingSelected()) return helpers
+ var result = []
+ for (var i = 0; i < helpers.length; i++)
+ if (helpers[i].supportsSelection) result.push(helpers[i])
+ return result
+ }
+
+ function resolveAutoHints(cm, pos) {
+ var helpers = cm.getHelpers(pos, "hint"), words
if (helpers.length) {
- for (var i = 0; i < helpers.length; i++) {
- var cur = helpers[i](cm, options);
- if (cur && cur.list.length) return cur;
+ var async = false, resolved
+ for (var i = 0; i < helpers.length; i++) if (helpers[i].async) async = true
+ if (async) {
+ resolved = function(cm, callback, options) {
+ var app = applicableHelpers(cm, helpers)
+ function run(i, result) {
+ if (i == app.length) return callback(null)
+ var helper = app[i]
+ if (helper.async) {
+ helper(cm, function(result) {
+ if (result) callback(result)
+ else run(i + 1)
+ }, options)
+ } else {
+ var result = helper(cm, options)
+ if (result) callback(result)
+ else run(i + 1)
+ }
+ }
+ run(0)
+ }
+ resolved.async = true
+ } else {
+ resolved = function(cm, options) {
+ var app = applicableHelpers(cm, helpers)
+ for (var i = 0; i < app.length; i++) {
+ var cur = app[i](cm, options)
+ if (cur && cur.list.length) return cur
+ }
+ }
}
+ resolved.supportsSelection = true
+ return resolved
} else if (words = cm.getHelper(cm.getCursor(), "hintWords")) {
- if (words) return CodeMirror.hint.fromList(cm, {words: words});
+ return function(cm) { return CodeMirror.hint.fromList(cm, {words: words}) }
} else if (CodeMirror.hint.anyword) {
- return CodeMirror.hint.anyword(cm, options);
+ return function(cm, options) { return CodeMirror.hint.anyword(cm, options) }
+ } else {
+ return function() {}
}
+ }
+
+ CodeMirror.registerHelper("hint", "auto", {
+ resolve: resolveAutoHints
});
CodeMirror.registerHelper("hint", "fromList", function(cm, options) {
var cur = cm.getCursor(), token = cm.getTokenAt(cur);
+ var to = CodeMirror.Pos(cur.line, token.end);
+ if (token.string && /\w/.test(token.string[token.string.length - 1])) {
+ var term = token.string, from = CodeMirror.Pos(cur.line, token.start);
+ } else {
+ var term = "", from = to;
+ }
var found = [];
for (var i = 0; i < options.words.length; i++) {
var word = options.words[i];
- if (word.slice(0, token.string.length) == token.string)
+ if (word.slice(0, term.length) == term)
found.push(word);
}
- if (found.length) return {
- list: found,
- from: CodeMirror.Pos(cur.line, token.start),
- to: CodeMirror.Pos(cur.line, token.end)
- };
+ if (found.length) return {list: found, from: from, to: to};
});
CodeMirror.commands.autocomplete = CodeMirror.showHint;
@@ -373,7 +430,7 @@
alignWithWord: true,
closeCharacters: /[\s()\[\]{};:>,]/,
closeOnUnfocus: true,
- completeOnSingleClick: false,
+ completeOnSingleClick: true,
container: null,
customKeys: null,
extraKeys: null
diff --git a/public/vendor/codemirror/addon/hint/sql-hint.js b/public/vendor/codemirror/addon/hint/sql-hint.js
index 22124b58..22124b58 100755..100644
--- a/public/vendor/codemirror/addon/hint/sql-hint.js
+++ b/public/vendor/codemirror/addon/hint/sql-hint.js
diff --git a/public/vendor/codemirror/addon/hint/xml-hint.js b/public/vendor/codemirror/addon/hint/xml-hint.js
index 9b9baa0c..9b9baa0c 100755..100644
--- a/public/vendor/codemirror/addon/hint/xml-hint.js
+++ b/public/vendor/codemirror/addon/hint/xml-hint.js