]> git.lyx.org Git - features.git/commitdiff
2001-12-28 Lars Gullik Bj�nnes <larsbj@birdstep.com>
authorLars Gullik Bjønnes <larsbj@gullik.org>
Fri, 28 Dec 2001 21:17:18 +0000 (21:17 +0000)
committerLars Gullik Bjønnes <larsbj@gullik.org>
Fri, 28 Dec 2001 21:17:18 +0000 (21:17 +0000)
text2.C (setCursor): add a couple of asserts.

paragraph.h (inset_iterator): add -> operator

paragraph.[Ch] (autoDeleteInsets): remove member function

BufferView2.C (removeAutoInsets): rewrite to handle the old
pos correctly and handle inset deletion by itself.
sertErrors): move iterator declaration out of for expression

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3271 a592a061-630c-0410-9148-cb99ea01b6c8

src/BufferView2.C
src/ChangeLog
src/paragraph.C
src/paragraph.h
src/text.C
src/text2.C

index 2dde52ce02830d1566ff12c8f94cdf0783811f5c..af1326aa034e21b578feebe2ef833a29d5deb40d 100644 (file)
 #include "support/FileInfo.h"
 #include "support/filetools.h"
 #include "support/lyxfunctional.h" //equal_1st_in_pair
+#include "support/types.h"
 
 #include <fstream>
 #include <algorithm>
 
 extern BufferList bufferlist;
 
+using lyx::pos_type;
+
 using std::pair;
 using std::endl;
 using std::ifstream;
