]> git.lyx.org Git - lyx.git/blobdiff - src/text2.C
Fix bugs #32 and #52.
[lyx.git] / src / text2.C
index 4ddfcffa2c8338d78cc66421514e8675b604b019..2437cf1570a22fa39762af7389e922135b6ff5d3 100644 (file)
@@ -17,7 +17,7 @@
 #include "lyxtext.h"
 #include "LString.h"
 #include "paragraph.h"
-#include "layout.h"
+#include "lyxtextclasslist.h"
 #include "LyXView.h"
 #include "undo_funcs.h"
 #include "buffer.h"
@@ -862,8 +862,9 @@ void LyXText::redoParagraphs(BufferView * bview, LyXCursor const & cur,
 
        if (!tmprow->previous()) {
                // a trick/hack for UNDO
-               // Can somebody please tell me _why_ this solves
-               // anything. (Lgb)
+               // This is needed because in an UNDO/REDO we could have changed
+               // the firstParagrah() so the paragraph inside the row is NOT
+               // my really first par anymore. Got it Lars ;) (Jug 20011206)
                first_phys_par = firstParagraph();
        } else {
                first_phys_par = tmprow->par();
@@ -886,7 +887,7 @@ void LyXText::redoParagraphs(BufferView * bview, LyXCursor const & cur,
                tmppar = tmprow->next()->par();
        else
                tmppar = 0;
-       while (tmppar != endpar) {
+       while (tmprow->next() && tmppar != endpar) {
                removeRow(tmprow->next());
                if (tmprow->next()) {
                        tmppar = tmprow->next()->par();
@@ -1012,7 +1013,7 @@ void LyXText::setSelection(BufferView * bview)
 
 
 string const LyXText::selectionAsString(Buffer const * buffer,
-                                       bool label) const
+                                        bool label) const
 {
        if (!selection.set()) return string();
        string result;
@@ -1683,8 +1684,8 @@ void LyXText::insertInset(BufferView * bview, Inset * inset)
 {
        if (!cursor.par()->insetAllowed(inset->lyxCode()))
                return;
-       setUndo(bview, Undo::INSERT,
-               cursor.par(), cursor.par()->next());
+       // I don't know if this is necessary here (Jug 20020102)
+       setUndo(bview, Undo::INSERT, cursor.par(), cursor.par()->next());
        cursor.par()->insertInset(cursor.pos(), inset);
        // Just to rebreak and refresh correctly.
        // The character will not be inserted a second time
@@ -2099,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);
@@ -2120,15 +2124,19 @@ void LyXText::setCursor(BufferView *bview, LyXCursor & cur, Paragraph * par,
        float fill_hfill;
        float fill_label_hfill;
        prepareToPrint(bview, row, x, fill_separator, fill_hfill,
-                      fill_label_hfill);
+                      fill_label_hfill);
        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)
@@ -2185,8 +2193,7 @@ void LyXText::setCursor(BufferView *bview, LyXCursor & cur, Paragraph * par,
 
 
 void LyXText::setCursorIntern(BufferView * bview, Paragraph * par,
-                             pos_type pos,
-                             bool setfont, bool boundary) const
+                              pos_type pos, bool setfont, bool boundary) const
 {
        InsetText * it = static_cast<InsetText *>(par->inInset());
        if (it) {
@@ -2205,8 +2212,7 @@ void LyXText::setCursorIntern(BufferView * bview, Paragraph * par,
                        // I moved the lyxerr stuff in here so we can see if
                        // this is actually really needed and where!
                        // (Jug)
-                       it->getLyXText(bview)->setCursorIntern(bview, par, pos, setfont,
-                                                              boundary);
+                       // it->getLyXText(bview)->setCursorIntern(bview, par, pos, setfont, boundary);
                        return;
                }
        }
@@ -2596,11 +2602,7 @@ void LyXText::ownerParagraph(int id, Paragraph * p) const
        if (op && op->inInset()) {
                static_cast<InsetText *>(op->inInset())->paragraph(p);
        } else {
-               if (inset_owner) {
-                       inset_owner->paragraph(p);
-               } else {
-                       bv_owner->buffer()->paragraph = p;
-               }
+               ownerParagraph(p);
        }
 }