Declare empty_ as a static variable inside the getrange function. Or return
the object by value, but that might get costly.

Op 22 dec 2010 08:29 schreef <sw...@lyx.org>:

Author: switt
Date: Wed Dec 22 08:29:16 2010
New Revision: 36990
URL: http://www.lyx.org/trac/changeset/36990

Log:
fix for #7081: the painting of misspelled marker is suppressed for the word
at cursor position

Modified:
  lyx-devel/trunk/src/Paragraph.cpp
  lyx-devel/trunk/src/Paragraph.h
  lyx-devel/trunk/src/Text3.cpp
  lyx-devel/trunk/src/rowpainter.cpp

Modified: lyx-devel/trunk/src/Paragraph.cpp
==============================================================================
--- lyx-devel/trunk/src/Paragraph.cpp   Wed Dec 22 02:29:17 2010
 (r36989)
+++ lyx-devel/trunk/src/Paragraph.cpp   Wed Dec 22 08:29:16 2010
 (r36990)
@@ -173,6 +173,18 @@
               return result;
       }

+       FontSpan const & getRange(pos_type pos) const
+       {
+               RangesIterator et = ranges_.end();
+               RangesIterator it = ranges_.begin();
+               for (; it != et; ++it) {
+                       if(it->inside(pos)) {
+                               return it->range();
+                       }
+               }
+               return empty_;
+       }
+
       bool needsRefresh() const {
               return needs_refresh_;
       }
@@ -215,6 +227,8 @@
       bool needs_refresh_;
       /// spell state cache version number
       SpellChecker::ChangeNumber current_change_number_;
+       /// empty span to indicate mismatch for getRange()
+       FontSpan empty_;


       void eraseCoveredRanges(FontSpan const fp)
@@ -2825,6 +2839,13 @@
 }


+bool Paragraph::isSameSpellRange(pos_type pos1, pos_type pos2) const
+{
+       return pos1 == pos2
+               || d->speller_state_.getRange(pos1) ==
d->speller_state_.getRange(pos2);
+}
+
+
 bool Paragraph::isChar(pos_type pos) const
 {
       if (Inset const * inset = getInset(pos))

Modified: lyx-devel/trunk/src/Paragraph.h
==============================================================================
--- lyx-devel/trunk/src/Paragraph.h     Wed Dec 22 02:29:17 2010
 (r36989)
+++ lyx-devel/trunk/src/Paragraph.h     Wed Dec 22 08:29:16 2010
 (r36990)
@@ -452,6 +452,11 @@
       /// \return true if pointed position is misspelled.
       bool isMisspelled(pos_type pos) const;

+       /// \return true if both positions are inside the same
+       /// spell range - i.e. the same word.
+       /// use it for positions inside misspelled range only.
+       bool isSameSpellRange(pos_type pos1, pos_type pos2) const;
+
       /// spell check of whole paragraph
       /// remember results until call of requestSpellCheck()
       void spellCheck() const;

Modified: lyx-devel/trunk/src/Text3.cpp
==============================================================================
--- lyx-devel/trunk/src/Text3.cpp       Wed Dec 22 02:29:17 2010
 (r36989)
+++ lyx-devel/trunk/src/Text3.cpp       Wed Dec 22 08:29:16 2010
 (r36990)
@@ -477,7 +477,10 @@
       // Signals that a full-screen update is required
       bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action(),
               LyXAction::NoUpdate) || singleParUpdate);
-
+       int const last_pid = cur.paragraph().id();
+       pos_type const last_pos = cur.pos();
+       bool const last_misspelled = lyxrc.spellcheck_continuously &&
cur.paragraph().isMisspelled(cur.pos());
+
       FuncCode const act = cmd.action();
       switch (act) {

@@ -2171,6 +2174,18 @@

       needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();

+       if (lyxrc.spellcheck_continuously && !needsUpdate) {
+               // Check for misspelled text
+               // The redraw is useful because of the painting of
+               // misspelled markers depends on the cursor position.
+               // Trigger a redraw for cursor moves inside misspelled text.
+               if (cur.paragraph().id() == last_pid && cur.pos() !=
last_pos) {
+                       needsUpdate |= last_misspelled ||
cur.paragraph().isMisspelled(cur.pos());
+               } else if (cur.paragraph().id() != last_pid) {
+                       needsUpdate |= last_misspelled ||
cur.paragraph().isMisspelled(cur.pos());
+               }
+       }
+
       // FIXME: The cursor flag is reset two lines below
       // so we need to check here if some of the LFUN did touch that.
       // for now only Text::erase() and Text::backspace() do that.

Modified: lyx-devel/trunk/src/rowpainter.cpp
==============================================================================
--- lyx-devel/trunk/src/rowpainter.cpp  Wed Dec 22 02:29:17 2010
 (r36989)
+++ lyx-devel/trunk/src/rowpainter.cpp  Wed Dec 22 08:29:16 2010
 (r36990)
@@ -394,7 +394,7 @@
                                               lang == "farsi";

       // spelling correct?
-       bool const misspelled_ =
+       bool const misspelled =
               lyxrc.spellcheck_continuously && par_.isMisspelled(pos);

       // draw as many chars as we can
@@ -410,8 +410,21 @@

       paintForeignMark(orig_x, orig_font.language());

-       if (lyxrc.spellcheck_continuously && misspelled_) {
-               paintMisspelledMark(orig_x, changed);
+       if (lyxrc.spellcheck_continuously && misspelled) {
+               // check for cursor position
+               // don't draw misspelled marker for words at cursor position
+               // we don't want to disturb the process of text editing
+               BufferView const * bv = pi_.base.bv;
+               Cursor const & cur = bv->cursor();
+               bool current_word = false;
+               if (par_.id() == cur.paragraph().id()) {
+                       pos_type cpos = cur.pos();
+                       if (cpos > 0 && cpos == par_.size() &&
!par_.isWordSeparator(cpos-1))
+                               --cpos;
+                       current_word = par_.isSameSpellRange(pos, cpos) ;
+               }
+               if (!current_word)
+                       paintMisspelledMark(orig_x, changed);
       }
 }

Reply via email to