Giter VIP home page Giter VIP logo

Comments (7)

stefano-salari avatar stefano-salari commented on June 8, 2024

I have solved the problem in my project with a patch in the spellchecker.js code. What I changed it's the regex declared at line 588. The regex was:

var regExp = '';
regExp += '([^' + letterChars + '])';
regExp += '(' + incorrectWords.join('|') + ')';
regExp += '(?=[^' + letterChars + '])';

I changed with:

var regExp = '';
regExp += '([^' + letterChars + ']*)';
regExp += '(' + incorrectWords.join('|') + ')';
regExp += '(?=[^' + letterChars + ']*)';

In my project it seems to solve the problem, I don't know if it introduces issues in other cases but it might be a hint for you.

Please, let me know if I can help somehow.

from jquery-spellchecker.

binario200 avatar binario200 commented on June 8, 2024

Great job man, my QA team reports me that missing highlight word as a bug; As same as you I don't know it this could impact other functionality of the spellchecker.

Thank you.

from jquery-spellchecker.

stefano-salari avatar stefano-salari commented on June 8, 2024

Thank you for your reply! Please, let me know if I can help you.

from jquery-spellchecker.

SugarRoll avatar SugarRoll commented on June 8, 2024

It works on the highlighting but when we choose a word from the suggestions, the word is not modified.

from jquery-spellchecker.

tomatau avatar tomatau commented on June 8, 2024

I've fixed this bug by reusing the Regex from the text parser

        var regExp = '';
        regExp += '(^|[^' + letterChars + '])';
        regExp += '(' + incorrectWords.join('|') + ')';
        regExp += '(?=[^' + letterChars + ']|$)';

from jquery-spellchecker.

bryandevvv avatar bryandevvv commented on June 8, 2024

I'm still having this same issue, though in a contenteditable div. The first word will not be highlighted, and also a word right after a newline ("br" inside div).

I tried the regex mentioned above:
var regExp = '';
regExp += '([^' + letterChars + '])';
regExp += '(' + incorrectWords.join('|') + ')';
regExp += '(?=[^' + letterChars + ']
)';
and also one mentioned in similar listed bug:
var regExp = '';
regExp += '([^' + letterChars + ']?)';
regExp += '(' + incorrectWords.join('|') + ')';
regExp += '(?=[^' + letterChars + ']?)';

Both fix the issue of first word being highlighted, BUT they both also allow words within words to be highlighted. Like "booz" is one of the words and marked misspelled, but "booz" of "booze" is also highlighted.

Using the regex from elsewhere in the lib does not solve the first highlight or after newline highlight for me:
var regExp = '';
regExp += '(^|[^' + letterChars + '])';
regExp += '(' + incorrectWords.join('|') + ')';
regExp += '(?=[^' + letterChars + ']|$)';

Help!

Thanks

from jquery-spellchecker.

bendman avatar bendman commented on June 8, 2024

The issue is worsened because it joins words between nodes before checking them. This way, if you have a word like foo_bar_baz it will match across the inline styles. This causes an issue with words at the ends of block level nodes though, for instance: <p>wierd</p><p>wierd</p> do not get highlighted because it is matching wierdwierd against weird when trying to hightlight.

This is fixable by adding a newline character before the closing tags of visually spaced block level elements. This character isn't visible in the rendered HTML, but it does get transformed into a space when comparing, which turns the example into wierd wierd which matches.

Also, as mentioned above, it doesn't account for words at the beginning or end of the entire checked area, so we need to account for begin and end characters (^ and $).

I fixed this in my code by doing this for the highlightWords function:

  HtmlParser.prototype.highlightWords = function(incorrectWords, element) {
    if (!incorrectWords.length) {
      return;
    }

    // add newlines at block level elements, for cross-node matching later
    element.html(element.html().replace(/\n?(<((\/(div|p|td|th|li|dt|dd))|br\/?)>)/gi, '\n$1'));

    this.incorrectWords = incorrectWords;
    incorrectWords = $.map(incorrectWords, function(word) {
      return RegExp.escape(word);
    });

    var regExp = '';
    regExp += '(^|[^' + letterChars + '])';
    regExp += '(' + incorrectWords.join('|') + ')';
    regExp += '(?=[^' + letterChars + ']|$)';

    this.replaceText(new RegExp(regExp, 'g'), element[0], this.highlightWordsHandler(incorrectWords), 2);
  };

Notice the element.html(...) part which adds newlines to the ends of visually breaking block level elements, as well as the ^ and $ characters added to the regExp as others did above.

from jquery-spellchecker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.