mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-21 23:09:40 +00:00
reduce nesting levels in markMisspelledWords; simplify range check of fontspan
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35369 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
c4d00e85eb
commit
7b0c3c0daf
@ -174,11 +174,9 @@ private:
|
||||
// 1. first of new range inside current range or
|
||||
// 2. last of new range inside current range or
|
||||
// 3. first of current range inside new range or
|
||||
// 4. last of current range inside new range or
|
||||
if ((fc.first <= fp.first && fp.first <= fc.last) ||
|
||||
(fc.first <= fp.last && fp.last <= fc.last) ||
|
||||
(fp.first <= fc.first && fc.first <= fp.last) ||
|
||||
(fp.first <= fc.last && fc.last <= fp.last))
|
||||
// 4. last of current range inside new range
|
||||
if (fc.inside(fp.first) || fc.inside(fp.last) ||
|
||||
fp.inside(fc.first) || fp.inside(fc.last))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@ -365,6 +363,17 @@ public:
|
||||
last = endpos;
|
||||
}
|
||||
|
||||
int countSoftbreaks(PositionsIterator & it, PositionsIterator const et, pos_type & start) const
|
||||
{
|
||||
int numbreaks = 0;
|
||||
while (it != et && *it < start) {
|
||||
++start;
|
||||
++numbreaks;
|
||||
++it;
|
||||
}
|
||||
return numbreaks;
|
||||
}
|
||||
|
||||
void markMisspelledWords(pos_type const & first, pos_type const & last,
|
||||
SpellChecker::Result result,
|
||||
docstring const & word,
|
||||
@ -3505,8 +3514,11 @@ void Paragraph::Private::markMisspelledWords(
|
||||
docstring const & word,
|
||||
Positions const & softbreaks)
|
||||
{
|
||||
if (!SpellChecker::misspelled(result)) {
|
||||
setMisspelled(first, last, SpellChecker::WORD_OK);
|
||||
return;
|
||||
}
|
||||
pos_type snext = first;
|
||||
if (SpellChecker::misspelled(result)) {
|
||||
SpellChecker * speller = theSpellChecker();
|
||||
// locate and enumerate the error positions
|
||||
int nerrors = speller->numMisspelledWords();
|
||||
@ -3517,33 +3529,27 @@ void Paragraph::Private::markMisspelledWords(
|
||||
int wstart;
|
||||
int wlen = 0;
|
||||
speller->misspelledWord(index, wstart, wlen);
|
||||
if (wlen) {
|
||||
/// should not happen if speller supports range checks
|
||||
if (!wlen) continue;
|
||||
docstring const misspelled = word.substr(wstart, wlen);
|
||||
wstart += first + numbreaks;
|
||||
if (snext < wstart) {
|
||||
while (it != et && *it < wstart) {
|
||||
++wstart;
|
||||
++numbreaks;
|
||||
++it;
|
||||
}
|
||||
/// mark the range of correct spelling
|
||||
numbreaks += countSoftbreaks(it, et, wstart);
|
||||
setMisspelled(snext,
|
||||
wstart - 1, SpellChecker::WORD_OK);
|
||||
}
|
||||
snext = wstart + wlen;
|
||||
while (it != et && *it < snext) {
|
||||
++snext;
|
||||
++numbreaks;
|
||||
++it;
|
||||
}
|
||||
numbreaks += countSoftbreaks(it, et, snext);
|
||||
/// mark the range of misspelling
|
||||
setMisspelled(wstart, snext, result);
|
||||
LYXERR(Debug::GUI, "misspelled word: \"" <<
|
||||
misspelled << "\" [" <<
|
||||
wstart << ".." << (snext-1) << "]");
|
||||
++snext;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (snext <= last) {
|
||||
/// mark the range of correct spelling at end
|
||||
setMisspelled(snext, last, SpellChecker::WORD_OK);
|
||||
}
|
||||
}
|
||||
@ -3558,7 +3564,7 @@ void Paragraph::spellCheck() const
|
||||
pos_type endpos;
|
||||
d->rangeOfSpellCheck(start, endpos);
|
||||
if (speller->canCheckParagraph()) {
|
||||
// loop until we leave the range argument
|
||||
// loop until we leave the range
|
||||
for (pos_type first = start; first < endpos; ) {
|
||||
pos_type last = endpos;
|
||||
Private::Positions softbreaks;
|
||||
|
@ -77,6 +77,10 @@ public:
|
||||
return first == s.first && last == s.last;
|
||||
}
|
||||
|
||||
inline bool inside(pos_type p) const
|
||||
{
|
||||
return first <= p && p <= last;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user