Merge branch 'master' of github.com:phpmyadmin/phpmyadmin
This commit is contained in:
commit
8fa9f576fd
@ -47,6 +47,8 @@ phpMyAdmin - ChangeLog
|
||||
+ rfe #1542 Better error reporting in Designer
|
||||
- bug #4547 Micro history does not work in Users page
|
||||
- bug #4551 Wrong test in source code
|
||||
- bug #4537 BLOB inline-view JPG column transformation does not work for anything except simple queries
|
||||
+ rfe #1535 Keyword-based autocompletion in SQL query editors
|
||||
|
||||
4.2.10.0 (not yet released)
|
||||
- bug #4361 Can't change font size (when config.inc.php not present)
|
||||
|
||||
389
js/codemirror/addon/hint/show-hint.js
vendored
Normal file
389
js/codemirror/addon/hint/show-hint.js
vendored
Normal file
@ -0,0 +1,389 @@
|
||||
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
||||
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
||||
|
||||
(function(mod) {
|
||||
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
||||
mod(require("../../lib/codemirror"));
|
||||
else if (typeof define == "function" && define.amd) // AMD
|
||||
define(["../../lib/codemirror"], mod);
|
||||
else // Plain browser env
|
||||
mod(CodeMirror);
|
||||
})(function(CodeMirror) {
|
||||
"use strict";
|
||||
|
||||
var HINT_ELEMENT_CLASS = "CodeMirror-hint";
|
||||
var ACTIVE_HINT_ELEMENT_CLASS = "CodeMirror-hint-active";
|
||||
|
||||
// This is the old interface, kept around for now to stay
|
||||
// backwards-compatible.
|
||||
CodeMirror.showHint = function(cm, getHints, options) {
|
||||
if (!getHints) return cm.showHint(options);
|
||||
if (options && options.async) getHints.async = true;
|
||||
var newOpts = {hint: getHints};
|
||||
if (options) for (var prop in options) newOpts[prop] = options[prop];
|
||||
return cm.showHint(newOpts);
|
||||
};
|
||||
|
||||
CodeMirror.defineExtension("showHint", function(options) {
|
||||
// We want a single cursor position.
|
||||
if (this.listSelections().length > 1 || this.somethingSelected()) return;
|
||||
|
||||
if (this.state.completionActive) this.state.completionActive.close();
|
||||
var completion = this.state.completionActive = new Completion(this, options);
|
||||
var getHints = completion.options.hint;
|
||||
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));
|
||||
});
|
||||
|
||||
function Completion(cm, options) {
|
||||
this.cm = cm;
|
||||
this.options = this.buildOptions(options);
|
||||
this.widget = this.onClose = null;
|
||||
}
|
||||
|
||||
Completion.prototype = {
|
||||
close: function() {
|
||||
if (!this.active()) return;
|
||||
this.cm.state.completionActive = null;
|
||||
|
||||
if (this.widget) this.widget.close();
|
||||
if (this.onClose) this.onClose();
|
||||
CodeMirror.signal(this.cm, "endCompletion", this.cm);
|
||||
},
|
||||
|
||||
active: function() {
|
||||
return this.cm.state.completionActive == this;
|
||||
},
|
||||
|
||||
pick: function(data, i) {
|
||||
var completion = data.list[i];
|
||||
if (completion.hint) completion.hint(this.cm, data, completion);
|
||||
else this.cm.replaceRange(getText(completion), completion.from || data.from,
|
||||
completion.to || data.to, "complete");
|
||||
CodeMirror.signal(data, "pick", completion);
|
||||
this.close();
|
||||
},
|
||||
|
||||
showHints: function(data) {
|
||||
if (!data || !data.list.length || !this.active()) return this.close();
|
||||
|
||||
if (this.options.completeSingle && data.list.length == 1)
|
||||
this.pick(data, 0);
|
||||
else
|
||||
this.showWidget(data);
|
||||
},
|
||||
|
||||
showWidget: function(data) {
|
||||
this.widget = new Widget(this, data);
|
||||
CodeMirror.signal(data, "shown");
|
||||
|
||||
var debounce = 0, completion = this, finished;
|
||||
var closeOn = this.options.closeCharacters;
|
||||
var startPos = this.cm.getCursor(), startLen = this.cm.getLine(startPos.line).length;
|
||||
|
||||
var requestAnimationFrame = window.requestAnimationFrame || function(fn) {
|
||||
return setTimeout(fn, 1000/60);
|
||||
};
|
||||
var cancelAnimationFrame = window.cancelAnimationFrame || clearTimeout;
|
||||
|
||||
function done() {
|
||||
if (finished) return;
|
||||
finished = true;
|
||||
completion.close();
|
||||
completion.cm.off("cursorActivity", activity);
|
||||
if (data) CodeMirror.signal(data, "close");
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
function finishUpdate(data_) {
|
||||
data = data_;
|
||||
if (finished) return;
|
||||
if (!data || !data.list.length) return done();
|
||||
if (completion.widget) completion.widget.close();
|
||||
completion.widget = new Widget(completion, data);
|
||||
}
|
||||
|
||||
function clearDebounce() {
|
||||
if (debounce) {
|
||||
cancelAnimationFrame(debounce);
|
||||
debounce = 0;
|
||||
}
|
||||
}
|
||||
|
||||
function activity() {
|
||||
clearDebounce();
|
||||
var pos = completion.cm.getCursor(), line = completion.cm.getLine(pos.line);
|
||||
if (pos.line != startPos.line || line.length - pos.ch != startLen - startPos.ch ||
|
||||
pos.ch < startPos.ch || completion.cm.somethingSelected() ||
|
||||
(pos.ch && closeOn.test(line.charAt(pos.ch - 1)))) {
|
||||
completion.close();
|
||||
} else {
|
||||
debounce = requestAnimationFrame(update);
|
||||
if (completion.widget) completion.widget.close();
|
||||
}
|
||||
}
|
||||
this.cm.on("cursorActivity", activity);
|
||||
this.onClose = done;
|
||||
},
|
||||
|
||||
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 getText(completion) {
|
||||
if (typeof completion == "string") return completion;
|
||||
else return completion.text;
|
||||
}
|
||||
|
||||
function buildKeyMap(completion, handle) {
|
||||
var baseMap = {
|
||||
Up: function() {handle.moveFocus(-1);},
|
||||
Down: function() {handle.moveFocus(1);},
|
||||
PageUp: function() {handle.moveFocus(-handle.menuSize() + 1, true);},
|
||||
PageDown: function() {handle.moveFocus(handle.menuSize() - 1, true);},
|
||||
Home: function() {handle.setFocus(0);},
|
||||
End: function() {handle.setFocus(handle.length - 1);},
|
||||
Enter: handle.pick,
|
||||
Tab: handle.pick,
|
||||
Esc: handle.close
|
||||
};
|
||||
var custom = completion.options.customKeys;
|
||||
var ourMap = custom ? {} : baseMap;
|
||||
function addBinding(key, val) {
|
||||
var bound;
|
||||
if (typeof val != "string")
|
||||
bound = function(cm) { return val(cm, handle); };
|
||||
// This mechanism is deprecated
|
||||
else if (baseMap.hasOwnProperty(val))
|
||||
bound = baseMap[val];
|
||||
else
|
||||
bound = val;
|
||||
ourMap[key] = bound;
|
||||
}
|
||||
if (custom)
|
||||
for (var key in custom) if (custom.hasOwnProperty(key))
|
||||
addBinding(key, custom[key]);
|
||||
var extra = completion.options.extraKeys;
|
||||
if (extra)
|
||||
for (var key in extra) if (extra.hasOwnProperty(key))
|
||||
addBinding(key, extra[key]);
|
||||
return ourMap;
|
||||
}
|
||||
|
||||
function getHintElement(hintsElement, el) {
|
||||
while (el && el != hintsElement) {
|
||||
if (el.nodeName.toUpperCase() === "LI" && el.parentNode == hintsElement) return el;
|
||||
el = el.parentNode;
|
||||
}
|
||||
}
|
||||
|
||||
function Widget(completion, data) {
|
||||
this.completion = completion;
|
||||
this.data = data;
|
||||
var widget = this, cm = completion.cm;
|
||||
|
||||
var hints = this.hints = document.createElement("ul");
|
||||
hints.className = "CodeMirror-hints";
|
||||
this.selectedHint = data.selectedHint || 0;
|
||||
|
||||
var completions = data.list;
|
||||
for (var i = 0; i < completions.length; ++i) {
|
||||
var elt = hints.appendChild(document.createElement("li")), cur = completions[i];
|
||||
var className = HINT_ELEMENT_CLASS + (i != this.selectedHint ? "" : " " + ACTIVE_HINT_ELEMENT_CLASS);
|
||||
if (cur.className != null) className = cur.className + " " + className;
|
||||
elt.className = className;
|
||||
if (cur.render) cur.render(elt, data, cur);
|
||||
else elt.appendChild(document.createTextNode(cur.displayText || getText(cur)));
|
||||
elt.hintId = i;
|
||||
}
|
||||
|
||||
var pos = cm.cursorCoords(completion.options.alignWithWord ? data.from : null);
|
||||
var left = pos.left, top = pos.bottom, below = true;
|
||||
hints.style.left = left + "px";
|
||||
hints.style.top = top + "px";
|
||||
// If we're at the edge of the screen, then we want the menu to appear on the left of the cursor.
|
||||
var winW = window.innerWidth || Math.max(document.body.offsetWidth, document.documentElement.offsetWidth);
|
||||
var winH = window.innerHeight || Math.max(document.body.offsetHeight, document.documentElement.offsetHeight);
|
||||
(completion.options.container || document.body).appendChild(hints);
|
||||
var box = hints.getBoundingClientRect(), overlapY = box.bottom - winH;
|
||||
if (overlapY > 0) {
|
||||
var height = box.bottom - box.top, curTop = pos.top - (pos.bottom - box.top);
|
||||
if (curTop - height > 0) { // Fits above cursor
|
||||
hints.style.top = (top = pos.top - height) + "px";
|
||||
below = false;
|
||||
} else if (height > winH) {
|
||||
hints.style.height = (winH - 5) + "px";
|
||||
hints.style.top = (top = pos.bottom - box.top) + "px";
|
||||
var cursor = cm.getCursor();
|
||||
if (data.from.ch != cursor.ch) {
|
||||
pos = cm.cursorCoords(cursor);
|
||||
hints.style.left = (left = pos.left) + "px";
|
||||
box = hints.getBoundingClientRect();
|
||||
}
|
||||
}
|
||||
}
|
||||
var overlapX = box.left - winW;
|
||||
if (overlapX > 0) {
|
||||
if (box.right - box.left > winW) {
|
||||
hints.style.width = (winW - 5) + "px";
|
||||
overlapX -= (box.right - box.left) - winW;
|
||||
}
|
||||
hints.style.left = (left = pos.left - overlapX) + "px";
|
||||
}
|
||||
|
||||
cm.addKeyMap(this.keyMap = buildKeyMap(completion, {
|
||||
moveFocus: function(n, avoidWrap) { widget.changeActive(widget.selectedHint + n, avoidWrap); },
|
||||
setFocus: function(n) { widget.changeActive(n); },
|
||||
menuSize: function() { return widget.screenAmount(); },
|
||||
length: completions.length,
|
||||
close: function() { completion.close(); },
|
||||
pick: function() { widget.pick(); },
|
||||
data: data
|
||||
}));
|
||||
|
||||
if (completion.options.closeOnUnfocus) {
|
||||
var closingOnBlur;
|
||||
cm.on("blur", this.onBlur = function() { closingOnBlur = setTimeout(function() { completion.close(); }, 100); });
|
||||
cm.on("focus", this.onFocus = function() { clearTimeout(closingOnBlur); });
|
||||
}
|
||||
|
||||
var startScroll = cm.getScrollInfo();
|
||||
cm.on("scroll", this.onScroll = function() {
|
||||
var curScroll = cm.getScrollInfo(), editor = cm.getWrapperElement().getBoundingClientRect();
|
||||
var newTop = top + startScroll.top - curScroll.top;
|
||||
var point = newTop - (window.pageYOffset || (document.documentElement || document.body).scrollTop);
|
||||
if (!below) point += hints.offsetHeight;
|
||||
if (point <= editor.top || point >= editor.bottom) return completion.close();
|
||||
hints.style.top = newTop + "px";
|
||||
hints.style.left = (left + startScroll.left - curScroll.left) + "px";
|
||||
});
|
||||
|
||||
CodeMirror.on(hints, "dblclick", function(e) {
|
||||
var t = getHintElement(hints, e.target || e.srcElement);
|
||||
if (t && t.hintId != null) {widget.changeActive(t.hintId); widget.pick();}
|
||||
});
|
||||
|
||||
CodeMirror.on(hints, "click", function(e) {
|
||||
var t = getHintElement(hints, e.target || e.srcElement);
|
||||
if (t && t.hintId != null) {
|
||||
widget.changeActive(t.hintId);
|
||||
if (completion.options.completeOnSingleClick) widget.pick();
|
||||
}
|
||||
});
|
||||
|
||||
CodeMirror.on(hints, "mousedown", function() {
|
||||
setTimeout(function(){cm.focus();}, 20);
|
||||
});
|
||||
|
||||
CodeMirror.signal(data, "select", completions[0], hints.firstChild);
|
||||
return true;
|
||||
}
|
||||
|
||||
Widget.prototype = {
|
||||
close: function() {
|
||||
if (this.completion.widget != this) return;
|
||||
this.completion.widget = null;
|
||||
this.hints.parentNode.removeChild(this.hints);
|
||||
this.completion.cm.removeKeyMap(this.keyMap);
|
||||
|
||||
var cm = this.completion.cm;
|
||||
if (this.completion.options.closeOnUnfocus) {
|
||||
cm.off("blur", this.onBlur);
|
||||
cm.off("focus", this.onFocus);
|
||||
}
|
||||
cm.off("scroll", this.onScroll);
|
||||
},
|
||||
|
||||
pick: function() {
|
||||
this.completion.pick(this.data, this.selectedHint);
|
||||
},
|
||||
|
||||
changeActive: function(i, avoidWrap) {
|
||||
if (i >= this.data.list.length)
|
||||
i = avoidWrap ? this.data.list.length - 1 : 0;
|
||||
else if (i < 0)
|
||||
i = avoidWrap ? 0 : this.data.list.length - 1;
|
||||
if (this.selectedHint == i) return;
|
||||
var node = this.hints.childNodes[this.selectedHint];
|
||||
node.className = node.className.replace(" " + ACTIVE_HINT_ELEMENT_CLASS, "");
|
||||
node = this.hints.childNodes[this.selectedHint = i];
|
||||
node.className += " " + ACTIVE_HINT_ELEMENT_CLASS;
|
||||
if (node.offsetTop < this.hints.scrollTop)
|
||||
this.hints.scrollTop = node.offsetTop - 3;
|
||||
else if (node.offsetTop + node.offsetHeight > this.hints.scrollTop + this.hints.clientHeight)
|
||||
this.hints.scrollTop = node.offsetTop + node.offsetHeight - this.hints.clientHeight + 3;
|
||||
CodeMirror.signal(this.data, "select", this.data.list[this.selectedHint], node);
|
||||
},
|
||||
|
||||
screenAmount: function() {
|
||||
return Math.floor(this.hints.clientHeight / this.hints.firstChild.offsetHeight) || 1;
|
||||
}
|
||||
};
|
||||
|
||||
CodeMirror.registerHelper("hint", "auto", function(cm, options) {
|
||||
var helpers = cm.getHelpers(cm.getCursor(), "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;
|
||||
}
|
||||
} else if (words = cm.getHelper(cm.getCursor(), "hintWords")) {
|
||||
if (words) return CodeMirror.hint.fromList(cm, {words: words});
|
||||
} else if (CodeMirror.hint.anyword) {
|
||||
return CodeMirror.hint.anyword(cm, options);
|
||||
}
|
||||
});
|
||||
|
||||
CodeMirror.registerHelper("hint", "fromList", function(cm, options) {
|
||||
var cur = cm.getCursor(), token = cm.getTokenAt(cur);
|
||||
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)
|
||||
found.push(word);
|
||||
}
|
||||
|
||||
if (found.length) return {
|
||||
list: found,
|
||||
from: CodeMirror.Pos(cur.line, token.start),
|
||||
to: CodeMirror.Pos(cur.line, token.end)
|
||||
};
|
||||
});
|
||||
|
||||
CodeMirror.commands.autocomplete = CodeMirror.showHint;
|
||||
|
||||
var defaultOptions = {
|
||||
hint: CodeMirror.hint.auto,
|
||||
completeSingle: true,
|
||||
alignWithWord: true,
|
||||
closeCharacters: /[\s()\[\]{};:>,]/,
|
||||
closeOnUnfocus: true,
|
||||
completeOnSingleClick: false,
|
||||
container: null,
|
||||
customKeys: null,
|
||||
extraKeys: null
|
||||
};
|
||||
|
||||
CodeMirror.defineOption("hintOptions", null);
|
||||
});
|
||||
160
js/codemirror/addon/hint/sql-hint.js
vendored
Normal file
160
js/codemirror/addon/hint/sql-hint.js
vendored
Normal file
@ -0,0 +1,160 @@
|
||||
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
||||
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
||||
|
||||
(function(mod) {
|
||||
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
||||
mod(require("../../lib/codemirror"), require("../../mode/sql/sql"));
|
||||
else if (typeof define == "function" && define.amd) // AMD
|
||||
define(["../../lib/codemirror", "../../mode/sql/sql"], mod);
|
||||
else // Plain browser env
|
||||
mod(CodeMirror);
|
||||
})(function(CodeMirror) {
|
||||
"use strict";
|
||||
|
||||
var tables;
|
||||
var keywords;
|
||||
var CONS = {
|
||||
QUERY_DIV: ";",
|
||||
ALIAS_KEYWORD: "AS"
|
||||
};
|
||||
var Pos = CodeMirror.Pos;
|
||||
|
||||
function getKeywords(editor) {
|
||||
var mode = editor.doc.modeOption;
|
||||
if (mode === "sql") mode = "text/x-sql";
|
||||
return CodeMirror.resolveMode(mode).keywords;
|
||||
}
|
||||
|
||||
function match(string, word) {
|
||||
var len = string.length;
|
||||
var sub = word.substr(0, len);
|
||||
return string.toUpperCase() === sub.toUpperCase();
|
||||
}
|
||||
|
||||
function addMatches(result, search, wordlist, formatter) {
|
||||
for (var word in wordlist) {
|
||||
if (!wordlist.hasOwnProperty(word)) continue;
|
||||
if (Array.isArray(wordlist)) {
|
||||
word = wordlist[word];
|
||||
}
|
||||
if (match(search, word)) {
|
||||
result.push(formatter(word));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function columnCompletion(result, editor) {
|
||||
var cur = editor.getCursor();
|
||||
var token = editor.getTokenAt(cur);
|
||||
var string = token.string.substr(1);
|
||||
var prevCur = Pos(cur.line, token.start);
|
||||
var table = editor.getTokenAt(prevCur).string;
|
||||
if (!tables.hasOwnProperty(table))
|
||||
table = findTableByAlias(table, editor);
|
||||
var columns = tables[table];
|
||||
if (!columns) return;
|
||||
|
||||
addMatches(result, string, columns, function(w) {return "." + w;});
|
||||
}
|
||||
|
||||
function eachWord(lineText, f) {
|
||||
if (!lineText) return;
|
||||
var excepted = /[,;]/g;
|
||||
var words = lineText.split(" ");
|
||||
for (var i = 0; i < words.length; i++) {
|
||||
f(words[i]?words[i].replace(excepted, '') : '');
|
||||
}
|
||||
}
|
||||
|
||||
function convertCurToNumber(cur) {
|
||||
// max characters of a line is 999,999.
|
||||
return cur.line + cur.ch / Math.pow(10, 6);
|
||||
}
|
||||
|
||||
function convertNumberToCur(num) {
|
||||
return Pos(Math.floor(num), +num.toString().split('.').pop());
|
||||
}
|
||||
|
||||
function findTableByAlias(alias, editor) {
|
||||
var doc = editor.doc;
|
||||
var fullQuery = doc.getValue();
|
||||
var aliasUpperCase = alias.toUpperCase();
|
||||
var previousWord = "";
|
||||
var table = "";
|
||||
var separator = [];
|
||||
var validRange = {
|
||||
start: Pos(0, 0),
|
||||
end: Pos(editor.lastLine(), editor.getLineHandle(editor.lastLine()).length)
|
||||
};
|
||||
|
||||
//add separator
|
||||
var indexOfSeparator = fullQuery.indexOf(CONS.QUERY_DIV);
|
||||
while(indexOfSeparator != -1) {
|
||||
separator.push(doc.posFromIndex(indexOfSeparator));
|
||||
indexOfSeparator = fullQuery.indexOf(CONS.QUERY_DIV, indexOfSeparator+1);
|
||||
}
|
||||
separator.unshift(Pos(0, 0));
|
||||
separator.push(Pos(editor.lastLine(), editor.getLineHandle(editor.lastLine()).text.length));
|
||||
|
||||
//find valid range
|
||||
var prevItem = 0;
|
||||
var current = convertCurToNumber(editor.getCursor());
|
||||
for (var i=0; i< separator.length; i++) {
|
||||
var _v = convertCurToNumber(separator[i]);
|
||||
if (current > prevItem && current <= _v) {
|
||||
validRange = { start: convertNumberToCur(prevItem), end: convertNumberToCur(_v) };
|
||||
break;
|
||||
}
|
||||
prevItem = _v;
|
||||
}
|
||||
|
||||
var query = doc.getRange(validRange.start, validRange.end, false);
|
||||
|
||||
for (var i = 0; i < query.length; i++) {
|
||||
var lineText = query[i];
|
||||
eachWord(lineText, function(word) {
|
||||
var wordUpperCase = word.toUpperCase();
|
||||
if (wordUpperCase === aliasUpperCase && tables.hasOwnProperty(previousWord)) {
|
||||
table = previousWord;
|
||||
}
|
||||
if (wordUpperCase !== CONS.ALIAS_KEYWORD) {
|
||||
previousWord = word;
|
||||
}
|
||||
});
|
||||
if (table) break;
|
||||
}
|
||||
return table;
|
||||
}
|
||||
|
||||
CodeMirror.registerHelper("hint", "sql", function(editor, options) {
|
||||
tables = (options && options.tables) || {};
|
||||
keywords = keywords || getKeywords(editor);
|
||||
var cur = editor.getCursor();
|
||||
var result = [];
|
||||
var token = editor.getTokenAt(cur), start, end, search;
|
||||
if (token.string.match(/^[.\w@]\w*$/)) {
|
||||
search = token.string;
|
||||
start = token.start;
|
||||
end = token.end;
|
||||
} else {
|
||||
start = end = cur.ch;
|
||||
search = "";
|
||||
}
|
||||
if (search.charAt(0) == ".") {
|
||||
columnCompletion(result, editor);
|
||||
if (!result.length) {
|
||||
while (start && search.charAt(0) == ".") {
|
||||
token = editor.getTokenAt(Pos(cur.line, token.start - 1));
|
||||
start = token.start;
|
||||
search = token.string + search;
|
||||
}
|
||||
addMatches(result, search, tables, function(w) {return w;});
|
||||
}
|
||||
} else {
|
||||
addMatches(result, search, tables, function(w) {return w;});
|
||||
addMatches(result, search, keywords, function(w) {return w.toUpperCase();});
|
||||
}
|
||||
|
||||
return {list: result, from: Pos(cur.line, start), to: Pos(cur.line, end)};
|
||||
});
|
||||
});
|
||||
@ -488,14 +488,20 @@ var PMA_consoleInput = {
|
||||
PMA_consoleInput._inputs.console = CodeMirror($('#pma_console .console_query_input')[0], {
|
||||
theme: 'pma',
|
||||
mode: 'text/x-sql',
|
||||
lineWrapping: true
|
||||
lineWrapping: true,
|
||||
extraKeys: {"Ctrl-Space": "autocomplete"},
|
||||
hintOptions: {"completeSingle": false, "completeOnSingleClick": true},
|
||||
});
|
||||
PMA_consoleInput._inputs.console.on("inputRead", codemirrorAutocompleteOnInputRead);
|
||||
if ($('#pma_bookmarks').length !== 0) {
|
||||
PMA_consoleInput._inputs.bookmark = CodeMirror($('#pma_console .bookmark_add_input')[0], {
|
||||
theme: 'pma',
|
||||
mode: 'text/x-sql',
|
||||
lineWrapping: true
|
||||
lineWrapping: true,
|
||||
extraKeys: {"Ctrl-Space": "autocomplete"},
|
||||
hintOptions: {"completeSingle": false, "completeOnSingleClick": true},
|
||||
});
|
||||
PMA_consoleInput._inputs.bookmark.on("inputRead", codemirrorAutocompleteOnInputRead);
|
||||
}
|
||||
} else {
|
||||
PMA_consoleInput._inputs.console =
|
||||
|
||||
@ -1669,6 +1669,24 @@ AJAX.registerOnload('functions.js', function () {
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* "inputRead" event handler for CodeMirror SQL query editors for autocompletion
|
||||
*/
|
||||
function codemirrorAutocompleteOnInputRead(instance) {
|
||||
if (instance.state.completionActive) {
|
||||
return;
|
||||
}
|
||||
var cur = instance.getCursor();
|
||||
var token = instance.getTokenAt(cur);
|
||||
var string = '';
|
||||
if (token.string.match(/^[.\w@]\w*$/)) {
|
||||
string = token.string;
|
||||
}
|
||||
if (string.length > 0) {
|
||||
CodeMirror.commands.autocomplete(instance);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Binds the CodeMirror to the text area used to inline edit a query.
|
||||
*/
|
||||
@ -1680,10 +1698,13 @@ function bindCodeMirrorToInlineEditor() {
|
||||
codemirror_inline_editor = CodeMirror.fromTextArea($inline_editor[0], {
|
||||
lineNumbers: true,
|
||||
matchBrackets: true,
|
||||
extraKeys: {"Ctrl-Space": "autocomplete"},
|
||||
hintOptions: {"completeSingle": false, "completeOnSingleClick": true},
|
||||
indentUnit: 4,
|
||||
mode: "text/x-mysql",
|
||||
lineWrapping: true
|
||||
});
|
||||
codemirror_inline_editor.on("inputRead", codemirrorAutocompleteOnInputRead);
|
||||
codemirror_inline_editor.getScrollerElement().style.height = height;
|
||||
codemirror_inline_editor.refresh();
|
||||
codemirror_inline_editor.focus();
|
||||
@ -4061,10 +4082,13 @@ AJAX.registerOnload('functions.js', function () {
|
||||
codemirror_editor = CodeMirror.fromTextArea($elm[0], {
|
||||
lineNumbers: true,
|
||||
matchBrackets: true,
|
||||
extraKeys: {"Ctrl-Space": "autocomplete"},
|
||||
hintOptions: {"completeSingle": false, "completeOnSingleClick": true},
|
||||
indentUnit: 4,
|
||||
mode: "text/x-mysql",
|
||||
lineWrapping: true
|
||||
});
|
||||
codemirror_editor.on("inputRead", codemirrorAutocompleteOnInputRead);
|
||||
codemirror_editor.focus();
|
||||
$(codemirror_editor.getWrapperElement()).bind(
|
||||
'keydown',
|
||||
@ -4266,11 +4290,14 @@ AJAX.registerOnload('functions.js', function () {
|
||||
{
|
||||
lineNumbers: true,
|
||||
matchBrackets: true,
|
||||
extraKeys: {"Ctrl-Space": "autocomplete"},
|
||||
hintOptions: {"completeSingle": false, "completeOnSingleClick": true},
|
||||
indentUnit: 4,
|
||||
mode: "text/x-mysql",
|
||||
lineWrapping: true
|
||||
}
|
||||
);
|
||||
syntaxHighlighter.on("inputRead", codemirrorAutocompleteOnInputRead);
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -4315,8 +4342,16 @@ function PMA_createViewDialog($this)
|
||||
// Attach syntax highlighted editor
|
||||
if (typeof CodeMirror !== 'undefined') {
|
||||
var $elm = $dialog.find('textarea');
|
||||
var opts = {lineNumbers: true, matchBrackets: true, indentUnit: 4, mode: "text/x-mysql", lineWrapping: true};
|
||||
syntaxHighlighter = CodeMirror.fromTextArea($elm[0], opts);
|
||||
syntaxHighlighter = CodeMirror.fromTextArea($elm[0], {
|
||||
lineNumbers: true,
|
||||
matchBrackets: true,
|
||||
extraKeys: {"Ctrl-Space": "autocomplete"},
|
||||
hintOptions: {"completeSingle": false, "completeOnSingleClick": true},
|
||||
indentUnit: 4,
|
||||
mode: "text/x-mysql",
|
||||
lineWrapping: true
|
||||
});
|
||||
syntaxHighlighter.on("inputRead", codemirrorAutocompleteOnInputRead);
|
||||
}
|
||||
$('input:visible[type=text]', $dialog).first().focus();
|
||||
} else {
|
||||
|
||||
@ -159,6 +159,8 @@ class PMA_Console
|
||||
$this->_scripts->addFile('codemirror/lib/codemirror.js');
|
||||
$this->_scripts->addFile('codemirror/mode/sql/sql.js');
|
||||
$this->_scripts->addFile('codemirror/addon/runmode/runmode.js');
|
||||
$this->_scripts->addFile('codemirror/addon/hint/show-hint.js');
|
||||
$this->_scripts->addFile('codemirror/addon/hint/sql-hint.js');
|
||||
}
|
||||
$this->_scripts->addFile('console.js');
|
||||
$output .= $this->_scripts->getDisplay();
|
||||
|
||||
@ -2926,12 +2926,29 @@ class PMA_DisplayResults
|
||||
'transform_key' => $meta->name,
|
||||
);
|
||||
|
||||
list($transform_where_clause, $clause_is_unique, $condition_array)
|
||||
= PMA_Util::getUniqueCondition(
|
||||
$dt_result,
|
||||
$this->__get('fields_cnt'),
|
||||
$this->__get('fields_meta'),
|
||||
$row,
|
||||
false,
|
||||
$this->__get('table')
|
||||
);
|
||||
$transform_url_params = array(
|
||||
'db' => $this->__get('db'),
|
||||
'table' => $this->__get('table'),
|
||||
'where_clause' => $transform_where_clause,
|
||||
'transform_key' => $meta->name,
|
||||
);
|
||||
|
||||
if (! empty($sql_query)) {
|
||||
$_url_params['sql_query'] = $url_sql_query;
|
||||
$transform_url_params['sql_query'] = $url_sql_query;
|
||||
}
|
||||
|
||||
$transform_options['wrapper_link']
|
||||
= PMA_URL_getCommon($_url_params);
|
||||
= PMA_URL_getCommon($transform_url_params);
|
||||
|
||||
$vertical_display = $this->__get('vertical_display');
|
||||
|
||||
|
||||
@ -384,6 +384,8 @@ class PMA_Header
|
||||
$this->_scripts->addFile('codemirror/lib/codemirror.js');
|
||||
$this->_scripts->addFile('codemirror/mode/sql/sql.js');
|
||||
$this->_scripts->addFile('codemirror/addon/runmode/runmode.js');
|
||||
$this->_scripts->addFile('codemirror/addon/hint/show-hint.js');
|
||||
$this->_scripts->addFile('codemirror/addon/hint/sql-hint.js');
|
||||
}
|
||||
if ($this->_userprefsOfferImport) {
|
||||
$this->_scripts->addFile('config.js');
|
||||
|
||||
@ -2079,18 +2079,20 @@ class PMA_Util
|
||||
/**
|
||||
* Function to generate unique condition for specified row.
|
||||
*
|
||||
* @param resource $handle current query result
|
||||
* @param integer $fields_cnt number of fields
|
||||
* @param array $fields_meta meta information about fields
|
||||
* @param array $row current row
|
||||
* @param boolean $force_unique generate condition only on pk or unique
|
||||
* @param resource $handle current query result
|
||||
* @param integer $fields_cnt number of fields
|
||||
* @param array $fields_meta meta information about fields
|
||||
* @param array $row current row
|
||||
* @param boolean $force_unique generate condition only on pk or unique
|
||||
* @param string $restrict_to_table restrict the unique condition to this table
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @return array the calculated condition and whether condition is unique
|
||||
*/
|
||||
public static function getUniqueCondition(
|
||||
$handle, $fields_cnt, $fields_meta, $row, $force_unique = false
|
||||
$handle, $fields_cnt, $fields_meta, $row, $force_unique = false,
|
||||
$restrict_to_table = false
|
||||
) {
|
||||
$primary_key = '';
|
||||
$unique_key = '';
|
||||
@ -2148,6 +2150,12 @@ class PMA_Util
|
||||
$meta->table = $meta->orgtable;
|
||||
}
|
||||
|
||||
// If this field is not from the table which the unique clause needs
|
||||
// to be restricted to.
|
||||
if ($restrict_to_table && $restrict_to_table != $meta->table) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// to fix the bug where float fields (primary or not)
|
||||
// can't be matched because of the imprecision of
|
||||
// floating comparison, use CONCAT
|
||||
|
||||
@ -305,3 +305,43 @@ span.cm-separator {
|
||||
span.cm-number {
|
||||
color: teal;
|
||||
}
|
||||
|
||||
/* CodeMirror Hints styling */
|
||||
.CodeMirror-hints {
|
||||
position: absolute;
|
||||
z-index: 2000;
|
||||
overflow: hidden;
|
||||
list-style: none;
|
||||
|
||||
margin: 0;
|
||||
padding: 2px;
|
||||
|
||||
-webkit-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
|
||||
-moz-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
|
||||
box-shadow: 2px 3px 5px rgba(0,0,0,.2);
|
||||
border-radius: 3px;
|
||||
border: 1px solid silver;
|
||||
|
||||
background: white;
|
||||
font-size: 90%;
|
||||
font-family: monospace;
|
||||
|
||||
max-height: 20em;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.CodeMirror-hint {
|
||||
margin: 0;
|
||||
padding: 0 4px;
|
||||
border-radius: 2px;
|
||||
max-width: 19em;
|
||||
overflow: hidden;
|
||||
white-space: pre;
|
||||
color: black;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
li.CodeMirror-hint-active {
|
||||
background: #08f;
|
||||
color: white;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user