Skip to content

Commit f985b3a

Browse files
committed
Revert "add mentions"
This reverts commit cae4bb0.
1 parent cae4bb0 commit f985b3a

File tree

1 file changed

+17
-51
lines changed

1 file changed

+17
-51
lines changed

src/js/simplemde.js

Lines changed: 17 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,68 @@
1-
/* eslint-disable no-useless-escape */
21
/*global require,module*/
32
"use strict";
43
var CodeMirror = require("codemirror");
54
require("codemirror/addon/edit/continuelist.js");
65
require("./codemirror/tablist");
76
require("codemirror/addon/display/fullscreen.js");
87
require("codemirror/mode/markdown/markdown.js");
9-
require("codemirror/addon/hint/show-hint.js");
108
require("codemirror/addon/mode/overlay.js");
9+
require("codemirror/addon/hint/show-hint.js");
1110
require("codemirror/addon/display/placeholder.js");
1211
require("codemirror/addon/selection/mark-selection.js");
1312
require("codemirror/mode/gfm/gfm.js");
1413
require("codemirror/mode/xml/xml.js");
1514
var CodeMirrorSpellChecker = require("codemirror-spell-checker");
1615
var marked = require("marked");
1716

18-
1917
var currentEditorHelperHint;
2018

21-
CodeMirror.defineOption("autoSuggest", [], function(cm, autoSuggestOptions) {
19+
CodeMirror.defineOption("autoSuggest", [], function(cm, autoSuggestOptions, old) {
2220
cm.on("inputRead", function(cm, change) {
2321
var mode = cm.getModeAt(cm.getCursor());
2422

25-
var currentTrigger = undefined;
26-
for(var trigger in autoSuggestOptions.triggers) {
27-
if(trigger === change.text[0]) {
28-
currentTrigger = trigger;
29-
}
30-
}
31-
32-
var forEachHint = function(action) {
33-
var hintsElement = document.querySelector(".CodeMirror-hints");
34-
if(hintsElement) {
35-
var hints = hintsElement.querySelectorAll(".CodeMirror-hint");
36-
for(var i = 0; i < hints.length; i++) {
37-
var hint = hints[i];
38-
action(hint);
39-
}
40-
}
41-
};
42-
43-
var setHintActive = function(event) {
44-
forEachHint(function(hint) {
45-
hint.classList.remove("CodeMirror-hint-active");
46-
});
47-
event.target.classList.add("CodeMirror-hint-active");
48-
};
49-
50-
forEachHint(function(hint) {
51-
hint.removeEventListener("mouseenter", setHintActive);
52-
});
53-
54-
if(mode.name === autoSuggestOptions.mode && currentTrigger) {
23+
if(mode.name === autoSuggestOptions.mode && autoSuggestOptions.startChars.indexOf(change.text[0]) != -1) {
5524

5625
currentEditorHelperHint = autoSuggestOptions;
5726
currentEditorHelperHint.startChar = change.text[0];
5827

5928
cm.showHint({
6029
completeSingle: false,
6130
closeCharacters: /[\v()\[\]{};:>,]/,
62-
className: "hints",
63-
hint: function(cm) {
31+
hint: function(cm, options) {
6432
var cur = cm.getCursor(),
6533
token = cm.getTokenAt(cur);
6634
var start = token.start + 1,
6735
end = token.end;
6836

6937
var line = cm.getCursor().line,
70-
lineToStarChar = cm.getLine(line).substring(0, start),
38+
ch = cm.getCursor().ch,
39+
stringToMatch = currentEditorHelperHint.startChar,
40+
n = stringToMatch.length,
41+
lineToStarChar = cm.getLine(line).substring(0, token.start + 1),
7142
charBeforeStarChar = lineToStarChar.substring(cm.getLine(line).lastIndexOf(currentEditorHelperHint.startChar) - 1, cm.getLine(line).lastIndexOf(currentEditorHelperHint.startChar)),
72-
stringToTest = lineToStarChar.substring(cm.getLine(line).lastIndexOf(currentEditorHelperHint.startChar), start);
43+
stringToTest = lineToStarChar.substring(cm.getLine(line).lastIndexOf(currentEditorHelperHint.startChar), token.start + 1);
7344

74-
if(charBeforeStarChar != " " && charBeforeStarChar != "") {
45+
if(charBeforeStarChar != ' ' && charBeforeStarChar != '') {
7546
return false;
7647
}
7748

78-
var callbackResult = currentEditorHelperHint.triggers[currentTrigger](stringToTest);
49+
var listCallback = currentEditorHelperHint.listCallback(stringToTest);
7950

80-
if(callbackResult.length == 0) {
51+
if(listCallback.length == 0) {
8152
return false;
8253
}
8354

8455
return {
85-
list: callbackResult,
56+
list: listCallback,
8657
from: CodeMirror.Pos(cur.line, cm.getLine(line).lastIndexOf(currentEditorHelperHint.startChar)),
8758
to: CodeMirror.Pos(cur.line, end)
8859
};
8960
}
9061
});
91-
92-
forEachHint(function(hint) {
93-
hint.addEventListener("mouseenter", setHintActive);
94-
});
9562
}
9663
});
9764
});
9865

99-
10066
// Some variables
10167
var isMac = /Mac/.test(navigator.platform);
10268

@@ -1411,8 +1377,8 @@ function SimpleMDE(options) {
14111377
}
14121378

14131379
// Add custom toolbar actions
1414-
if(options.additionalToolbarButtons !== undefined) {
1415-
for(var index in options.additionalToolbarButtons) {
1380+
if (options.additionalToolbarButtons !== undefined) {
1381+
for (var index in options.additionalToolbarButtons) {
14161382
options.toolbar.push(options.additionalToolbarButtons[index]);
14171383
}
14181384
}
@@ -1582,7 +1548,7 @@ SimpleMDE.prototype.render = function(el) {
15821548
allowDropFileTypes: ["text/plain"],
15831549
placeholder: options.placeholder || el.getAttribute("placeholder") || "",
15841550
styleSelectedText: (options.styleSelectedText != undefined) ? options.styleSelectedText : true,
1585-
autoSuggest: (options.autoSuggest != undefined) ? options.autoSuggest : null,
1551+
autoSuggest: (options.autoSuggest != undefined) ? options.autoSuggest : NULL
15861552
});
15871553

15881554
if(options.forceSync === true) {
@@ -2113,4 +2079,4 @@ SimpleMDE.prototype.toTextArea = function() {
21132079
}
21142080
};
21152081

2116-
module.exports = SimpleMDE;
2082+
module.exports = SimpleMDE;

0 commit comments

Comments
 (0)