Am 31.01.2011 um 14:30 schrieb Stephan Witt:

> Am 29.01.2011 um 21:14 schrieb Stephan Witt:
> 
>> Am 29.01.2011 um 20:40 schrieb Edwin Leuven:
>> 
>>> Stephan Witt <st.w...@gmx.net> wrote:
>>> 
>>>> I already checked open-office, eclipse and apple mail.
>>>> All of them don't mark an unfinished word at first.
>>>> 
>>>> Apple mail has exact the same behavior as LyX has now.
>>>> Office and eclipse are doing the same as you are describing for word.
>>> 
>>> so wouldn't we like to maintain the misspell marker on word entry?
>> 
>> To be honest, the current implementation already was no simplification
>> of the code - to go on and add the distinction between first edit
>> and the latter ones when painting the misspelled marker is doable, but...
>> I may have a look, but I wouldn't wait with 2.0.0 beta4 because of that.
> 
> Dear buffer-view/cursor-experts,
> 
> I'm looking for a possibility to decide if the current cursor position is
> inside the word the user currently is "creating". Is there any infrastructure
> in place to help to solve that problem? I imagine something like a range
> variable starting to exist when the first character of a word is entered,
> growing until the user leaves this area or enters some delimiter like space
> or punctuation. When the word is complete this range should vanish (become 
> empty).
> 
> The only thing far related to this is the anchor of cursor, AFAICS.

Finally I have a basically working solution. See the attached patch.
I know, I've to add some comments. Please, can anyone try it?
I'd like to apply it if possible...

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/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