Am 08.04.2011 um 09:38 schrieb Jean-Pierre Chrétien:

> Abdelrazak Younes a écrit :
>> On 04/03/2011 08:38 PM, Jean-Pierre Chrétien wrote:
>>> Hello,
>>> 
>>> Using the spellchecker window, I get this quite often when I hit 'Ignore 
>>> all':
>>> 
>>> <cite>
>>> We reached the end of the document, would you like to continue from the 
>>> beginning?
>>> </cite>
>>> 
>>> If I say yes, it restars at the beginning, which is not what I want.
>>> If I say no, it goes on where I was, which is I want, but it's a bore to 
>>> acknowledge the message all the time.
>>> 
>>> Found nothing on Trac, new bug ?
>> Yes, new one, please create an entry for it. I probably won't have time to 
>> fix it this week but maybe Stephan will... :-P
> 
> Not done yet as I'm just back home after a trip, and I see Stephan committed 
> a patch about this and other problems with spekllcheck: I will test it before 
> posting any new bug.
> 

Please note, I did not commit all patches I posted to the list until now.
In case you notice problems - what I expect - it would be nice
if you can apply these patches and test it. I'll attach them again.
The first one is for the spell checker dialog, the 2nd one is for
marking single dashes misspelled wrongly.

Stephan

Index: src/frontends/qt4/GuiSpellchecker.h
===================================================================
--- src/frontends/qt4/GuiSpellchecker.h (Revision 38299)
+++ src/frontends/qt4/GuiSpellchecker.h (Arbeitskopie)
@@ -31,12 +31,12 @@
        Q_OBJECT
 
 public:
-       SpellcheckerWidget(GuiView * gv, QWidget * parent = 0);
+       SpellcheckerWidget(GuiView * gv, DockView * dv, QWidget * parent = 0);
        ~SpellcheckerWidget();
        ///
        void updateView();
        ///
-       bool initialiseParams(std::string const & data);
+       bool initialiseParams(std::string const &);
 
 private Q_SLOTS:
        void on_findNextPB_clicked();
@@ -71,7 +71,7 @@
 private:
        ///{
        void updateView();
-       bool initialiseParams(std::string const &) { return true; }
+       bool initialiseParams(std::string const & data) { return 
widget_->initialiseParams(data); }
        void clearParams() {}
        void dispatchParams() {}
        bool isBufferDependent() const { return false; }
Index: src/frontends/qt4/GuiSpellchecker.cpp
===================================================================
--- src/frontends/qt4/GuiSpellchecker.cpp       (Revision 38299)
+++ src/frontends/qt4/GuiSpellchecker.cpp       (Arbeitskopie)
@@ -59,8 +59,8 @@
 
 struct SpellcheckerWidget::Private
 {
-       Private(SpellcheckerWidget * parent)
-               : p(parent) {}
+       Private(SpellcheckerWidget * parent, DockView * dv)
+               : p(parent), dv_(dv), start_(true), incheck_(false) {}
        /// update from controller
        void updateSuggestions(docstring_list & words);
        /// move to next position after current word
@@ -71,19 +71,33 @@
        bool continueFromBeginning();
        ///
        void setLanguage(Language const * lang);
+       /// test and set guard flag
+       bool inCheck() {
+               if (incheck_)
+                       return true;
+               incheck_ = true;
+               return false;
+       }
+       void canCheck() { incheck_ = false; }
        ///
        Ui::SpellcheckerUi ui;
        ///
        SpellcheckerWidget * p;
        ///
        GuiView * gv_;
+       ///
+       DockView * dv_;
        /// current word being checked and lang code
        WordLangTuple word_;
+       ///
+       bool start_;
+       ///
+       bool incheck_;
 };
 
 
