Am 02.02.2011 um 10:59 schrieb Edwin Leuven:

> On Wed, Feb 2, 2011 at 09:33, Stephan Witt <st.w...@gmx.net> wrote:
>> Finally I have a basically working solution. See the attached patch.
> 
> thanks! it compiles fine
> 
>> I know, I've to add some comments. Please, can anyone try it?
> 
> so the idea is that words that are being typed are not marked? i don't
> see this...

Sorry, one changed file was missing in patch.
This is the complete patch.

The missing file in patch is src/BufferView.cpp

Stephan

Index: src/Paragraph.h
===================================================================
--- src/Paragraph.h     (Revision 37410)
+++ src/Paragraph.h     (Arbeitskopie)
@@ -77,12 +77,34 @@
        {
                return first == s.first && last == s.last;
        }
-       
+
        inline bool inside(pos_type p) const
        {
                return first <= p && p <= last;
        }
 
+       inline size_t size() const
+       {
+               return empty() ? 0 : last - first;
+       }
+       
+
+       inline FontSpan intersect(FontSpan const & f) const
+       {
+               FontSpan result = FontSpan();
+               if (inside(f.first))
+                       result.first = f.first;
+               else if (f.inside(first))
+                       result.first = first;
+               else
+                       return result;
+               if (inside(f.last))
+                       result.last = f.last;
+               else if (f.inside(last))
+                       result.last = last;
+               return result;
+       }
+       
        inline bool empty() const
        {
                return first > last;
Index: src/DocIterator.h
===================================================================
--- src/DocIterator.h   (Revision 37410)
+++ src/DocIterator.h   (Arbeitskopie)
@@ -25,6 +25,7 @@
 class Paragraph;
 class Text;
 class InsetIterator;
+class FontSpan;
 
 DocIterator doc_iterator_begin(Buffer const * buf, Inset const * inset = 0);
 DocIterator doc_iterator_end(Buffer const * buf, Inset const * inset = 0);
@@ -162,6 +163,8 @@
        /// return the inner text slice.
        CursorSlice const & innerTextSlice() const;
        ///
+       FontSpan locateWord(word_location const loc) const;
+       ///
        Text * text() const;
        /// the containing inset or the cell, respectively
        Inset * realInset() const;
Index: src/DocIterator.cpp
===================================================================
--- src/DocIterator.cpp (Revision 37410)
+++ src/DocIterator.cpp (Arbeitskopie)
@@ -192,6 +192,16 @@
 }
 
 
+FontSpan DocIterator::locateWord(word_location const loc) const
+{
+       FontSpan f = FontSpan();
+
+       f.first = pos();
+       top().paragraph().locateWord(f.first, f.last, loc);
+       return f;
+}
+
+       
 CursorSlice const & DocIterator::innerTextSlice() const
 {
        LASSERT(!empty(), /**/);
Index: src/Cursor.h
===================================================================
--- src/Cursor.h        (Revision 37410)
+++ src/Cursor.h        (Arbeitskopie)
@@ -292,6 +292,11 @@
        ///
        void checkBufferStructure();
 
+       DocIterator newWord() const { return new_word_; }
+       void markEditPosition();
+       void clearEditPosition();
+       void checkEditPosition();
+
 public:
 //private:
        
@@ -305,6 +310,8 @@
        BufferView * bv_;
        /// the anchor position
        DocIterator anchor_;
+       /// the start of the new born word
+       DocIterator new_word_;
        ///
        mutable DispatchResult disp_;
        /**
Index: src/Cursor.cpp
===================================================================
--- src/Cursor.cpp      (Revision 37410)
+++ src/Cursor.cpp      (Arbeitskopie)
@@ -503,6 +503,7 @@
 void Cursor::resetAnchor()
 {
        anchor_ = *this;
+       checkEditPosition();
 }
 
 
@@ -519,6 +520,38 @@
 }
 
 
+void Cursor::markEditPosition()
+{
+       if (inTexted() && new_word_.empty()) {
+               FontSpan ow = locateWord(WHOLE_WORD);
+               if (ow.size() == 1)
+                       new_word_ = *this;
+       }
+}
+
+
+void Cursor::clearEditPosition()
+{
+       if (!new_word_.empty())
+               new_word_.resize(0);
+}
+
+
+void Cursor::checkEditPosition()
+{
+       if (inTexted() && !new_word_.empty()) {
+               if (paragraph().id() != new_word_.paragraph().id())
+                       clearEditPosition();
+               else {
+                       FontSpan ow = locateWord(WHOLE_WORD);
+                       FontSpan nw = new_word_.locateWord(WHOLE_WORD);
+                       if (nw.intersect(ow).empty())
+                               clearEditPosition();
+               }
+       }
+}
+
+
 bool Cursor::posBackward()
 {
        if (pos() == 0)
Index: src/BufferView.cpp
===================================================================
--- src/BufferView.cpp  (Revision 37410)
+++ src/BufferView.cpp  (Arbeitskopie)
@@ -700,6 +700,7 @@
 
 void BufferView::bookmarkEditPosition()
 {
+       d->cursor_.markEditPosition();
        // Don't eat cpu time for each keystroke
        if (d->cursor_.paragraph().id() == d->bookmark_edit_position_)
                return;
Index: src/rowpainter.cpp
===================================================================
--- src/rowpainter.cpp  (Revision 37410)
+++ src/rowpainter.cpp  (Arbeitskopie)
@@ -415,10 +415,10 @@
                // 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();
+               DocIterator const nw = bv->cursor().newWord();
                bool current_word = false;
-               if (cur.inTexted() && par_.id() == cur.paragraph().id()) {
-                       pos_type cpos = cur.pos();
+               if (!nw.empty() && nw.inTexted() && par_.id() == 
nw.paragraph().id()) {
+                       pos_type cpos = nw.pos();
                        if (cpos > 0 && cpos == par_.size() && 
!par_.isWordSeparator(cpos-1))
                                --cpos;
                        else if (cpos > 0 && par_.isWordSeparator(cpos))

Reply via email to