Update textcomplete rules to support more conditions and fix hint typo

This commit is contained in:
Cheng-Han, Wu 2016-05-27 13:38:59 +08:00
parent bce92d06df
commit 56840e784f
1 changed files with 17 additions and 12 deletions

View File

@ -116,11 +116,11 @@ var supportReferrals = [
search: '[]()' search: '[]()'
}, },
{ {
text: '![image text][reference]', text: '![image alt][reference]',
search: '![][]' search: '![][]'
}, },
{ {
text: '![image text](url "title")', text: '![image alt](url "title")',
search: '![]()' search: '![]()'
}, },
{ {
@ -2959,8 +2959,10 @@ function matchInContainer(text) {
$(editor.getInputField()) $(editor.getInputField())
.textcomplete([ .textcomplete([
{ // emoji strategy { // emoji strategy
match: /(?:^|\n|)\B:([\-+\w]*)$/, match: /(^|\n|\s)\B:([\-+\w]*)$/,
search: function (term, callback) { search: function (term, callback) {
var line = editor.getLine(editor.getCursor().line);
term = line.match(this.match)[2];
var list = []; var list = [];
$.map(emojify.emojiNames, function (emoji) { $.map(emojify.emojiNames, function (emoji) {
if (emoji.indexOf(term) === 0) //match at first character if (emoji.indexOf(term) === 0) //match at first character
@ -2976,7 +2978,7 @@ $(editor.getInputField())
return '<img class="emoji" src="' + serverurl + '/vendor/emojify/images/' + value + '.png"></img> ' + value; return '<img class="emoji" src="' + serverurl + '/vendor/emojify/images/' + value + '.png"></img> ' + value;
}, },
replace: function (value) { replace: function (value) {
return ':' + value + ':'; return '$1:' + value + ': ';
}, },
index: 1, index: 1,
context: function (text) { context: function (text) {
@ -3033,9 +3035,8 @@ $(editor.getInputField())
match: /(^|\n):::(\s*)(\w*)$/, match: /(^|\n):::(\s*)(\w*)$/,
search: function (term, callback) { search: function (term, callback) {
var line = editor.getLine(editor.getCursor().line); var line = editor.getLine(editor.getCursor().line);
term = line.match(this.match)[3]; term = line.match(this.match)[3].trim();
var list = []; var list = [];
term = term.trim();
$.map(this.containers, function (container) { $.map(this.containers, function (container) {
if (container.indexOf(term) === 0 && container !== term) if (container.indexOf(term) === 0 && container !== term)
list.push(container); list.push(container);
@ -3079,13 +3080,17 @@ $(editor.getInputField())
} }
}, },
{ //extra tags for blockquote { //extra tags for blockquote
match: /(?:^|\n|\s)(\>.*)(\[\])(\w*)$/, match: /(?:^|\n|\s)(\>.*|)((\^|)\[(\^|)\](\[\]|\(\)|\:|))(\w*)$/,
search: function (term, callback) { search: function (term, callback) {
var line = editor.getLine(editor.getCursor().line);
quote = line.match(this.match)[1].trim();
var list = []; var list = [];
$.map(supportExtraTags, function (extratag) { if (quote.indexOf('>') == 0) {
if (extratag.search.indexOf(term) === 0) $.map(supportExtraTags, function (extratag) {
list.push(extratag.command()); if (extratag.search.indexOf(term) === 0)
}); list.push(extratag.command());
});
}
$.map(supportReferrals, function (referral) { $.map(supportReferrals, function (referral) {
if (referral.search.indexOf(term) === 0) if (referral.search.indexOf(term) === 0)
list.push(referral.text); list.push(referral.text);
@ -3121,7 +3126,7 @@ $(editor.getInputField())
} }
}, },
{ //referral { //referral
match: /(^|\n|\s)(\!|\!|\[\])(\w*)$/, match: /(^|\n|\s)(\!(\[\]|)(\[\]|\(\)|))(\w*)$/,
search: function (term, callback) { search: function (term, callback) {
callback($.map(supportReferrals, function (referral) { callback($.map(supportReferrals, function (referral) {
return referral.search.indexOf(term) === 0 ? referral.text : null; return referral.search.indexOf(term) === 0 ? referral.text : null;