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
|
// 1. first of new range inside current range or
|
||||||
// 2. last 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
|
// 3. first of current range inside new range or
|
||||||
// 4. last of current range inside new range or
|
// 4. last of current range inside new range
|
||||||
if ((fc.first <= fp.first && fp.first <= fc.last) ||
|
if (fc.inside(fp.first) || fc.inside(fp.last) ||
|
||||||
(fc.first <= fp.last && fp.last <= fc.last) ||
|
fp.inside(fc.first) || fp.inside(fc.last))
|
||||||
(fp.first <= fc.first && fc.first <= fp.last) ||
|
|
||||||
(fp.first <= fc.last && fc.last <= fp.last))
|
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -364,7 +362,18 @@ public:
|
|||||||
}
|
}
|
||||||
last = endpos;
|
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,
|
void markMisspelledWords(pos_type const & first, pos_type const & last,
|
||||||
SpellChecker::Result result,
|
SpellChecker::Result result,
|
||||||
docstring const & word,
|
docstring const & word,
|
||||||
@ -3505,45 +3514,42 @@ void Paragraph::Private::markMisspelledWords(
|
|||||||
docstring const & word,
|
docstring const & word,
|
||||||
Positions const & softbreaks)
|
Positions const & softbreaks)
|
||||||
{
|
{
|
||||||
|
if (!SpellChecker::misspelled(result)) {
|
||||||
|
setMisspelled(first, last, SpellChecker::WORD_OK);
|
||||||
|
return;
|
||||||
|
}
|
||||||
pos_type snext = first;
|
pos_type snext = first;
|
||||||
if (SpellChecker::misspelled(result)) {
|
SpellChecker * speller = theSpellChecker();
|
||||||
SpellChecker * speller = theSpellChecker();
|
// locate and enumerate the error positions
|
||||||
// locate and enumerate the error positions
|
int nerrors = speller->numMisspelledWords();
|
||||||
int nerrors = speller->numMisspelledWords();
|
int numbreaks = 0;
|
||||||
int numbreaks = 0;
|
PositionsIterator it = softbreaks.begin();
|
||||||
PositionsIterator it = softbreaks.begin();
|
PositionsIterator et = softbreaks.end();
|
||||||
PositionsIterator et = softbreaks.end();
|
for (int index = 0; index < nerrors; ++index) {
|
||||||
for (int index = 0; index < nerrors; ++index) {
|
int wstart;
|
||||||
int wstart;
|
int wlen = 0;
|
||||||
int wlen = 0;
|
speller->misspelledWord(index, wstart, wlen);
|
||||||
speller->misspelledWord(index, wstart, wlen);
|
/// should not happen if speller supports range checks
|
||||||
if (wlen) {
|
if (!wlen) continue;
|
||||||
docstring const misspelled = word.substr(wstart, wlen);
|
docstring const misspelled = word.substr(wstart, wlen);
|
||||||
wstart += first + numbreaks;
|
wstart += first + numbreaks;
|
||||||
if (snext < wstart) {
|
if (snext < wstart) {
|
||||||
while (it != et && *it < wstart) {
|
/// mark the range of correct spelling
|
||||||
++wstart;
|
numbreaks += countSoftbreaks(it, et, wstart);
|
||||||
++numbreaks;
|
setMisspelled(snext,
|
||||||
++it;
|
wstart - 1, SpellChecker::WORD_OK);
|
||||||
}
|
|
||||||
setMisspelled(snext,
|
|
||||||
wstart - 1, SpellChecker::WORD_OK);
|
|
||||||
}
|
|
||||||
snext = wstart + wlen;
|
|
||||||
while (it != et && *it < snext) {
|
|
||||||
++snext;
|
|
||||||
++numbreaks;
|
|
||||||
++it;
|
|
||||||
}
|
|
||||||
setMisspelled(wstart, snext, result);
|
|
||||||
LYXERR(Debug::GUI, "misspelled word: \"" <<
|
|
||||||
misspelled << "\" [" <<
|
|
||||||
wstart << ".." << (snext-1) << "]");
|
|
||||||
++snext;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
snext = wstart + wlen;
|
||||||
|
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) {
|
if (snext <= last) {
|
||||||
|
/// mark the range of correct spelling at end
|
||||||
setMisspelled(snext, last, SpellChecker::WORD_OK);
|
setMisspelled(snext, last, SpellChecker::WORD_OK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3558,7 +3564,7 @@ void Paragraph::spellCheck() const
|
|||||||
pos_type endpos;
|
pos_type endpos;
|
||||||
d->rangeOfSpellCheck(start, endpos);
|
d->rangeOfSpellCheck(start, endpos);
|
||||||
if (speller->canCheckParagraph()) {
|
if (speller->canCheckParagraph()) {
|
||||||
// loop until we leave the range argument
|
// loop until we leave the range
|
||||||
for (pos_type first = start; first < endpos; ) {
|
for (pos_type first = start; first < endpos; ) {
|
||||||
pos_type last = endpos;
|
pos_type last = endpos;
|
||||||
Private::Positions softbreaks;
|
Private::Positions softbreaks;
|
||||||
|
@ -77,7 +77,11 @@ public:
|
|||||||
return first == s.first && last == s.last;
|
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