Refactoring: move check for match in spellignore() to buffer params.

This commit is contained in:
Stephan Witt 2021-03-07 17:46:01 +01:00
parent 430327152a
commit 07122f066b
4 changed files with 27 additions and 29 deletions

View File

@ -616,6 +616,23 @@ IgnoreList const & BufferParams::spellignore() const
}
bool BufferParams::spellignored(WordLangTuple const & wl) const
{
bool has_item = false;
vector<WordLangTuple> il = spellignore();
vector<WordLangTuple>::const_iterator it = il.begin();
for (; it != il.end(); ++it) {
if (it->lang()->code() != wl.lang()->code())
continue;
if (it->word() == wl.word()) {
has_item = true;
break;
}
}
return has_item;
}
Bullet & BufferParams::temp_bullet(lyx::size_type const index)
{
LASSERT(index < 4, return pimpl_->temp_bullets[0]);

View File

@ -341,6 +341,7 @@ public:
///
IgnoreList & spellignore();
IgnoreList const & spellignore() const;
bool spellignored(WordLangTuple const & wl) const;
/**
* The LyX name of the input encoding for LaTeX. This can be one of
* - \c auto: find out the input encoding from the used languages

View File

@ -464,8 +464,7 @@ public:
pos_type const & first, pos_type const & last,
SpellChecker::Result result,
docstring const & word,
SkipPositions const & skips,
vector<WordLangTuple> const & docdict);
SkipPositions const & skips);
InsetCode ownerCode() const
{
@ -4930,8 +4929,7 @@ void Paragraph::Private::markMisspelledWords(
pos_type const & first, pos_type const & last,
SpellChecker::Result result,
docstring const & word,
SkipPositions const & skips,
vector<WordLangTuple> const & docdict)
SkipPositions const & skips)
{
if (!SpellChecker::misspelled(result)) {
setMisspelled(first, last, SpellChecker::WORD_OK);
@ -4951,7 +4949,6 @@ void Paragraph::Private::markMisspelledWords(
/// should not happen if speller supports range checks
if (!wlen)
continue;
docstring const candidate = word.substr(wstart, wlen);
wstart += first + numskipped;
if (snext < wstart) {
/// mark the range of correct spelling
@ -4961,26 +4958,20 @@ void Paragraph::Private::markMisspelledWords(
}
snext = wstart + wlen;
// Check whether the candidate is in the document's local dict
vector<WordLangTuple>::const_iterator iit = docdict.begin();
WordLangTuple const candidate(word.substr(wstart, wlen), lang);
SpellChecker::Result actresult = result;
for (; iit != docdict.end(); ++iit) {
if (iit->lang()->code() != lang->code())
continue;
if (iit->word() == candidate) {
actresult = SpellChecker::WORD_OK;
break;
}
}
if (inset_owner_->buffer().params().spellignored(candidate))
actresult = SpellChecker::WORD_OK;
numskipped += countSkips(it, et, snext);
/// mark the range of misspelling
setMisspelled(wstart, snext, actresult);
if (actresult == SpellChecker::WORD_OK)
LYXERR(Debug::GUI, "local dictionary word: \"" <<
candidate << "\" [" <<
candidate.word() << "\" [" <<
wstart << ".." << (snext-1) << "]");
else
LYXERR(Debug::GUI, "misspelled word: \"" <<
candidate << "\" [" <<
candidate.word() << "\" [" <<
wstart << ".." << (snext-1) << "]");
++snext;
}
@ -5013,8 +5004,7 @@ void Paragraph::spellCheck() const
BufferParams const & bparams = d->inset_owner_->buffer().params();
SpellChecker::Result result = !word.empty() ?
speller->check(wl, bparams.spellignore()) : SpellChecker::WORD_OK;
d->markMisspelledWords(lang, first, last, result, word, skips,
bparams.spellignore());
d->markMisspelledWords(lang, first, last, result, word, skips);
first = ++last;
}
} else {

View File

@ -2745,17 +2745,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
}
}
WordLangTuple wl(word, language);
bool has_item = false;
vector<WordLangTuple> il = bv->buffer().params().spellignore();
vector<WordLangTuple>::const_iterator it = il.begin();
for (; it != il.end(); ++it) {
if (it->lang()->code() != wl.lang()->code())
continue;
if (it->word() == wl.word()) {
has_item = true;
break;
}
}
bool const has_item = bv->buffer().params().spellignored(wl);
if (!has_item) {
cur.recordUndoBufferParams();
bv->buffer().params().spellignore().push_back(wl);