]> git.lyx.org Git - features.git/commitdiff
a PosIterator-based ParIterator ctor and 1 user
authorAlfredo Braunstein <abraunst@lyx.org>
Thu, 6 Nov 2003 09:51:08 +0000 (09:51 +0000)
committerAlfredo Braunstein <abraunst@lyx.org>
Thu, 6 Nov 2003 09:51:08 +0000 (09:51 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8051 a592a061-630c-0410-9148-cb99ea01b6c8

src/ChangeLog
src/PosIterator.h
src/bufferview_funcs.C
src/iterators.C
src/iterators.h

index 116e76b48dd5024d628493b073b2559e1109593c..89714a822efac48ae364e6751ac810e409a34bfe 100644 (file)
@@ -1,3 +1,8 @@
+2003-11-06  Alfredo Braunstein  <abraunst@libero.it>
+
+       * iterators.[Ch] (ParIterator): new PosIterator-based ctor
+       * bufferview_funcs.C (put_selection_at): use the above
+
 2003-11-05  Alfredo Braunstein  <abraunst@libero.it>
 
        * text2.C (deleteEmptyParagraphMechanism): fix n-th crash
index e42ddb4681547f737ec000f0d8e7fb5cdff65826..6b32ed10c6123e3d8f96c761b2ea74968b937f32 100644 (file)
@@ -52,6 +52,7 @@ public:
        lyx::pos_type pos() const { return stack_.top().pos; }
        bool at_end() const;
        friend PosIterator ParIterator::asPosIterator(lyx::pos_type) const;
+       friend ParIterator::ParIterator(PosIterator const &);
        
 private:
        PosIterator() {};
index a2f1b8f328d93433342a0a822c915c91b0f664f7..3a0b79de35350feb5990270c2967d45d1fd816bb 100644 (file)
@@ -428,9 +428,7 @@ void replaceSelection(LyXText * text)
 void put_selection_at(BufferView * bv, PosIterator const & cur,
                      int length, bool backwards)
 {
-       ParIterator par = bv->buffer()->par_iterator_begin();
-       for (; par.pit() != cur.pit(); ++par)
-               ;
+       ParIterator par(cur);
        
        bv->getLyXText()->clearSelection();
 
index 2eccf985a58aedb0bd2146c89d38d202839c1847..49ce762af495c6c38a59bd0639c6f4b08d7334b8 100644 (file)
@@ -363,6 +363,31 @@ PosIterator ParIterator::asPosIterator(lyx::pos_type pos) const
 }
 
 
+ParIterator::ParIterator(PosIterator const & pos)
+       : pimpl_(new Pimpl)
+{
+       PosIterator copy = pos;
+       int const size = copy.stack_.size();
+       
+       for (int i = 0; i < size; ++i) {
+               PosIteratorItem & it = copy.stack_.top();
+               ParPosition pp(it.pit, *it.pl);
+               if (i > 0) {
+                       InsetOld * inset = it.pit->getInset(it.pos);
+                       BOOST_ASSERT(inset);
+                       InsetList::iterator beg = it.pit->insetlist.begin();
+                       InsetList::iterator end = it.pit->insetlist.end();
+                       for (; beg != end && beg->inset != inset; ++beg);
+                       BOOST_ASSERT(beg != end);
+                       pp.it.reset(beg);
+                       pp.index.reset(it.index - 1);
+               }
+               pimpl_->positions.insert(pimpl_->positions.begin(), pp);
+               copy.stack_.pop();
+       }
+}
+
+
 void ParIterator::lockPath(BufferView * bv) const
 {
        bv->insetUnlock();
index 1f23dbf494a88bd87406a2983ec8a75269e9a88f..bb3288ce8a711d9ec28ba87ed182ccd4882d9453 100644 (file)
@@ -33,6 +33,8 @@ public:
        ///
        ParIterator(ParIterator const &);
        ///
+       ParIterator(PosIterator const &);
+       ///
        void operator=(ParIterator const &);
        ///
        ParIterator & operator++();
@@ -46,8 +48,7 @@ public:
        ParagraphList::iterator pit() const;
        ///
        ParagraphList & plist() const;
-       /// returns 'innermost' LyXText if in an inset or '0' instead of
-       //bv->text
+       /// returns 'innermost' LyXText
        LyXText * text(BufferView *) const;
        /// returns innermost inset
        InsetOld * inset() const;