#7220 correct spell check state ranges for word splits

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37146 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Stephan Witt 2011-01-07 15:20:58 +00:00
parent 8882b2b68f
commit 64d9fed8c3
2 changed files with 32 additions and 15 deletions

View File

@ -137,7 +137,30 @@ public:
void setRange(FontSpan const fp, SpellChecker::Result state)
{
eraseCoveredRanges(fp);
Ranges result;
RangesIterator et = ranges_.end();
RangesIterator it = ranges_.begin();
for (; it != et; ++it) {
if (!it->covered(fp))
result.push_back(SpellResultRange(it->range(), it->result()));
else if (state == SpellChecker::WORD_OK) {
// trim or split the current misspelled range
// store misspelled ranges only
FontSpan range = it->range();
if (fp.first > range.first) {
// misspelled area in front of WORD_OK
range.last = fp.first - 1;
result.push_back(SpellResultRange(range, it->result()));
range = it->range();
}
if (fp.last < range.last) {
// misspelled area after WORD_OK range
range.first = fp.last + 1;
result.push_back(SpellResultRange(range, it->result()));
}
}
}
ranges_ = result;
if (state != SpellChecker::WORD_OK)
ranges_.push_back(SpellResultRange(fp, state));
}
@ -207,8 +230,10 @@ public:
if (pos > refresh_.last)
refresh_.last = pos;
} else if (pos != -1) {
refresh_.first = pos;
refresh_.last = pos;
// init request check for neighbour positions too
refresh_.first = pos > 0 ? pos - 1 : 0;
// no need for special end of paragraph check
refresh_.last = pos + 1;
}
needs_refresh_ = pos != -1;
}
@ -231,18 +256,6 @@ private:
SpellChecker::ChangeNumber current_change_number_;
void eraseCoveredRanges(FontSpan const fp)
{
Ranges result;
RangesIterator et = ranges_.end();
RangesIterator it = ranges_.begin();
for (; it != et; ++it) {
if (!it->covered(fp))
result.push_back(SpellResultRange(it->range(), it->result()));
}
ranges_ = result;
}
void correctRangesAfterPos(pos_type pos, int offset)
{
RangesIterator et = ranges_.end();

View File

@ -82,6 +82,10 @@ public:
return first <= p && p <= last;
}
inline bool empty() const
{
return first > last;
}
};
///