]> git.lyx.org Git - features.git/commitdiff
Fix deleting of paragraphs after undo (fix #236).
authorJürgen Vigna <jug@sad.it>
Thu, 14 Mar 2002 13:40:19 +0000 (13:40 +0000)
committerJürgen Vigna <jug@sad.it>
Thu, 14 Mar 2002 13:40:19 +0000 (13:40 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3752 a592a061-630c-0410-9148-cb99ea01b6c8

src/ChangeLog
src/text.C
src/text2.C
src/undo_funcs.C

index 44f789e14bd52df1dfa46d6e2205bf2838393d11..c48018e2b8304ff78af565630bbd279528696a0c 100644 (file)
@@ -1,3 +1,14 @@
+2002-03-14  Juergen Vigna  <jug@sad.it>
+
+       * text2.C (setCursor): just some testcode for #44 not ready yet.
+
+       * undo_funcs.C (textHandleUndo): set the next() and previous()
+       pointers of the paragraph to 0 before deleting otherwise we have
+       problems with the Paragraph::[destructor].
+
+       * text.C (breakParagraph): IMO we should ALWAYS force a real undo
+       on a paragraph insertion.
+
 2002-03-14  Lars Gullik Bjønnes  <larsbj@birdstep.com>
 
        * buffer.C (asciiParagraph): use += operator for char append to
index fd5eb806ce3e922ed8bc90f475f7bbac05ce7c01..f96bd6408944550d04dc6a6f847e7cc5eb916754 100644 (file)
@@ -1690,7 +1690,7 @@ void LyXText::breakParagraph(BufferView * bview, char keep_layout)
        && layout.labeltype!= LABEL_SENSITIVE)
           return;
    
-   setUndo(bview, Undo::INSERT,cursor.par(),cursor.par()->next()); 
+   setUndo(bview, Undo::FINISH, cursor.par(), cursor.par()->next()); 
 
    // Always break behind a space
    //
@@ -1781,8 +1781,7 @@ void LyXText::redoParagraph(BufferView * bview) const
  * same Paragraph one to the right and make a rebreak */
 void LyXText::insertChar(BufferView * bview, char c)
 {
-       setUndo(bview, Undo::INSERT,
-               cursor.par(), cursor.par()->next());
+       setUndo(bview, Undo::INSERT, cursor.par(), cursor.par()->next());
 
        // When the free-spacing option is set for the current layout,
        // disable the double-space checking
@@ -2545,8 +2544,7 @@ void LyXText::changeRegionCase(BufferView * bview,
 {
        lyx::Assert(from <= to);
        
-       setUndo(bview, Undo::FINISH,
-               from.par(), to.par()->next());
+       setUndo(bview, Undo::FINISH, from.par(), to.par()->next());
 
        pos_type pos = from.pos();
        Paragraph * par = from.par();
@@ -2588,8 +2586,7 @@ void LyXText::transposeChars(BufferView & bview)
 {
        Paragraph * tmppar = cursor.par();
 
-       setUndo(&bview, Undo::FINISH,
-               tmppar, tmppar->next()); 
+       setUndo(&bview, Undo::FINISH, tmppar, tmppar->next()); 
 
        pos_type tmppos = cursor.pos();
 
@@ -2646,7 +2643,7 @@ void LyXText::Delete(BufferView * bview)
                // to make sure undo gets the right cursor position
                cursor = old_cursor;
                setUndo(bview, Undo::DELETE,
-                       cursor.par(), cursor.par()->next()); 
+                       cursor.par(), cursor.par()->next());
                cursor = tmpcursor;
                backspace(bview);
        }
index de33573ee34bc77d1fb1e70d766256c075f38326..ce3c27d570d3bc099775f48c1a1c24ecf527413b 100644 (file)
@@ -2048,15 +2048,26 @@ bool LyXText::setCursor(BufferView * bview, Paragraph * par,
 
 
 void LyXText::setCursor(BufferView * bview, LyXCursor & cur, Paragraph * par,
-                       pos_type pos, bool boundary) const
+                        pos_type pos, bool boundary) const
 {
        lyx::Assert(par);
        lyx::Assert(bview);
-       
+
        cur.par(par);
        cur.pos(pos);
        cur.boundary(boundary);
 
+#if 0
+       if (pos && par->getChar(pos) == Paragraph::META_INSET &&
+               par->getInset(pos)) {
+               Inset * ins = par->getInset(pos);
+               if (ins->needFullRow() || ins->display()) {
+                       --pos;
+                       boundary = true;
+               }
+       }
+#endif
+
        // get the cursor y position in text
        int y = 0;
        Row * row = getRow(par, pos, y);
@@ -2085,12 +2096,12 @@ void LyXText::setCursor(BufferView * bview, LyXCursor & cur, Paragraph * par,
        }
        
        if (last < row->pos())
-                cursor_vpos = row->pos();
+               cursor_vpos = row->pos();
        else if (pos > last && !boundary)
                cursor_vpos = (row->par()->isRightToLeftPar(bview->buffer()->params))
                        ? row->pos() : last + 1; 
        else if (pos > row->pos() &&
-                (pos > last || boundary))
+                (pos > last || boundary))
                /// Place cursor after char at (logical) position pos - 1
                cursor_vpos = (bidi_level(pos - 1) % 2 == 0)
                        ? log2vis(pos - 1) + 1 : log2vis(pos - 1);
@@ -2106,8 +2117,7 @@ void LyXText::setCursor(BufferView * bview, LyXCursor & cur, Paragraph * par,
             !row->par()->isLineSeparator(main_body-1)))
                main_body = 0;
        
-       for (pos_type vpos = row->pos();
-            vpos < cursor_vpos; ++vpos) {
+       for (pos_type vpos = row->pos(); vpos < cursor_vpos; ++vpos) {
                pos = vis2log(vpos);
                if (main_body > 0 && pos == main_body - 1) {
                        x += fill_label_hfill +
index b60ee0c7fc13ceb4cc0ab2ca73d77e3cc9fc41a9..8862b76d2590e09718f6c366326655438e82f1bc 100644 (file)
@@ -23,7 +23,7 @@
 
 #include "iterators.h"
 
-//#define DELETE_UNUSED_PARAGRAPHS 1
+#define DELETE_UNUSED_PARAGRAPHS 1
 #ifdef DELETE_UNUSED_PARAGRAPHS
 #include <vector>
 #endif
@@ -275,17 +275,27 @@ bool textHandleUndo(BufferView * bv, Undo * undo)
                // And here it's save enough to delete all removed paragraphs
                vector<Paragraph *>::iterator pit = vvpar.begin();
                if (pit != vvpar.end()) {
+#if 0
+                       lyxerr << endl << "PARS BEFORE:";
+                       ParIterator end = bv->buffer()->par_iterator_end();
+                       ParIterator it = bv->buffer()->par_iterator_begin();
+                       for (; it != end; ++it)
+                               lyxerr << (*it)->previous() << "<- " << (*it) << " ->" << (*it)->next() << endl;
                        lyxerr << "DEL: ";
+#endif
                        for(;pit != vvpar.end(); ++pit) {
-                               lyxerr << *pit << " ";
+//                             lyxerr << *pit << " ";
+                               (*pit)->previous(0);
+                               (*pit)->next(0);
                                delete (*pit);
                        }
-                       lyxerr << endl << "PARS:";
-                       ParIterator end = bv->buffer()->par_iterator_end();
-                       ParIterator it = bv->buffer()->par_iterator_begin();
+#if 0
+                       lyxerr << endl << "PARS AFTER:";
+                       end = bv->buffer()->par_iterator_end();
+                       it = bv->buffer()->par_iterator_begin();
                        for (; it != end; ++it)
-                               lyxerr << *it << " ";
-                       lyxerr << endl;
+                               lyxerr << (*it)->previous() << "<- " << (*it) << " ->" << (*it)->next() << endl;
+#endif
                }
 #endif
        }