Skip to content

Commit

Permalink
Merge branch 'release/1.0.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
gregpriday committed Jan 21, 2016
2 parents 6aa4a24 + affd71a commit 8615078
Show file tree
Hide file tree
Showing 17 changed files with 882 additions and 422 deletions.
1 change: 1 addition & 0 deletions js/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
// Setup the Codemirror instance
this.codeMirror = CodeMirror.fromTextArea(this.$('textarea.css-editor').get(0), {
tabSize: 2,
lineNumbers: true,
mode: 'css',
theme: 'neat',
gutters: [
Expand Down
4 changes: 3 additions & 1 deletion lib/codemirror/addon/fold/comment-fold.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ CodeMirror.registerGlobalHelper("fold", "comment", function(mode) {
continue;
}
if (pass == 1 && found < start.ch) return;
if (/comment/.test(cm.getTokenTypeAt(CodeMirror.Pos(line, found + 1)))) {
if (/comment/.test(cm.getTokenTypeAt(CodeMirror.Pos(line, found + 1))) &&
(lineText.slice(found - endToken.length, found) == endToken ||
!/comment/.test(cm.getTokenTypeAt(CodeMirror.Pos(line, found))))) {
startCh = found + startToken.length;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/codemirror/addon/hint/anyword-hint.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
156 changes: 102 additions & 54 deletions lib/codemirror/addon/hint/show-hint.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,35 @@
};

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);
if (!completion.options.hint) return;

CodeMirror.signal(this, "startCompletion", this);
completion.update();
completion.update(true);
});

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(); });
Expand All @@ -61,6 +71,7 @@
this.tick = null;
this.cm.off("cursorActivity", this.activityFunc);

if (this.widget && this.data) CodeMirror.signal(this.data, "close");
if (this.widget) this.widget.close();
CodeMirror.signal(this.cm, "endCompletion", this.cm);
},
Expand All @@ -78,15 +89,6 @@
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);
},

cursorActivity: function() {
if (this.debounce) {
cancelAnimationFrame(this.debounce);
Expand All @@ -105,47 +107,48 @@
}
},

update: function() {
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), myTick);
this.finishUpdate(this.options.hint(this.cm, this.options), first);
} else {
var myTick = ++this.tick, self = this;
this.options.hint(this.cm, function(data) {
if (self.tick == myTick) self.finishUpdate(data);
if (self.tick == myTick) self.finishUpdate(data, first);
}, this.options);
}
},

finishUpdate: function(data) {
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;

var picked = (this.widget && this.widget.picked) || (first && this.options.completeSingle);
if (this.widget) this.widget.close();
if (data && data.list.length) {
if (picked && data.list.length == 1) this.pick(data, 0);
else this.widget = new Widget(this, data);
if (picked && data.list.length == 1) {
this.pick(data, 0);
} else {
this.widget = new Widget(this, data);
CodeMirror.signal(data, "shown");
}
}
},

showWidget: function(data) {
this.data = data;
this.widget = new Widget(this, data);
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;
Expand Down Expand Up @@ -344,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;
Expand All @@ -382,7 +430,7 @@
alignWithWord: true,
closeCharacters: /[\s()\[\]{};:>,]/,
closeOnUnfocus: true,
completeOnSingleClick: false,
completeOnSingleClick: true,
container: null,
customKeys: null,
extraKeys: null
Expand Down
17 changes: 13 additions & 4 deletions lib/codemirror/addon/hint/sql-hint.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,21 +112,28 @@
string = nameParts.pop();
var table = nameParts.join(".");

var alias = false;
var aliasTable = table;
// Check if table is available. If not, find table by Alias
if (!getItem(tables, table))
if (!getItem(tables, table)) {
var oldTable = table;
table = findTableByAlias(table, editor);
if (table !== oldTable) alias = true;
}

var columns = getItem(tables, table);
if (columns && columns.columns)
columns = columns.columns;

if (columns) {
addMatches(result, string, columns, function(w) {
var tableInsert = table;
if (alias == true) tableInsert = aliasTable;
if (typeof w == "string") {
w = table + "." + w;
w = tableInsert + "." + w;
} else {
w = shallowClone(w);
w.text = table + "." + w.text;
w.text = tableInsert + "." + w.text;
}
return useBacktick ? insertBackticks(w) : w;
});
Expand Down Expand Up @@ -205,6 +212,7 @@
CodeMirror.registerHelper("hint", "sql", function(editor, options) {
tables = (options && options.tables) || {};
var defaultTableName = options && options.defaultTable;
var disableKeywords = options && options.disableKeywords;
defaultTable = defaultTableName && getItem(tables, defaultTableName);
keywords = keywords || getKeywords(editor);

Expand Down Expand Up @@ -237,7 +245,8 @@
} else {
addMatches(result, search, tables, function(w) {return w;});
addMatches(result, search, defaultTable, function(w) {return w;});
addMatches(result, search, keywords, function(w) {return w.toUpperCase();});
if (!disableKeywords)
addMatches(result, search, keywords, function(w) {return w.toUpperCase();});
}

return {list: result, from: Pos(cur.line, start), to: Pos(cur.line, end)};
Expand Down
10 changes: 1 addition & 9 deletions lib/codemirror/addon/lint/css-lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,7 @@
CodeMirror.registerHelper("lint", "css", function(text) {
var found = [];
if (!window.CSSLint) return found;
// This has been modified to only display certain errors
var results = CSSLint.verify(text, {
"box-model": 1,
"display-property-grouping": 1,
"duplicate-properties": 1,
"empty-rules": 1,
"known-properties": 1
}), messages = results.messages, message = null;

var results = CSSLint.verify(text), messages = results.messages, message = null;
for ( var i = 0; i < messages.length; i++) {
message = messages[i];
var startLine = message.line -1, endLine = message.line -1, startCol = message.col -1, endCol = message.col;
Expand Down
46 changes: 46 additions & 0 deletions lib/codemirror/addon/lint/html-lint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE

// Depends on htmlhint.js from http://htmlhint.com/js/htmlhint.js

// declare global: HTMLHint

(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"), require("htmlhint"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror", "htmlhint"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";

var defaultRules = {
"tagname-lowercase": true,
"attr-lowercase": true,
"attr-value-double-quotes": true,
"doctype-first": false,
"tag-pair": true,
"spec-char-escape": true,
"id-unique": true,
"src-not-empty": true,
"attr-no-duplication": true
};

CodeMirror.registerHelper("lint", "html", function(text, options) {
var found = [];
if (!window.HTMLHint) return found;
var messages = HTMLHint.verify(text, options && options.rules || defaultRules);
for (var i = 0; i < messages.length; i++) {
var message = messages[i];
var startLine = message.line - 1, endLine = message.line - 1, startCol = message.col - 1, endCol = message.col;
found.push({
from: CodeMirror.Pos(startLine, startCol),
to: CodeMirror.Pos(endLine, endCol),
message: message.message,
severity : message.type
});
}
return found;
});
});
Loading

0 comments on commit 8615078

Please sign in to comment.