From 56840e784f04fcf71e6cd5f11047921fe41bb3c5 Mon Sep 17 00:00:00 2001 From: "Cheng-Han, Wu" Date: Fri, 27 May 2016 13:38:59 +0800 Subject: [PATCH] Update textcomplete rules to support more conditions and fix hint typo --- public/js/index.js | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/public/js/index.js b/public/js/index.js index 8671af4..76edf02 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -116,11 +116,11 @@ var supportReferrals = [ search: '[]()' }, { - text: '![image text][reference]', + text: '![image alt][reference]', search: '![][]' }, { - text: '![image text](url "title")', + text: '![image alt](url "title")', search: '![]()' }, { @@ -2959,8 +2959,10 @@ function matchInContainer(text) { $(editor.getInputField()) .textcomplete([ { // emoji strategy - match: /(?:^|\n|)\B:([\-+\w]*)$/, + match: /(^|\n|\s)\B:([\-+\w]*)$/, search: function (term, callback) { + var line = editor.getLine(editor.getCursor().line); + term = line.match(this.match)[2]; var list = []; $.map(emojify.emojiNames, function (emoji) { if (emoji.indexOf(term) === 0) //match at first character @@ -2976,7 +2978,7 @@ $(editor.getInputField()) return ' ' + value; }, replace: function (value) { - return ':' + value + ':'; + return '$1:' + value + ': '; }, index: 1, context: function (text) { @@ -3033,9 +3035,8 @@ $(editor.getInputField()) match: /(^|\n):::(\s*)(\w*)$/, search: function (term, callback) { var line = editor.getLine(editor.getCursor().line); - term = line.match(this.match)[3]; + term = line.match(this.match)[3].trim(); var list = []; - term = term.trim(); $.map(this.containers, function (container) { if (container.indexOf(term) === 0 && container !== term) list.push(container); @@ -3079,13 +3080,17 @@ $(editor.getInputField()) } }, { //extra tags for blockquote - match: /(?:^|\n|\s)(\>.*)(\[\])(\w*)$/, + match: /(?:^|\n|\s)(\>.*|)((\^|)\[(\^|)\](\[\]|\(\)|\:|))(\w*)$/, search: function (term, callback) { + var line = editor.getLine(editor.getCursor().line); + quote = line.match(this.match)[1].trim(); var list = []; - $.map(supportExtraTags, function (extratag) { - if (extratag.search.indexOf(term) === 0) - list.push(extratag.command()); - }); + if (quote.indexOf('>') == 0) { + $.map(supportExtraTags, function (extratag) { + if (extratag.search.indexOf(term) === 0) + list.push(extratag.command()); + }); + } $.map(supportReferrals, function (referral) { if (referral.search.indexOf(term) === 0) list.push(referral.text); @@ -3121,7 +3126,7 @@ $(editor.getInputField()) } }, { //referral - match: /(^|\n|\s)(\!|\!|\[\])(\w*)$/, + match: /(^|\n|\s)(\!(\[\]|)(\[\]|\(\)|))(\w*)$/, search: function (term, callback) { callback($.map(supportReferrals, function (referral) { return referral.search.indexOf(term) === 0 ? referral.text : null;