-SpellcheckerWidget::SpellcheckerWidget(GuiView * gv, QWidget * parent)
-       : QTabWidget(parent), d(new Private(this))
+SpellcheckerWidget::SpellcheckerWidget(GuiView * gv, DockView * dv, QWidget * 
parent)
+       : QTabWidget(parent), d(new Private(this, dv))
 {
        d->ui.setupUi(this);
        d->gv_ = gv;
@@ -161,7 +175,8 @@
 {
        BufferView * bv = d->gv_->documentBufferView();
        setEnabled(bv != 0);
-       if (bv && hasFocus()) {
+       if (bv && hasFocus() && d->start_) {
+               d->start_ = false;
 
                BufferView * bv = d->gv_->documentBufferView();
                std::set<Language const *> languages = 
@@ -181,8 +196,10 @@
                        qt_("We reached the end of the document, would you like 
to "
                                "continue from the beginning?"),
                        QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
-               if (answer == QMessageBox::No)
+               if (answer == QMessageBox::No) {
+                       dv_->hide();
                        return false;
+               }
                dispatch(FuncRequest(LFUN_BUFFER_BEGIN));
                return true;
 }
@@ -195,7 +212,7 @@
 
        dispatch(FuncRequest(LFUN_ESCAPE));
        dispatch(FuncRequest(LFUN_CHAR_FORWARD));
-       if (bv->cursor().atLastPos()) {
+       if (bv->cursor().depth() <= 1 && bv->cursor().atLastPos()) {
                continueFromBeginning();
                return;
        }
@@ -218,64 +235,96 @@
 }
 
 
+bool SpellcheckerWidget::initialiseParams(std::string const &)
+{
+       d->start_ = true;
+       return true;
+}
+
+
 void SpellcheckerWidget::on_ignoreAllPB_clicked()
 {
-       /// replace all occurrences of word
+       /// ignore all occurrences of word
+       if (d->inCheck())
+               return;
+       LYXERR(Debug::GUI, "Spellchecker: ignore all button");
        if (d->word_.lang() && !d->word_.word().empty())
                theSpellChecker()->accept(d->word_);
        d->forward();
        d->check();
+       d->canCheck();
 }
 
 
 void SpellcheckerWidget::on_addPB_clicked()
 {
        /// insert word in personal dictionary
+       if (d->inCheck())
+               return;
+       LYXERR(Debug::GUI, "Spellchecker: add word button");
        theSpellChecker()->insert(d->word_);
        d->forward();
        d->check();
+       d->canCheck();
 }
 
 
 void SpellcheckerWidget::on_ignorePB_clicked()
 {
+       /// ignore this occurrence of word
+       if (d->inCheck())
+               return;
+       LYXERR(Debug::GUI, "Spellchecker: ignore button");
        d->forward();
        d->check();
+       d->canCheck();
 }
 
 
 void SpellcheckerWidget::on_findNextPB_clicked()
 {
-       docstring const data = find2string(
-                               qstring_to_ucs4(d->ui.wordED->text()),
+       if (d->inCheck())
+               return;
+       docstring const textfield = qstring_to_ucs4(d->ui.wordED->text());
+       docstring const datastring = find2string(textfield,
                                true, true, true);
-       dispatch(FuncRequest(LFUN_WORD_FIND, data));
+       LYXERR(Debug::GUI, "Spellchecker: find next (" << textfield << ")");
+       dispatch(FuncRequest(LFUN_WORD_FIND, datastring));
+       d->canCheck();
 }
 
 
 void SpellcheckerWidget::on_replacePB_clicked()
 {
+       if (d->inCheck())
+               return;
+       docstring const textfield = qstring_to_ucs4(d->ui.wordED->text());
        docstring const replacement = 
qstring_to_ucs4(d->ui.replaceCO->currentText());
-       docstring const data = replace2string(
-               replacement, qstring_to_ucs4(d->ui.wordED->text()),
+       docstring const datastring = replace2string(replacement, textfield,
                true, true, false, false);
 
        LYXERR(Debug::GUI, "Replace (" << replacement << ")");
-       dispatch(FuncRequest(LFUN_WORD_REPLACE, data));
+       dispatch(FuncRequest(LFUN_WORD_REPLACE, datastring));
        d->forward();
        d->check();
+       d->canCheck();
 }
 
 
 void SpellcheckerWidget::on_replaceAllPB_clicked()
 {
-       docstring const data = replace2string(
-               qstring_to_ucs4(d->ui.replaceCO->currentText()),
-               qstring_to_ucs4(d->ui.wordED->text()),
+       if (d->inCheck())
+               return;
+       docstring const textfield = qstring_to_ucs4(d->ui.wordED->text());
+       docstring const replacement = 
qstring_to_ucs4(d->ui.replaceCO->currentText());
+       docstring const datastring = replace2string(replacement, textfield,
                true, true, true, true);
-       dispatch(FuncRequest(LFUN_WORD_REPLACE, data));
+
+       LYXERR(Debug::GUI, "Replace all (" << replacement << ")");
+       dispatch(FuncRequest(LFUN_WORD_REPLACE, datastring));
        d->forward();
        d->check(); // continue spellchecking
+       d->canCheck();
 }
 
 
@@ -317,6 +366,7 @@
        WordLangTuple word_lang;
        docstring_list suggestions;
 
+       LYXERR(Debug::GUI, "Spellchecker: start check at " << from);
        int progress;
        try {
                progress = bv->buffer().spellCheck(from, to, word_lang, 
suggestions);
@@ -355,7 +405,7 @@
        : DockView(parent, "spellchecker", qt_("Spellchecker"),
                   area, flags)
 {
-       widget_ = new SpellcheckerWidget(&parent);
+       widget_ = new SpellcheckerWidget(&parent, this);
        setWidget(widget_);
        setFocusProxy(widget_);
 }
/Users/Shared/LyX ~/cvs/lyx
Index: src/Paragraph.h
===================================================================
--- src/Paragraph.h     (Revision 38299)
+++ src/Paragraph.h     (Arbeitskopie)
@@ -420,6 +420,9 @@
        bool isChar(pos_type pos) const;
        /// True if the element at this point is a space
        bool isSpace(pos_type pos) const;
+       /// True if the element at this point is a hard hyphen or a quote
+       /// If it is enclosed by spaces return false
+       bool isHardHyphenOrQuote(pos_type pos) const;
 
        /// returns true if at least one line break or line separator has been 
deleted
        /// at the beginning of the paragraph (either physically or logically)
Index: src/Paragraph.cpp
===================================================================
--- src/Paragraph.cpp   (Revision 38299)
+++ src/Paragraph.cpp   (Arbeitskopie)
@@ -2847,25 +2847,43 @@
 
 bool Paragraph::isWordSeparator(pos_type pos) const
 {
+       if (pos == size())
+               return true;
        if (Inset const * inset = getInset(pos))
                return !inset->isLetter();
-       if (pos == size())
-               return true;
+       // if we have a hard hyphen (no en- or emdash) or quote
+       // we pass this to the spell checker
+       // FIXME: this method is subject to change, visit
+       // https://bugzilla.mozilla.org/show_bug.cgi?id=355178
+       // to get an impression how complex this is.
+       if (isHardHyphenOrQuote(pos))
+               return false;
        char_type const c = d->text_[pos];
-       // if we have a hard hyphen (no en- or emdash),
-       // we pass this to the spell checker
-       if (c == '-') {
-               int j = pos + 1;
-               if ((j == size() || d->text_[j] != '-')
-                   && (pos == 0 || d->text_[pos - 1] != '-'))
-                       return false;
-       }
-       // We want to pass the ' and escape chars to the spellchecker
-       static docstring const quote = from_utf8(lyxrc.spellchecker_esc_chars + 
'\'');
-       return (!isLetterChar(c) && !isDigitASCII(c) && !contains(quote, c));
+       // We want to pass the escape chars to the spellchecker
+       docstring const escape_chars = from_utf8(lyxrc.spellchecker_esc_chars);
+       return !isLetterChar(c) && !isDigitASCII(c) && !contains(escape_chars, 
c);
 }
 
 
+bool Paragraph::isHardHyphenOrQuote(pos_type pos) const
+{
+       pos_type const psize = size();
+       if (pos >= psize)
+               return false;
+       char_type const c = d->text_[pos];
+       if (c != '-' && c != '\'')
+               return false;
+       int nextpos = pos + 1;
+       int prevpos = pos > 0 ? pos - 1 : 0;
+       if ((nextpos == psize || isSpace(nextpos))
+               && (pos == 0 || isSpace(prevpos)))
+               return false;
+       return c == '\''
+               || ((nextpos == psize || d->text_[nextpos] != '-')
+               && (pos == 0 || d->text_[prevpos] != '-'));
+}
+
+
 bool Paragraph::isSameSpellRange(pos_type pos1, pos_type pos2) const
 {
        return pos1 == pos2

Reply via email to