From 5d4993d62357e438b6211247278025040f3ae382 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Fri, 12 Aug 2016 18:16:36 -0500 Subject: [PATCH] Only autocomplete commands at the beginning of a line --- app/assets/javascripts/gfm_auto_complete.js.es6 | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/gfm_auto_complete.js.es6 b/app/assets/javascripts/gfm_auto_complete.js.es6 index 9be32ed5937..2e1cbb362a3 100644 --- a/app/assets/javascripts/gfm_auto_complete.js.es6 +++ b/app/assets/javascripts/gfm_auto_complete.js.es6 @@ -268,7 +268,7 @@ return _.template(tpl)(value); }, insertTpl: function(value) { - var tpl = "\n/${name} "; + var tpl = "/${name} "; var reference_prefix = null; if (value.params.length > 0) { reference_prefix = value.params[0][0]; @@ -282,7 +282,16 @@ callbacks: { sorter: this.DefaultOptions.sorter, filter: this.DefaultOptions.filter, - beforeInsert: this.DefaultOptions.beforeInsert + beforeInsert: this.DefaultOptions.beforeInsert, + matcher: function(flag, subtext, should_startWithSpace, acceptSpaceBar) { + var regexp = /(?:^|\n)\/([A-Za-z_]*)$/gi + var match = regexp.exec(subtext); + if (match) { + return match[1]; + } else { + return null; + } + } } }); return;