]> git.lyx.org Git - lyx.git/blobdiff - src/text.C
Forgot to save changed file ;)
[lyx.git] / src / text.C
index 6898b18145d487bf9a5ae7c438508a9fc0fdc451..217398f890a7b39ae556b028f6b2fefa8544aeec 100644 (file)
@@ -254,10 +254,21 @@ pos_type LyXText::rowLast(Row const * row) const
 pos_type LyXText::rowLastPrintable(Row const * row) const
 {
        pos_type const last = rowLast(row);
+       bool ignore_the_space_on_the_last_position = true;
+       Inset * ins;
+       // we have to consider a space on the last position in this case!
+       if (row->next() && row->par() == row->next()->par() &&
+           row->next()->par()->getChar(last+1) == Paragraph::META_INSET &&
+           (ins=row->next()->par()->getInset(last+1)) &&
+           (ins->needFullRow() || ins->display()))
+       {
+               ignore_the_space_on_the_last_position = false;
+       }
        if (last >= row->pos()
            && row->next()
            && row->next()->par() == row->par()
-           && row->par()->isSeparator(last))
+           && row->par()->isSeparator(last)
+               && ignore_the_space_on_the_last_position)
                return last - 1;
        else
                return last;
@@ -679,6 +690,12 @@ void LyXText::draw(DrawRowParams & p, pos_type & vpos)
 // exactly the label-width.
 int LyXText::leftMargin(BufferView * bview, Row const * row) const
 {
+       Inset * ins;
+       if ((row->par()->getChar(row->pos()) == Paragraph::META_INSET) &&
+               (ins=row->par()->getInset(row->pos())) &&
+               (ins->needFullRow() || ins->display()))
+               return LYX_PAPER_MARGIN;
+
        LyXTextClass const & tclass =
                textclasslist[bview->buffer()->params.textclass];
        LyXLayout const & layout = tclass[row->par()->layout()];
@@ -855,6 +872,12 @@ int LyXText::leftMargin(BufferView * bview, Row const * row) const
 
 int LyXText::rightMargin(Buffer const * buf, Row const * row) const
 {
+       Inset * ins;
+       if ((row->par()->getChar(row->pos()) == Paragraph::META_INSET) &&
+               (ins=row->par()->getInset(row->pos())) &&
+               (ins->needFullRow() || ins->display()))
+               return LYX_PAPER_MARGIN;
+
        LyXTextClass const & tclass = textclasslist[buf->params.textclass];
        LyXLayout const & layout = tclass[row->par()->layout()];
 
@@ -1134,10 +1157,11 @@ int LyXText::labelFill(BufferView * bview, Row const * row) const
 // on the very last column doesnt count
 int LyXText::numberOfSeparators(Buffer const * buf, Row const * row) const
 {
-       pos_type const last = rowLast(row);
+       pos_type last = rowLastPrintable(row);
        pos_type p = max(row->pos(), beginningOfMainBody(buf, row->par()));
+               
        int n = 0;
-       for (; p < last; ++p) {
+       for (; p <= last; ++p) {
                if (row->par()->isSeparator(p)) {
                        ++n;
                }
@@ -1686,8 +1710,10 @@ void LyXText::breakParagraph(BufferView * bview, char keep_layout)
    LyXLayout const & layout = tclass[cursor.par()->layout()];
 
    // this is only allowed, if the current paragraph is not empty or caption
+   // and if it has not the keepempty flag aktive
    if ((cursor.par()->size() <= 0)
-       && layout.labeltype!= LABEL_SENSITIVE)
+       && layout.labeltype != LABEL_SENSITIVE
+          && !layout.keepempty)
           return;
 
    setUndo(bview, Undo::FINISH, cursor.par(), cursor.par()->next());
@@ -1723,7 +1749,8 @@ void LyXText::breakParagraph(BufferView * bview, char keep_layout)
     * This touches only the screen-update. Otherwise we would may have
     * an empty row on the screen */
    if (cursor.pos() && !cursor.row()->par()->isNewline(cursor.row()->pos() - 1)
-       && cursor.row()->pos() == cursor.pos()) {
+       && cursor.row()->pos() == cursor.pos())
+   {
           cursorLeft(bview);
    }
 
@@ -1756,7 +1783,7 @@ void LyXText::breakParagraph(BufferView * bview, char keep_layout)
 
    /* This check is necessary. Otherwise the new empty paragraph will
     * be deleted automatically. And it is more friendly for the user! */
-   if (cursor.pos())
+   if (cursor.pos() || layout.keepempty)
           setCursor(bview, cursor.par()->next(), 0);
    else
           setCursor(bview, cursor.par(), 0);
@@ -1883,13 +1910,14 @@ void LyXText::insertChar(BufferView * bview, char c)
                }
        } else if (IsNewlineChar(c)) {
                if (cursor.pos() <= beginningOfMainBody(bview->buffer(),
-                                                       cursor.par())) {
+                                                       cursor.par()))
+               {
                        charInserted();
                        return;
                }
                /* No newline at first position
                 * of a paragraph or behind labels.
-                * TeX does not allow that. */
+                * TeX does not allow that */
 
                if (cursor.pos() < cursor.par()->size() &&
                    cursor.par()->isLineSeparator(cursor.pos()))
@@ -1925,12 +1953,12 @@ void LyXText::insertChar(BufferView * bview, char c)
        }
 
        // Is there a break one row above
-       if ((cursor.par()->isLineSeparator(cursor.pos())
-            || cursor.par()->isNewline(cursor.pos())
-                || ((cursor.pos() < cursor.par()->size()) &&
-                        cursor.par()->isInset(cursor.pos()+1))
-            || cursor.row()->fill() == -1)
-           && row->previous() && row->previous()->par() == row->par())
+       if (row->previous() && row->previous()->par() == row->par()
+           && (cursor.par()->isLineSeparator(cursor.pos())
+               || cursor.par()->isNewline(cursor.pos())
+               || ((cursor.pos() < cursor.par()->size()) &&
+                   cursor.par()->isInset(cursor.pos()+1))
+               || cursor.row()->fill() == -1))
        {
                pos_type z = nextBreakPoint(bview,
                                                           row->previous(),
@@ -1978,7 +2006,7 @@ void LyXText::insertChar(BufferView * bview, char c)
                                * will set fill to -1. Otherwise
                                * we would not get a rebreak! */
                row->fill(fill(bview, row, workWidth(bview)));
-       if (row->fill() < 0) {
+       if (c == Paragraph::META_INSET || row->fill() < 0) {
                refresh_y = y;
                refresh_row = row;
                refresh_x = cursor.x();
@@ -2076,7 +2104,8 @@ void LyXText::prepareToPrint(BufferView * bview,
                x = (workWidth(bview) > 0)
                        ? rightMargin(bview->buffer(), row) : 0;
        } else
-               x = (workWidth(bview) > 0) ? leftMargin(bview, row) : 0;
+               x = (workWidth(bview) > 0)
+                       ? leftMargin(bview, row) : 0;
 
        // is there a manual margin with a manual label
        LyXTextClass const & tclass = textclasslist[bview->buffer()->params.textclass];
@@ -3580,7 +3609,14 @@ void LyXText::paintRowText(DrawRowParams & p)
 
        pos_type vpos = p.row->pos();
        while (vpos <= last) {
+               if (p.x > p.bv->workWidth())
+                       break;
                pos_type pos = vis2log(vpos);
+               if (p.x + singleWidth(p.bv, par, pos) < 0) {
+                       p.x += singleWidth(p.bv, par, pos);
+                       ++vpos;
+                       continue;
+               }
                if (main_body > 0 && pos == main_body - 1) {
                        int const lwidth = lyxfont::width(layout.labelsep,
                                getLabelFont(buffer, par));