On Fri, Dec 09, 2005 at 11:15:50PM +0100, Jean-Marc Lasgouttes wrote:
> >>>>> "Andre" == Andre Poenitz <[EMAIL PROTECTED]> writes:
> 
> Andre> Would it help if I came up with a ParagraphList implementation
> Andre> wrapping a vector that avoids that problem?
> 
> Yes, I think so.

First shot attached.

This is supposed to handle directly the case of insertion of a single
paragraph far from the end of the document.

While I cannot see anything getting worse, the par id still go up
quickly. More precisely, the id of the first par of the UserGuide is
6183.  Hit enter on the first line, then go down to the par now
containing the "The LyX User Guide" heading. With this patch it has id
10294, without 12300 + x. So while there is some improvement this does
not seem to be the only problem.

Btw, I noticed an unrelated redrawing bug (unchanged by this patch):

New doc
a<enter>
a<enter>
a<enter>
a<enter>
a<enter>
a<enter>
<left><left>
<backspace>
<backspace>
<backspace>
<backspace>
<backspace>

The lower paragraphs do not get redrawn correctly.

Andre'
Index: InsetList.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/InsetList.h,v
retrieving revision 1.15
diff -u -p -r1.15 InsetList.h
--- InsetList.h 19 Jan 2005 15:03:27 -0000      1.15
+++ InsetList.h 11 Dec 2005 21:04:26 -0000
@@ -68,6 +68,8 @@ public:
        void increasePosAfterPos(lyx::pos_type pos);
        ///
        void decreasePosAfterPos(lyx::pos_type pos);
+       ///
+       void swap(InsetList & other) { list_.swap(other.list_); }
 
 private:
        ///
Index: paragraph.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph.C,v
retrieving revision 1.417
diff -u -p -r1.417 paragraph.C
--- paragraph.C 25 Nov 2005 14:40:34 -0000      1.417
+++ paragraph.C 11 Dec 2005 21:04:30 -0000
@@ -70,6 +70,33 @@ ParagraphList::ParagraphList()
 {}
 
 
+ParagraphList::iterator ParagraphList::insert
+       (iterator pos, const Paragraph & par)
+{
+       //return BaseType::insert(pos, par);
+       ptrdiff_t const p = pos - begin();
+       push_back(par);
+       for (ptrdiff_t i = size() - 1; i > p; --i)
+               (*this)[i].swap((*this)[i - 1]);
+       return begin() + p;
+}
+
+
+ParagraphList::iterator ParagraphList::erase(iterator pos)
+{
+       return BaseType::erase(pos);
+       if (pos == end())
+               return pos;
+       iterator curr = pos;
+       iterator next = pos;
+       for (++next; next != end(); ++curr, ++next)
+               pos->swap(*next);
+       pop_back();
+       ++pos;
+       return pos;
+}
+
+
 Paragraph::Paragraph()
        : begin_of_body_(0), pimpl_(new Paragraph::Pimpl(this))
 {
@@ -1854,3 +1881,20 @@ void Paragraph::dump() const
                rows_[i].dump();
        }
 }
+
+
+void Paragraph::swap(Paragraph & other)
+{
+       lyxerr << "Swapping " << id() << " and " << other.id() << endl;
+       insetlist.swap(other.insetlist);
+       rows_.swap(other.rows_);
+       text_.swap(other.text_);
+       std::swap(dim_, other.dim_);
+       std::swap(layout_, other.layout_);
+       std::swap(begin_of_body_, other.begin_of_body_);
+       std::swap(itemdepth, other.itemdepth);
+       std::swap(pimpl_, other.pimpl_);
+       std::swap(pimpl_->owner_, other.pimpl_->owner_);
+       std::swap(pimpl_->inset_owner, other.pimpl_->inset_owner);
+}
+
Index: paragraph.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph.h,v
retrieving revision 1.157
diff -u -p -r1.157 paragraph.h
--- paragraph.h 7 Sep 2005 10:36:59 -0000       1.157
+++ paragraph.h 11 Dec 2005 21:04:31 -0000
@@ -397,6 +397,8 @@ public:
 
        /// dump some information to lyxerr
        void dump() const;
+       ///
+       void swap(Paragraph & other);
 
 public:
        ///
Index: ParagraphList_fwd.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/ParagraphList_fwd.h,v
retrieving revision 1.4
diff -u -p -r1.4 ParagraphList_fwd.h
--- ParagraphList_fwd.h 16 Nov 2004 20:41:37 -0000      1.4
+++ ParagraphList_fwd.h 11 Dec 2005 21:04:31 -0000
@@ -22,12 +22,21 @@ public:
        ///
        typedef std::vector<Paragraph> BaseType;
        ///
+       using BaseType::erase;
+       ///
+       using BaseType::insert;
+
+       ///
        ParagraphList();
        ///
        template <class Iter>
        ParagraphList(Iter beg, Iter end)
                : BaseType(beg, end)
        {}
+       ///
+       iterator insert(iterator pos, const Paragraph & par);
+       ///
+       iterator erase(iterator pos);
 };
 
 #endif
Index: paragraph_pimpl.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph_pimpl.h,v
retrieving revision 1.48
diff -u -p -r1.48 paragraph_pimpl.h
--- paragraph_pimpl.h   7 Sep 2005 10:37:00 -0000       1.48
+++ paragraph_pimpl.h   11 Dec 2005 21:04:33 -0000
@@ -181,6 +181,7 @@ public:
        ParagraphParameters params;
 
 private:
+       friend class Paragraph;
        ///
        lyx::pos_type size() const { return owner_->size(); }
        /// match a string against a particular point in the paragraph

Reply via email to