Commit cd1106c0 authored by Alan (Maciej) Paruszewski's avatar Alan (Maciej) Paruszewski Committed by Nicolò Maria Mezzopera

Add ^ as a special reference for to GFM Autocomplete

This change adds ability to use ^ as a special reference in Markdown
Editor.
parent fe352403
...@@ -14,6 +14,7 @@ export default function initGFMInput($els) { ...@@ -14,6 +14,7 @@ export default function initGFMInput($els) {
milestones: enableGFM, milestones: enableGFM,
mergeRequests: enableGFM, mergeRequests: enableGFM,
labels: enableGFM, labels: enableGFM,
vulnerabilities: enableGFM,
}); });
}); });
} }
...@@ -52,6 +52,7 @@ export const defaultAutocompleteConfig = { ...@@ -52,6 +52,7 @@ export const defaultAutocompleteConfig = {
milestones: true, milestones: true,
labels: true, labels: true,
snippets: true, snippets: true,
vulnerabilities: true,
}; };
class GfmAutoComplete { class GfmAutoComplete {
...@@ -647,7 +648,8 @@ class GfmAutoComplete { ...@@ -647,7 +648,8 @@ class GfmAutoComplete {
// https://github.com/ichord/At.js // https://github.com/ichord/At.js
const atSymbolsWithBar = Object.keys(controllers) const atSymbolsWithBar = Object.keys(controllers)
.join('|') .join('|')
.replace(/[$]/, '\\$&'); .replace(/[$]/, '\\$&')
.replace(/[+]/, '\\+');
const atSymbolsWithoutBar = Object.keys(controllers).join(''); const atSymbolsWithoutBar = Object.keys(controllers).join('');
const targetSubtext = subtext.split(GfmAutoComplete.regexSubtext).pop(); const targetSubtext = subtext.split(GfmAutoComplete.regexSubtext).pop();
const resultantFlag = flag.replace(/[-[\]/{}()*+?.\\^$|]/g, '\\$&'); const resultantFlag = flag.replace(/[-[\]/{}()*+?.\\^$|]/g, '\\$&');
...@@ -678,6 +680,7 @@ GfmAutoComplete.atTypeMap = { ...@@ -678,6 +680,7 @@ GfmAutoComplete.atTypeMap = {
'~': 'labels', '~': 'labels',
'%': 'milestones', '%': 'milestones',
'/': 'commands', '/': 'commands',
'+': 'vulnerabilities',
$: 'snippets', $: 'snippets',
}; };
......
...@@ -16,5 +16,6 @@ export default (initGFM = true) => { ...@@ -16,5 +16,6 @@ export default (initGFM = true) => {
milestones: initGFM, milestones: initGFM,
labels: initGFM, labels: initGFM,
snippets: initGFM, snippets: initGFM,
vulnerabilities: initGFM,
}); });
}; };
...@@ -14,6 +14,7 @@ document.addEventListener('DOMContentLoaded', () => { ...@@ -14,6 +14,7 @@ document.addEventListener('DOMContentLoaded', () => {
milestones: false, milestones: false,
labels: false, labels: false,
snippets: false, snippets: false,
vulnerabilities: false,
}; };
const projectSnippetOptions = {}; const projectSnippetOptions = {};
......
...@@ -174,6 +174,7 @@ export default { ...@@ -174,6 +174,7 @@ export default {
milestones: this.enableAutocomplete, milestones: this.enableAutocomplete,
labels: this.enableAutocomplete && !this.glFeatures.tributeAutocomplete, labels: this.enableAutocomplete && !this.glFeatures.tributeAutocomplete,
snippets: this.enableAutocomplete, snippets: this.enableAutocomplete,
vulnerabilities: this.enableAutocomplete,
}); });
}, },
beforeDestroy() { beforeDestroy() {
......
...@@ -16,6 +16,10 @@ class GfmAutoCompleteEE extends GfmAutoComplete { ...@@ -16,6 +16,10 @@ class GfmAutoCompleteEE extends GfmAutoComplete {
this.setupAutoCompleteEpics($input, this.getDefaultCallbacks()); this.setupAutoCompleteEpics($input, this.getDefaultCallbacks());
} }
if (this.enableMap.vulnerabilities) {
this.setupAutoCompleteVulnerabilities($input, this.getDefaultCallbacks());
}
super.setupAtWho($input); super.setupAtWho($input);
} }
...@@ -51,6 +55,40 @@ class GfmAutoCompleteEE extends GfmAutoComplete { ...@@ -51,6 +55,40 @@ class GfmAutoCompleteEE extends GfmAutoComplete {
}, },
}); });
}; };
setupAutoCompleteVulnerabilities = ($input, defaultCallbacks) => {
$input.atwho({
at: '+',
alias: 'vulnerabilities',
searchKey: 'search',
displayTpl(value) {
let tmpl = GfmAutoComplete.Loading.template;
if (value.title != null) {
tmpl = GfmAutoComplete.Issues.templateFunction(value);
}
return tmpl;
},
data: GfmAutoComplete.defaultLoadingData,
insertTpl: GfmAutoComplete.Issues.insertTemplateFunction,
skipSpecialCharacterTest: true,
callbacks: {
...defaultCallbacks,
beforeSave(merges) {
return merges.map(m => {
if (m.title == null) {
return m;
}
return {
id: m.id,
title: m.title.replace(/<(?:.|\n)*?>/gm, ''),
reference: m.reference,
search: `${m.id} ${m.title}`,
};
});
},
},
});
};
} }
export default GfmAutoCompleteEE; export default GfmAutoCompleteEE;
---
title: Add + as a special reference for to GFM Autocomplete
merge_request: 42190
author:
type: added
...@@ -119,7 +119,7 @@ describe('GfmAutoComplete', () => { ...@@ -119,7 +119,7 @@ describe('GfmAutoComplete', () => {
const defaultMatcher = (context, flag, subtext) => const defaultMatcher = (context, flag, subtext) =>
gfmAutoCompleteCallbacks.matcher.call(context, flag, subtext); gfmAutoCompleteCallbacks.matcher.call(context, flag, subtext);
const flagsUseDefaultMatcher = ['@', '#', '!', '~', '%', '$']; const flagsUseDefaultMatcher = ['@', '#', '!', '~', '%', '$', '+'];
const otherFlags = ['/', ':']; const otherFlags = ['/', ':'];
const flags = flagsUseDefaultMatcher.concat(otherFlags); const flags = flagsUseDefaultMatcher.concat(otherFlags);
...@@ -153,7 +153,6 @@ describe('GfmAutoComplete', () => { ...@@ -153,7 +153,6 @@ describe('GfmAutoComplete', () => {
'я', 'я',
'.', '.',
"'", "'",
'+',
'-', '-',
'_', '_',
]; ];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment