]> git.lyx.org Git - lyx.git/blobdiff - src/text2.C
John's Layout Tabular UI improvements and Martins fixes to clearing the
[lyx.git] / src / text2.C
index 1440f91c561c231dfe5469c97ac90dd470d44efa..19ad0bdc1d4517f45c1b2bef7c94a0bc73ffeeb1 100644 (file)
 #include "lyxtext.h"
 #include "LString.h"
 #include "paragraph.h"
-#include "insets/inseterror.h"
-#include "insets/insetbib.h"
-#include "insets/insetspecialchar.h"
-#include "insets/insettext.h"
-#include "insets/insetfloat.h"
-#include "layout.h"
+#include "lyxtextclasslist.h"
 #include "LyXView.h"
-#include "support/textutils.h"
-#include "support/lstrings.h"
 #include "undo_funcs.h"
 #include "buffer.h"
 #include "bufferparams.h"
 #include "FloatList.h"
 #include "language.h"
 #include "ParagraphParameters.h"
+
+#include "insets/inseterror.h"
+#include "insets/insetbib.h"
+#include "insets/insetspecialchar.h"
+#include "insets/insettext.h"
+#include "insets/insetfloat.h"
+
 #include "support/LAssert.h"
+#include "support/textutils.h"
+#include "support/lstrings.h"
 
 using std::copy;
 using std::find;
@@ -391,7 +393,7 @@ void LyXText::removeRow(Row * row) const
                row->next()->previous(row->previous());
        if (!row->previous()) {
                firstrow = row->next();
-               lyx::Assert(firstrow);
+//             lyx::Assert(firstrow);
        } else  {
                row->previous()->next(row->next());
        }
@@ -788,11 +790,11 @@ void LyXText::setFont(BufferView * bview, LyXFont const & font, bool toggleall)
        redoParagraphs(bview, selection.start, selection.end.par()->next());
    
        // we have to reset the selection, because the
-       // geometry could have changed
+       // geometry could have changed, but we keep
+       // it for user convenience
        setCursor(bview, selection.start.par(), selection.start.pos());
        selection.cursor = cursor;
        setCursor(bview, selection.end.par(), selection.end.pos());
-       clearSelection();
        setSelection(bview);
        setCursor(bview, tmpcursor.par(), tmpcursor.pos(), true,
                  tmpcursor.boundary());
@@ -860,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();
@@ -872,7 +875,7 @@ void LyXText::redoParagraphs(BufferView * bview, LyXCursor const & cur,
                        y -= tmprow->height();
                }
        }
-       
+
        // we can set the refreshing parameters now
        status(bview, LyXText::NEED_MORE_REFRESH);
        refresh_y = y;
@@ -884,13 +887,14 @@ 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())
+               if (tmprow->next()) {
                        tmppar = tmprow->next()->par();
-               else
+               } else {
                        tmppar = 0;
-       }  
+               }
+       }
    
        // remove the first one
        tmprow2 = tmprow;     /* this is because tmprow->previous()
@@ -1009,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;
@@ -1054,7 +1058,7 @@ void LyXText::clearSelection() const
 {
        selection.set(false);
        selection.mark(false);
-       selection.end = selection.start = selection.cursor = cursor;
+       last_sel_cursor = selection.end = selection.start = selection.cursor = cursor;
 }
 
 
@@ -1680,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
@@ -2096,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);
@@ -2121,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)
@@ -2182,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) {
@@ -2202,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;
                }
        }
@@ -2367,17 +2376,16 @@ void LyXText::fixCursorAfterDelete(BufferView * bview,
 void LyXText::deleteEmptyParagraphMechanism(BufferView * bview,
                                            LyXCursor const & old_cursor) const
 {
-       // don't delete anything if this is the ONLY paragraph!
-       if (!old_cursor.par()->next() && !old_cursor.par()->previous())
-               return;
-       
        // Would be wrong to delete anything if we have a selection.
        if (selection.set()) return;
 
        // We allow all kinds of "mumbo-jumbo" when freespacing.
        if (textclasslist.Style(bview->buffer()->params.textclass,
-                               old_cursor.par()->getLayout()).free_spacing)
+                               old_cursor.par()->getLayout()).free_spacing
+           || old_cursor.par()->isFreeSpacing())
+       {
                return;
+       }
 
        bool deleted = false;
        
@@ -2405,7 +2413,8 @@ void LyXText::deleteEmptyParagraphMechanism(BufferView * bview,
        // MISSING
 
        // If the pos around the old_cursor were spaces, delete one of them.
-       if (old_cursor.par() != cursor.par() || old_cursor.pos() != cursor.pos()) { 
+       if (old_cursor.par() != cursor.par()
+           || old_cursor.pos() != cursor.pos()) { 
                // Only if the cursor has really moved
                
                if (old_cursor.pos() > 0
@@ -2437,6 +2446,10 @@ void LyXText::deleteEmptyParagraphMechanism(BufferView * bview,
                }
        }
 
+       // don't delete anything if this is the ONLY paragraph!
+       if (!old_cursor.par()->next() && !old_cursor.par()->previous())
+               return;
+       
        // Do not delete empty paragraphs with keepempty set.
        if ((textclasslist.Style(bview->buffer()->params.textclass,
                                 old_cursor.par()->getLayout())).keepempty)
@@ -2470,7 +2483,7 @@ void LyXText::deleteEmptyParagraphMechanism(BufferView * bview,
                        setUndo(bview, Undo::DELETE, old_cursor.par(), endpar);
                        cursor = tmpcursor;
 
-                               // delete old row
+                       // delete old row
                        removeRow(old_cursor.row());
                        if (ownerParagraph() == old_cursor.par()) {
                                ownerParagraph(ownerParagraph()->next());
@@ -2589,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);
        }
 }