Stephan Witt <st.w...@gmx.net> writes: > I've made some changes again... shorten lines as Jürgen suggested and > formatting of if/while. And I added code to handle the soft-hyphens > and friends. > > So I attach it again and hope I can put it in later. JMarc, can you > have a look, please?
See below. Nice work. JMarc > +int AppleSpellChecker::numMisspelledWords() const > +{ > + return numMisspelledWordsAppleSpeller(d->speller); > +} It might be nice, short of having proper objc++ files, to rename the objc helper functions to something more obvious like AppleSpeller_numMisspelledWords (or even AS_numMisspelledWords). > --- src/Text2.cpp (Revision 35252) > +++ src/Text2.cpp (Arbeitskopie) > @@ -356,6 +356,9 @@ > Font f = tm.displayFont(pit, pos); > f.update(font, language, toggleall); > setCharFont(pit, pos, f, tm.font_); > + // font change may change language... > + // spell checker has to know that > + pars_[pit].requestSpellCheck(); > } > } > > - void setMisspelled(bool misspelled) { misspelled_ = misspelled; } > - /// > - bool isMisspelled() const { return misspelled_; } > - /// Yay! > Index: src/Paragraph.cpp > =================================================================== > --- src/Paragraph.cpp (Revision 35252) > +++ src/Paragraph.cpp (Arbeitskopie) > @@ -73,8 +73,107 @@ > char_type const META_INSET = 0x200001; > }; > > + > ///////////////////////////////////////////////////////////////////// > // > +// Paragraph::SpellRanges > +// > +///////////////////////////////////////////////////////////////////// > + > +class Paragraph::SpellCheckerState { What is the real name? Does it need to be in Paragraph, or can it be in Paragraph::Private? Or can it even be toplevel? > +private: > + /// store the ranges as map of FontSpan and spell result pairs > + typedef map<FontSpan, SpellChecker::Result> Ranges; > + typedef map<FontSpan, SpellChecker::Result>::const_iterator > RangesIterator; > + Ranges ranges_; typedef map<FontSpan, SpellChecker::Result> Ranges; typedef Ranges::const_iterator const_iterator; > + void eraseCoveredRanges(FontSpan const fp) > + void correctRangesAfterPos(pos_type pos, int offset) I do not see why you need that. After all, the spellchecking is done linearly in the paragraph, and thus all you have to do is to append to the Range object (actually, a list<> and some push_back would be enough). I would have a std::list that lists the ranges for misspelled words. Wouldn't that be enough? > + Language * locateSpellRange( > + pos_type & from, pos_type & to, > + Positions & softbreaks) const; Maybe: Language * locateSpellRange(pos_type & from, pos_type & to, Positions & softbreaks) const; > + void setMisspelled(pos_type from, pos_type to, SpellChecker::Result > state) As I wrote, this one is probably not needed either. > @@ -297,6 +425,7 @@ > // Add a new entry in the fontlist_. > fontlist_.set(fcit->pos() - beg, fcit->font()); > } > + requestSpellCheck(); > } I guess the question with this change and the others is whether you have covered all the possibilities for modifying the paragraph. Time will tell, I guess. > + while (last < to && !owner_->isWordSeparator(last)) { > + if (owner_->getInset(last)) { > + softbreaks.insert(softbreaks.end(), last); > + } > + ++last; > + } Can you explain what the softbreaks variable is for? > + /// start position and length of misspelled word at index > + virtual void misspelledWord( > + int index, > + int & start, int & length) const > + { > + /// index is used here to make the compiler happy > + if (index == 0) > + start = 0; > + length = 0; > + } > + Why not make this misspelledWord method pure virtual? BTW, If you want to avoid warnings about variables, all you have to do is: virtual void misspelledWord(int /*index*/, int & /*start*/, int & /*length*/) const