standardnotes / react-blank-slate

A blank canvas for creating a ReactJS component
GNU Affero General Public License v3.0
6 stars 5 forks source link

Use word boundaries for word matching? #17

Open ryanpcmcquen opened 4 years ago

ryanpcmcquen commented 4 years ago

Is there a reason the analyzeNote function doesn't use word boundaries?

  analyzeNote() {
    var s = this.state.note.content.text;
    s = s.replace(/(^\s*)|(\s*$)/gi,"");//exclude  start and end white-space
    s = s.replace(/[ ]{2,}/gi," ");//2 or more space to 1
    s = s.replace(/\n /,"\n"); // exclude newline with a start spacing
    let wordCount = s.split(' ').length;
    this.setState({wordCount: wordCount});
  }

Would become:

  analyzeNote() {
    // Count all word boundaries in the note text and divide by 2
    // to get the word count:
    let wordCount = this.state.note.content.text.match(/\b/gm).length / 2;
    this.setState({wordCount: wordCount});
  }

If this is OK, I'll set up PRs to change it here and in the documentation.

ryanpcmcquen commented 4 years ago

Example: https://repl.it/@ryanpcmcquen/BonyLiquidBase

moughxyz commented 4 years ago

I suppose that could work. However the Action Bar extension is located here: https://github.com/standardnotes/action-bar

This repo is just an example project.

ryanpcmcquen commented 4 years ago

OK, I'll fix it in all 3 places.

ryanpcmcquen commented 4 years ago

@mobitar, it's been PR'ed in all three places!

ryanpcmcquen commented 4 years ago

https://github.com/sn-extensions/react-blank-slate/pull/18 https://github.com/standardnotes/action-bar/pull/19 https://github.com/standardnotes/docs/pull/13