]> git.lyx.org Git - lyx.git/blobdiff - src/text.C
Fix deleting of paragraphs after undo (fix #236).
[lyx.git] / src / text.C
index 44c7a81e4f55a46c35fcb125228ee9da970a731a..f96bd6408944550d04dc6a6f847e7cc5eb916754 100644 (file)
@@ -834,8 +834,10 @@ int LyXText::leftMargin(BufferView * bview, Row const * row) const
                         && ! row->par()->isFirstInSequence()))
                    && align == LYX_ALIGN_BLOCK
                    && !row->par()->params().noindent()
-                       // in tabulars paragraphs are never indented!
-                       && (!row->par()->inInset() || row->par()->inInset()->owner()->lyxCode() != Inset::TABULAR_CODE)
+                       // in tabulars and ert paragraphs are never indented!
+                       && (!row->par()->inInset() || !row->par()->inInset()->owner() ||
+                               (row->par()->inInset()->owner()->lyxCode() != Inset::TABULAR_CODE &&
+                                row->par()->inInset()->owner()->lyxCode() != Inset::ERT_CODE))
                    && (row->par()->layout() != tclass.defaultLayoutName() ||
                        bview->buffer()->params.paragraph_separation ==
                        BufferParams::PARSEP_INDENT)) {
@@ -1679,15 +1681,16 @@ void LyXText::breakAgainOneRow(BufferView * bview, Row * row)
 
 void LyXText::breakParagraph(BufferView * bview, char keep_layout)
 {
-   LyXLayout const & layout =
-          textclasslist[bview->buffer()->params.textclass][cursor.par()->layout()];
+       LyXTextClass const & tclass =
+               textclasslist[bview->buffer()->params.textclass];
+   LyXLayout const & layout = tclass[cursor.par()->layout()];
 
    // this is only allowed, if the current paragraph is not empty or caption
    if ((cursor.par()->size() <= 0)
        && 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
    //
@@ -1709,10 +1712,10 @@ void LyXText::breakParagraph(BufferView * bview, char keep_layout)
    if (layout.labeltype == LABEL_SENSITIVE) {
      if (!cursor.pos())
             // set to standard-layout
-            cursor.par()->applyLayout(0);
+            cursor.par()->applyLayout(tclass.defaultLayoutName());
      else
             // set to standard-layout
-            cursor.par()->next()->applyLayout(0);
+            cursor.par()->next()->applyLayout(tclass.defaultLayoutName());
    }
    
    /* if the cursor is at the beginning of a row without prior newline, 
@@ -1778,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
@@ -1788,7 +1790,6 @@ void LyXText::insertChar(BufferView * bview, char c)
                textclasslist[bview->buffer()->params.textclass][cursor.row()->par()->layout()].free_spacing ||
                cursor.row()->par()->isFreeSpacing();
 
-
        if (lyxrc.auto_number) {
                static string const number_operators = "+-/*";
                static string const number_unary_operators = "+-";
@@ -1910,7 +1911,7 @@ void LyXText::insertChar(BufferView * bview, char c)
        Row * row = cursor.row();
        int y = cursor.y() - row->baseline();
        if (c != Paragraph::META_INSET) /* Here case LyXText::InsertInset 
-                                           * already insertet the character */
+                                        * already insertet the character */
                cursor.par()->insertChar(cursor.pos(), c);
        setCharFont(bview->buffer(), cursor.par(), cursor.pos(), rawtmpfont);
 
@@ -1929,7 +1930,8 @@ void LyXText::insertChar(BufferView * bview, char c)
                 || ((cursor.pos() < cursor.par()->size()) &&
                         cursor.par()->isInset(cursor.pos()+1))
             || cursor.row()->fill() == -1)
-           && row->previous() && row->previous()->par() == row->par()) {
+           && row->previous() && row->previous()->par() == row->par())
+       {
                pos_type z = nextBreakPoint(bview,
                                                           row->previous(),
                                                           workWidth(bview));
@@ -1973,8 +1975,8 @@ void LyXText::insertChar(BufferView * bview, char c)
    
        // recalculate the fill of the row
        if (row->fill() >= 0)  /* needed because a newline
-                             * will set fill to -1. Otherwise
-                             * we would not get a rebreak! */
+                               * will set fill to -1. Otherwise
+                               * we would not get a rebreak! */
                row->fill(fill(bview, row, workWidth(bview)));
        if (row->fill() < 0) {
                refresh_y = y;
@@ -2115,6 +2117,13 @@ void LyXText::prepareToPrint(BufferView * bview,
                    && (inset->display())) // || (inset->scroll() < 0)))
                    align = (inset->lyxCode() == Inset::MATHMACRO_CODE)
                        ? LYX_ALIGN_BLOCK : LYX_ALIGN_CENTER;
+               // ERT insets should always be LEFT ALIGNED on screen
+               inset = row->par()->inInset();
+               if (inset && inset->owner() &&
+                       inset->owner()->lyxCode() == Inset::ERT_CODE)
+               {
+                       align = LYX_ALIGN_LEFT;
+               }
                
                switch (align) {
            case LYX_ALIGN_BLOCK:
@@ -2535,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();
@@ -2578,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();
 
@@ -2636,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);
        }
@@ -3838,7 +3845,7 @@ Row * LyXText::getRowNearY(int & y) const
        
        y = tmpy;   // return the real y
 
-       lyxerr << "returned y = " << y << endl;
+       //lyxerr << "returned y = " << y << endl;
        
        return tmprow;
 #else