@@ -106,34 +109,42 @@ bool BufferView::insertLyXFile(string const & filen)
 bool BufferView::removeAutoInsets()
 {
        LyXCursor tmpcursor = text->cursor;
-       LyXCursor cursor;
+       Paragraph * cur_par = tmpcursor.par();
+       pos_type cur_pos = tmpcursor.pos();
+       
        bool found = false;
 
+       ParIterator it = buffer()->par_iterator_begin();
        ParIterator end = buffer()->par_iterator_end();
-       for (ParIterator it = buffer()->par_iterator_begin();
-            it != end; ++it) {
+       for (; it != end; ++it) {
                Paragraph * par = *it;
-               // this has to be done before the delete
-               if (par->autoDeleteInsets()) {
-                       found = true;
-#ifdef WITH_WARNINGS
-#warning FIXME
-#endif
-                       // The test it.size()==1 was needed to prevent crashes.
-                       if (it.size() == 1) {
-                               text->setCursor(this, cursor, par, 0);
-                               text->redoParagraphs(this, cursor,
-                                                    cursor.par()->next());
-                               text->fullRebreak(this);
+               bool removed = false;
+
+               text->setCursor(this, par, 0);
+               
+               Paragraph::inset_iterator pit = par->inset_iterator_begin();
+               Paragraph::inset_iterator pend = par->inset_iterator_end();
+               while (pit != pend) {
+                       if (pit->autoDelete()) {
+                               removed = true;
+                               pos_type const pos = pit.getPos();
+                               
+                               par->erase(pos);
+                               if (cur_par == par) {
+                                       if (cur_pos > pos)
+                                               --cur_pos;
+                               }
+                       } else {
+                               ++pit;
                        }
                }
+               if (removed) {
+                       found = true;
+                       text->redoParagraph(this);
+               }
        }
 
-       // avoid forbidden cursor positions caused by error removing
-       if (tmpcursor.pos() > tmpcursor.par()->size())
-               tmpcursor.pos(tmpcursor.par()->size());
-
-       text->setCursorIntern(this, tmpcursor.par(), tmpcursor.pos());
+       text->setCursorIntern(this, cur_par, cur_pos);
 
        return found;
 }
@@ -144,9 +155,9 @@ void BufferView::insertErrors(TeXErrors & terr)
        // Save the cursor position
        LyXCursor cursor = text->cursor;
 
-       for (TeXErrors::Errors::const_iterator cit = terr.begin();
-            cit != terr.end();
-            ++cit) {
+       TeXErrors::Errors::const_iterator cit = terr.begin();
+       TeXErrors::Errors::const_iterator end = terr.end();
+       for (; cit != end; ++cit) {
                string const desctext(cit->error_desc);
                string const errortext(cit->error_text);
                string const msgtxt = desctext + '\n' + errortext;
index e89b6d1aaad9d29f83e90a533b743fe0a5d9297c..c61e2ac310052942e77f5e64c136bc643801294e 100644 (file)
@@ -1,5 +1,17 @@
 2001-12-28  Lars Gullik Bjønnes  <larsbj@birdstep.com>
 
+       * text2.C (setCursor): add a couple of asserts.
+
+       * paragraph.h (inset_iterator): add -> operator 
+
+       * paragraph.[Ch] (autoDeleteInsets): remove member function 
+
+       * BufferView2.C (removeAutoInsets): rewrite to handle the old
+       cursor pos correctly and handle inset deletion by itself.
+       (insertErrors): move iterator declaration out of for expression
+
+       * lyxtextclass.C: add <algorithm>
+
        * Makefile.am: added the new files to sources, removed layout.C
        
        * layout.C: removed file
index 3b7fa3bf3382d83fe1248bdfdb210174f1a63e28..f3d909649e8f03c35b834bf8cb517e8d661d5545 100644 (file)
@@ -1191,22 +1191,6 @@ Paragraph const * Paragraph::outerHook() const
        return depthHook(depth_type(getDepth() - 1));
 }
 
-int Paragraph::autoDeleteInsets()
-{
-       int count = 0;
-       InsetList::size_type index = 0;
-       while (index < insetlist.size()) {
-               if (insetlist[index].inset && insetlist[index].inset->autoDelete()) {
-                       erase(insetlist[index].pos); 
-                       // erase() calls to insetlist.erase(&insetlist[index])
-                       // so index shouldn't be increased.
-                       ++count;
-               } else
-                       ++index;
-       }
-       return count;
-}
-
 
 Paragraph::inset_iterator
 Paragraph::InsetIterator(pos_type pos)
index 953b3f96ea124b83be6da3773283057bbe525855..2aad07ade892d36e46669128a425fcbf48e8879b 100644 (file)
@@ -311,9 +311,6 @@ public:
        */ 
        void pasteParagraph(BufferParams const &);
 
-       /// used to remove the error messages
-       int autoDeleteInsets();
-
        /// returns -1 if inset not found
        int getPositionOfInset(Inset const * inset) const;
 
@@ -370,6 +367,9 @@ public:
                }
                ///
                Inset * operator*() { return it->inset; }
+               ///
+               Inset * operator->() { return it->inset; }
+               
                ///
                lyx::pos_type getPos() const { return it->pos; }
                ///
index 92c46e3b629a421ee48247b5c7123ef730c802a6..8a1027265571d66ac9bbe8bffdcaf528dbbc060d 100644 (file)
@@ -245,10 +245,11 @@ int LyXText::singleWidth(BufferView * bview, Paragraph * par,
 // Returns the paragraph position of the last character in the specified row
 pos_type LyXText::rowLast(Row const * row) const
 {
-       if (!row->next() || row->next()->par() != row->par())
+       if (!row->next() || row->next()->par() != row->par()) {
                return row->par()->size() - 1;
-       else 
+       } else {
                return row->next()->pos() - 1;
+       }
 }
 
 
@@ -1134,16 +1135,19 @@ int LyXText::numberOfHfills(Buffer const * buf, Row const * row) const
 {
        pos_type const last = rowLast(row);
        pos_type first = row->pos();
+       
        if (first) { /* hfill *DO* count at the beginning 
                      * of paragraphs! */
-               while (first <= last && row->par()->isHfill(first))
+               while (first <= last && row->par()->isHfill(first)) {
                        ++first;
+               }
        }
 
        first = max(first, beginningOfMainBody(buf, row->par()));
        int n = 0;
        for (pos_type p = first; p <= last; ++p) {
                // last, because the end is ignored!
+               
                if (row->par()->isHfill(p)) {
                        ++n;
                }
index 50a93c69ac07420d39aa627ad7335b4d9bcc9642..e86a6e6cf43f3685dc5580515d9f3a3f304df29d 100644 (file)
@@ -2100,9 +2100,12 @@ void LyXText::setCursor(BufferView * bview, Paragraph * par,
 }
 
 
-void LyXText::setCursor(BufferView *bview, LyXCursor & cur, Paragraph * par,
+void LyXText::setCursor(BufferView * bview, LyXCursor & cur, Paragraph * par,
                        pos_type pos, bool boundary) const
 {
+       lyx::Assert(par);
+       lyx::Assert(bview);
+       
        cur.par(par);
        cur.pos(pos);
        cur.boundary(boundary);
@@ -2125,11 +2128,15 @@ void LyXText::setCursor(BufferView *bview, LyXCursor & cur, Paragraph * par,
        pos_type cursor_vpos = 0;
        pos_type last = rowLastPrintable(row);
 
-       if (pos > last + 1)   // This shouldn't happen.
+       if (pos > last + 1) {
+               // This shouldn't happen.
                pos = last + 1;
-       else if (pos < row->pos())
+               cur.pos(pos);
+       } else if (pos < row->pos()) {
                pos = row->pos();
-
+               cur.pos(pos);
+       }
+       
        if (last < row->pos())
                 cursor_vpos = row->pos();
        else if (pos > last && !boundary)