#9477 improved argument handling for LFUN_SPELLING_ADD,LFUN_SPELLING_IGNORE and LFUN_SPELLING_REMOVE (backport)

This commit is contained in:
Stephan Witt 2015-03-28 11:07:56 +01:00
parent c56d72ffa3
commit 2622c99dd5
3 changed files with 30 additions and 5 deletions

View File

@ -1016,6 +1016,7 @@ void LyXAction::init()
* \var lyx::FuncCode lyx::LFUN_SPELLING_ADD
* \li Action: Add the word under the cursor to the respective
* spell checker dictionary.
* The default for the language is retrieved from the cursor position.
* \li Syntax: spelling-add [<STRING>] [<LANG>]
* \li Params: <WORD>: word to add
<LANG>: language name (see file languages)
@ -1027,6 +1028,7 @@ void LyXAction::init()
* \var lyx::FuncCode lyx::LFUN_SPELLING_IGNORE
* \li Action: Let the spell checker ignore the word under the cursor
* in the current session for the given language.
* The default for the language is retrieved from the cursor position.
* \li Syntax: spelling-ignore [<WORD>] [<LANG>]
* \li Params: <WORD>: word to ignore
<LANG>: language name (see file languages)
@ -1038,9 +1040,10 @@ void LyXAction::init()
* \var lyx::FuncCode lyx::LFUN_SPELLING_REMOVE
* \li Action: Remove the word under the cursor from the respective
* spell checker dictionary.
* The default for the language is retrieved from the cursor position.
* \li Syntax: spelling-remove [<STRING>] [<LANG>]
* \li Params: <WORD>: word to remove
<LANG>: language name (see file languages)
* <LANG>: language name (see file languages)
* \li Origin: SWitt, 28 July 2010
* \endvar
*/

View File

@ -2241,8 +2241,13 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
word = cur.selectionAsString(false);
}
lang = const_cast<Language *>(cur.getFont().language());
} else
} else if (cmd.getArg(1).empty()) {
// optional language argument is missing
// use the language at cursor position
lang = const_cast<Language *>(cur.getFont().language());
} else {
lang = const_cast<Language *>(languages.getLanguage(cmd.getArg(1)));
}
WordLangTuple wl(word, lang);
theSpellChecker()->insert(wl);
break;
@ -2260,8 +2265,11 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
word = cur.selectionAsString(false);
}
lang = const_cast<Language *>(cur.getFont().language());
} else
} else if (cmd.getArg(1).empty()) {
lang = const_cast<Language *>(cur.getFont().language());
} else {
lang = const_cast<Language *>(languages.getLanguage(cmd.getArg(1)));
}
WordLangTuple wl(word, lang);
theSpellChecker()->accept(wl);
break;
@ -2279,8 +2287,11 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
word = cur.selectionAsString(false);
}
lang = const_cast<Language *>(cur.getFont().language());
} else
} else if (cmd.getArg(1).empty()) {
lang = const_cast<Language *>(cur.getFont().language());
} else {
lang = const_cast<Language *>(languages.getLanguage(cmd.getArg(1)));
}
WordLangTuple wl(word, lang);
theSpellChecker()->remove(wl);
break;
@ -2933,7 +2944,12 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
case LFUN_SPELLING_ADD:
case LFUN_SPELLING_IGNORE:
case LFUN_SPELLING_REMOVE:
enable = theSpellChecker();
enable = theSpellChecker() != NULL;
if (enable && !cmd.getArg(1).empty()) {
// validate explicitly given language
Language const * const lang = const_cast<Language *>(languages.getLanguage(cmd.getArg(1)));
enable &= lang != NULL;
}
break;
case LFUN_LAYOUT: {

View File

@ -139,6 +139,12 @@ What's new
- Fix consecutive merging of tabular cells.
- Fix crash with missing optional or wrong arguments for
* LFUN_SPELLING_ADD,
* LFUN_SPELLING_IGNORE and
* LFUN_SPELLING_REMOVE
(bug 9477).
* INTERNALS