Index: gc_lang/fr/tb/content/overlay.js ================================================================== --- gc_lang/fr/tb/content/overlay.js +++ gc_lang/fr/tb/content/overlay.js @@ -340,12 +340,43 @@ let xNodeSuggLine = document.createElement("p"); xNodeSuggLine.setAttribute("class", "suggestions"); let xNodeSuggButton = document.createElement("span"); xNodeSuggButton.setAttribute("class", "suggestions_button"); xNodeSuggButton.textContent = "Suggestions : "; - xNodeSuggButton.addEventListener("click", function (e) { - if (this.bDictActive === null) { + xNodeSuggButton.addEventListener("click", (e) => { + let xPromise = this.xGCEWorker.post('suggest', [dErr['sValue'], 10]); + xPromise.then( + function (sVal) { + console.log(sVal); + if (sVal != "") { + let lSugg = sVal.split("|"); + let n = 0; + for (let sSugg of lSugg) { + if (true || n > 0) { + xNodeSuggLine.appendChild(document.createTextNode(" ")); + } + let xNodeSugg = document.createElement("span"); + xNodeSugg.setAttribute("class", "sugg"); + xNodeSugg.textContent = sSugg; + xNodeSugg.addEventListener("click", function (e) { + xEditor.changeParagraph(iParagraph, xNodeSugg.textContent, dErr["nStart"], dErr["nEnd"]); + xNodeDiv.textContent = ""; + that.reparseParagraph(xEditor, iParagraph); + }); + xNodeSuggLine.appendChild(xNodeSugg); + n += 1; + } + } else { + xNodeSuggLine.appendChild(document.createTextNode("Aucune suggestion.")); + } + + }, + function (aReason) { console.error('Promise rejected - ', aReason); } + ).catch( + function (aCaught) { console.error('Promise Error - ', aCaught); } + ); + /*if (this.bDictActive === null) { this.bDictActive = oSpellControl.setDictionary("fr"); } try { let aSugg = oSpellControl.suggest(dErr['sValue']); if (aSugg) { @@ -370,11 +401,11 @@ } } catch (e) { xNodeSuggLine.appendChild(document.createTextNode("# Erreur : dictionnaire orthographique introuvable.")); Cu.reportError(e); - } + }*/ }); xNodeSuggLine.appendChild(xNodeSuggButton); xNodeDiv.appendChild(xNodeSuggLine); return xNodeDiv; }, Index: gc_lang/fr/tb/worker/gce_worker.js ================================================================== --- gc_lang/fr/tb/worker/gce_worker.js +++ gc_lang/fr/tb/worker/gce_worker.js @@ -107,10 +107,18 @@ function parseAndSpellcheck (sText, sCountry, bDebug, bContext) { let aGrammErr = gce.parse(sText, sCountry, bDebug, bContext); let aSpellErr = oSpellChecker.parseParagraph(sText); return JSON.stringify({ aGrammErr: aGrammErr, aSpellErr: aSpellErr }); } + +function suggest (sWord, nSuggLimit=10) { + let lSugg = [] + for (let aSugg of oSpellChecker.suggest(sWord, nSuggLimit)) { + lSugg.push(...aSugg); + } + return lSugg.join("|"); +} function getOptions () { return gce.getOptions().gl_toString(); } Index: graphspell-js/str_transform.js ================================================================== --- graphspell-js/str_transform.js +++ graphspell-js/str_transform.js @@ -211,8 +211,14 @@ } }; if (typeof(exports) !== 'undefined') { + exports.longestCommonSubstring = str_transform.longestCommonSubstring; + exports.distanceDamerauLevenshtein = str_transform.distanceDamerauLevenshtein; + exports.distanceDamerauLevenshtein2 = str_transform.distanceDamerauLevenshtein2; + exports.showDistance = str_transform.showDistance; exports.changeWordWithSuffixCode = str_transform.changeWordWithSuffixCode; exports.changeWordWithAffixCode = str_transform.changeWordWithAffixCode; + exports.defineAffixCode = str_transform.defineAffixCode; + exports.defineSuffixCode = str_transform.defineSuffixCode; }