From 64d9fed8c3f7df4b886b3a8ed1bef993816ddb67 Mon Sep 17 00:00:00 2001 From: Stephan Witt Date: Fri, 7 Jan 2011 15:20:58 +0000 Subject: [PATCH] #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 --- src/Paragraph.cpp | 43 ++++++++++++++++++++++++++++--------------- src/Paragraph.h | 4 ++++ 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index 67965ef4c5..8eb49befbf 100644 --- a/src/Paragraph.cpp +++ b/src/Paragraph.cpp @@ -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(); diff --git a/src/Paragraph.h b/src/Paragraph.h index 762e97dc66..0e4372593a 100644 --- a/src/Paragraph.h +++ b/src/Paragraph.h @@ -82,6 +82,10 @@ public: return first <= p && p <= last; } + inline bool empty() const + { + return first > last; + } }; ///