Spell-checking with options and contextmenu
Review Request #2207 — Created March 19, 2011 and discarded
- Spell-checking: highlight spell errors in changed lines. - Options: spell-checking, personal wordlist path options under settings/diffs - ContextMenu: ignore or add spell errors into personal wordlist with context menu on diff view page.
FireFox 3.6 Chromium 10.0
-
Cool stuff. Some work needed though to get it in shape.
-
-
Should probably be: super(SpellCheckerWithPWL, self).__init__(lang, ...) In fact, since we're just mostly using values that SpellChecker takes, you can do: def __init__(self, *args, **kwargs): super(SpellCheckerWithPWL, self).__init__(*args, **kwargs) Then you'll need to access pwl and lang, which I imagine you can get from 'self'? If not, include just those in the argument lists and what you pass to the parent constructor.
-
We can't really rely on this path. It won't be writable on a public server, and it's shared, which means it'll be problematic with multiple Review Board installs on one server. This will need to be created on demand (see my other post about this). It might be worth having a configurable field for the location of this. The file should, by default, live in the site's data/ directory. You can see some examples for building a valid location by looking at what we do for the logging settings.
-
-
I know it's a little bit more work, but all API communication should really happen through datastore.js APIs. This one should be simple, but you should have some representation in there.
-
The braces style isn't correct. It should be: if (o.className == 's_spellerr') { o.className = 's'; } else { o.className = 'c'; } Actually, you can even simplify this: o.className = (o.className == 's_spellerr' ? 's' : 'c');
-
-
-
-
One space indentation. "ignore" and "Add" are too generic. Please use "spellcheck_ignore" and "spellcheck_add" Also, {% trans "Ignore Once" %} and same for Add to Dictionary.
-
You'll need the proper decorators for this, like on other resources. @webapi_check_local_site @webapi_check_login_required @webapi_request_fields(...) with 'check' Also should have documentation for how this is used from an API standpoint.
-
-
-
-
DO
- Change Summary:
-
Documentation on resource.py rbAPICall in datastore.js
- Diff:
-
Revision 2 (+301 -5)
DO
- Change Summary:
-
Merge in options for spellchecking in settings/diff page. The path for personal wordlist can be typed in.
DO
- Change Summary:
-
Speed up spell-checking by focusing only on changed lines. Test done: for a diff with 176 changes in 4000+ lines, it costs about 0.2 seconds more for spell-checking. (3.2s generating diff w/o spell-checking and 3.4s generating diff with spell-checking.)
DO
- Summary:
-
Context Menu for 'ignore' and 'add to dictionary'Spell-checking with options and contextmenu
- Description:
-
~ Pop up Context Menu when right click on an spell error.
~ 'Ignore Once': only changes the style of target word at this time. ~ 'Add to Dictionary': add target word to local dictionary and won't appear next time. ~ -
Spell-checking: highlight spell errors in changed lines.
~ -
Options: spell-checking, personal wordlist path options under settings/diffs
~ -
ContextMenu: ignore or add spell errors into personal wordlist with context menu on diff view page.
- - - - TODO: dictionary_dir setting
-
-
-
-
-
-
You can speed this up even more by pre-compiling the regex. Near the top of the file (we have other regexes there), you can do: SPELL_CHECKED_SPANS_RE = re.compile('<span ....') Then: mark = SPELL_CHECKED_SPANS_RE.search(line[5]) Also, variable should just be 'm' for consistency, instead of 'mark'. I'll refer to it as 'm' in following comments. I'm a little concerned about this not finding more than one spelling error per line, though.
-
If you change the above regex to: '<span class="[sc]">(^<]*)</span>' Then you can just do: check = m.group(1)
-
-
I'm not exactly sure I know what all you're doing here, but I suspect we can make it much cleaner. Mind going over it with me?
-
Probably best not to initialize these if we don't have spell checking enabled. They could just be set to None otherwise.
-
-
Another speed improvement would be to have spell_check_lines 'yield' each item instead of returning an array. This is what's called a generator function. Instead of doing: def foo(): lines = [] for a in b: lines.append(something(a)) return lines You can do: def foo(): for a in b; yield something(a) You'd then modify new_chunk to explicitly do: list(lines), which will convert it to a list when needed. The advantages are that 1) we don't have to use memory for this list in spell_check_lines, 2) we only do effectively one iteration instead of one in spell_check_lines and another in new_chunk.
-
-
-
-
This doesn't do what you may expect it to do. It's no different than doing: language = siteconfig.get(...). You basically never want to store global variables that can change. Only constants. I thought I had a review covering what to do here but I can't find it.. Anyway, I think the purpose here is to not have to create SpellCheckers more than necessary? If so, here's what I suggest: 1) Store a spell_checker_cache dictionary, with the key being the language and the value being a SpellChecker instance. 2) Provide a get_spell_checker() function that takes the language and pwl. It will do: if language not in spell_checker_cache: spell_checker_cache[language] = SpellCheckerWithPWL(lang=language, pwl=pwl, filters=[...]) return spell_checker_cache[language]
-
-
-
-
-
-
No space before ; We don't actually want to set className to undefined, though, because an element can have multiple classes. Instead, specifically call $(word).removeClass('whatever').
-
-
These two lines should be: var gSpellCheck = new RB.SpellCheck(); I don't know that we want this in its own file though. I'd move it into diffviewer.js.
-
This may not do what you expect. This only operates on existing elements with a "spellerr" class. Since we load diffs asynchronously, you're going to find it doesn't work on some diffs. Instead, look at jQuery's $.live()
-
-
-
-
-
-
-
-
-
-
"If the word is already added, this will return :http:`304`." (Note that the :http: thing is a special thing understood by our documentation generation code.)
DO
- Change Summary:
-
Highlight spell errors in different strings and comments in one line.
- Diff:
-
Revision 5 (+483 -9)
- Screenshots:
-
able to deal with several strings and comments in a line