Update SpellCheck.plugin.js

This commit is contained in:
Mirco Wittrien 2022-05-23 13:30:09 +02:00
parent 1a4fa710a8
commit ea73d41416
1 changed files with 22 additions and 16 deletions

View File

@ -2,7 +2,7 @@
* @name SpellCheck * @name SpellCheck
* @author DevilBro * @author DevilBro
* @authorId 278543574059057154 * @authorId 278543574059057154
* @version 1.6.0 * @version 1.6.1
* @description Adds a Spell Check to all Message Inputs. Select a Word and Right Click it to add it to your Dictionary * @description Adds a Spell Check to all Message Inputs. Select a Word and Right Click it to add it to your Dictionary
* @invite Jx3TjNS * @invite Jx3TjNS
* @donate https://www.paypal.me/MircoWittrien * @donate https://www.paypal.me/MircoWittrien
@ -17,8 +17,13 @@ module.exports = (_ => {
"info": { "info": {
"name": "SpellCheck", "name": "SpellCheck",
"author": "DevilBro", "author": "DevilBro",
"version": "1.6.0", "version": "1.6.1",
"description": "Adds a Spell Check to all Message Inputs. Select a Word and Right Click it to add it to your Dictionary" "description": "Adds a Spell Check to all Message Inputs. Select a Word and Right Click it to add it to your Dictionary"
},
"changeLog": {
"improved": {
"Conjoined Words": "Now properly splits conjoined words and checks each segment of the conjoinment, for example 'green-blue' will no longer show as error"
}
} }
}; };
@ -282,36 +287,37 @@ module.exports = (_ => {
spellCheckText (string) { spellCheckText (string) {
let htmlString = []; let htmlString = [];
string.replace(/\n/g, "\n ").split(" ").forEach(word => { let splitter = "!?!?!?!?!?!?!?!" + this.name + BDFDB.NumberUtils.generateId() + this.name + "!?!?!?!?!?!?!?!";
if (!word) htmlString.push(""); string.replace(/([0-9\ \@\>\<\|\,\;\.\:\-\_\#\+\*\~\\\´\`\}\=\]\)\[\(\{\/\&\^\t\r\n])/g, "$1" + splitter).split(splitter).forEach(word => {
else { let execReturn = /[0-9\ \@\>\<\|\,\;\.\:\-\_\#\+\*\~\\\´\`\}\=\]\)\[\(\{\/\&\^\t\r\n]$/g.exec(word);
let hasNewline = word.endsWith("\n"); if (execReturn) word = word.slice(0, execReturn[0].length * -1);
word = word.replace(/\n/g, ""); htmlString.push(`<span class="${this.isWordNotInDictionary(word) ? BDFDB.disCN._spellcheckerror : ""}" style="color: transparent !important; text-shadow: none !important;">${BDFDB.StringUtils.htmlEscape(word)}</span>`);
htmlString.push(`<span class="${this.isWordNotInDictionary(word) ? BDFDB.disCN._spellcheckerror : ""}" style="color: transparent !important; text-shadow: none !important;">${BDFDB.StringUtils.htmlEscape(word)}</span>${hasNewline ? "\n" : ""}`); if (execReturn) htmlString.push(`<span>${execReturn[0]}</span>`);
}
}); });
return htmlString.join("<span> </span>").replace(/\n /g, "\n"); return htmlString.join("").replace(/\n /g, "\n");
} }
replaceWord (editor, toBeReplaced, replacement) { replaceWord (editor, toBeReplaced, replacement) {
if (!editor) return; if (!editor) return;
toBeReplaced = toBeReplaced.toUpperCase(); toBeReplaced = toBeReplaced.toUpperCase();
let newString = []; let newString = [];
BDFDB.SlateUtils.toTextValue(editor.children).replace(/\n/g, "\n ").split(" ").forEach(word => { let splitter = "!?!?!?!?!?!?!?!" + this.name + BDFDB.NumberUtils.generateId() + this.name + "!?!?!?!?!?!?!?!";
let hasNewline = word.endsWith("\n"); BDFDB.SlateUtils.toTextValue(editor.children).replace(/([0-9\ \@\>\<\|\,\;\.\:\-\_\#\+\*\~\\\´\`\}\=\]\)\[\(\{\/\&\^\t\r\n])/g, "$1" + splitter).split(splitter).forEach(word => {
word = word.replace(/\n/g, ""); let execReturn = /[0-9\ \@\>\<\|\,\;\.\:\-\_\#\+\*\~\\\´\`\}\=\]\)\[\(\{\/\&\^\t\r\n]$/g.exec(word);
if (execReturn) word = word.slice(0, execReturn[0].length * -1);
if (word.toUpperCase() == toBeReplaced) { if (word.toUpperCase() == toBeReplaced) {
let firstLetter = word.charAt(0); let firstLetter = word.charAt(0);
let isCapitalised = firstLetter.toUpperCase() == firstLetter && firstLetter.toLowerCase() != firstLetter; let isCapitalised = firstLetter.toUpperCase() == firstLetter && firstLetter.toLowerCase() != firstLetter;
newString.push((isCapitalised ? replacement.charAt(0).toUpperCase() + replacement.slice(1) : replacement) + (hasNewline ? "\n" : "")); newString.push(isCapitalised ? replacement.charAt(0).toUpperCase() + replacement.slice(1) : replacement);
} }
else newString.push(word + (hasNewline ? "\n" : "")); else newString.push(word);
if (execReturn) newString.push(execReturn[0]);
}); });
editor.history.stack.splice(editor.history.index + 1, 0, { editor.history.stack.splice(editor.history.index + 1, 0, {
type: "other", type: "other",
mergeable: false, mergeable: false,
createdAt: new Date().getTime(), createdAt: new Date().getTime(),
value: BDFDB.SlateUtils.toRichValue(newString.join(" ").replace(/\n /g, "\n")), value: BDFDB.SlateUtils.toRichValue(newString.join("")),
selection: editor.history.stack[editor.history.index].selection selection: editor.history.stack[editor.history.index].selection
}); });
editor.redo(); editor.redo();