]> git.lyx.org Git - features.git/commitdiff
final(?) tweaks for removeAutoInsets() and removed one redundant conditional clause...
authorAllan Rae <rae@lyx.org>
Tue, 15 Jan 2002 11:44:16 +0000 (11:44 +0000)
committerAllan Rae <rae@lyx.org>
Tue, 15 Jan 2002 11:44:16 +0000 (11:44 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3382 a592a061-630c-0410-9148-cb99ea01b6c8

src/BufferView2.C
src/ChangeLog
src/text.C

index 4e2906a3215783edabef9e8e732d9b3c489dbfb4..ad4d36297c9b9d22efcd04972b1a2a0f9ddec25a 100644 (file)
@@ -107,11 +107,10 @@ bool BufferView::insertLyXFile(string const & filen)
 
 bool BufferView::removeAutoInsets()
 {
-       LyXCursor tmpcursor = text->cursor;
-       Paragraph * cur_par = tmpcursor.par();
+       Paragraph * cur_par = text->cursor.par();
        Paragraph * cur_par_prev = cur_par ? cur_par->previous() : 0;
        Paragraph * cur_par_next = cur_par ? cur_par->next() : 0;
-       pos_type cur_pos = tmpcursor.pos();
+       pos_type cur_pos = text->cursor.pos();
 
        bool found = false;
 
@@ -153,6 +152,11 @@ bool BufferView::removeAutoInsets()
                        // The previous setCursor line was deleted and that
                        // was the cur_par line.  This can only happen if an
                        // error box was the sole item on cur_par.
+                       // It is possible for cur_par_prev to be stray if
+                       // the line it pointed to only had a error box on it
+                       // so we have to set it to a known correct value.
+                       // This is often the same value it already had.
+                       cur_par_prev = par->previous();
                        if (cur_par_prev) {
                                // '|' = par, '.' = cur_par, 'E' = error box
                                // First step below may occur before while{}
@@ -203,6 +207,20 @@ bool BufferView::removeAutoInsets()
                }
        }
 
+       // It is possible that the last line is empty if it was cur_par and/or
+       // only had an error inset on it.
+       if (text->setCursor(this, text->ownerParagraph(), 0)
+           && 0 == cur_par_next) {
+               cur_par = cur_par_prev;
+               cur_pos = cur_par->size();
+       } else if (cur_pos > cur_par->size()) {
+               // Some C-Enter lines were removed by the setCursor call which
+               // then invalidated cur_pos. It could still be "wrong" because
+               // the cursor may appear to have jumped but since we collapsed
+               // some C-Enter lines this should be a reasonable compromise.
+               cur_pos = cur_par->size();
+       }
+
        text->setCursorIntern(this, cur_par, cur_pos);
 
        return found;
index fd700b29b4cf20fbbada454c5af3a37764a92730..1a76fb8b033199ed6ba584cb6db570d0097e09d4 100644 (file)
@@ -1,3 +1,11 @@
+2002-01-15  Allan Rae  <rae@lyx.org>
+
+       * text.C (insertChar): removed conditional truism.
+
+       * BufferView2.C (removeAutoInsets): More tweaks.
+       cur_par_prev could be a stray pointer.  Check for trailing empty line
+       in case last line was cur_par and only had an error inset on it.
+
 2002-01-14  Jean-Marc Lasgouttes  <lasgouttes@freesurf.fr>
 
        * lyx_cb.C (MenuWrite): buffer->fileName is guaranteed to be
index 1c2e34e2ec89046956189b539bd69e2b56402bd7..75d1156d7177f263d5ccdf98302180acfa71f0fa 100644 (file)
@@ -1892,8 +1892,8 @@ void LyXText::insertChar(BufferView * bview, char c)
                        return;
                }
        } else if (IsNewlineChar(c)) {
-               if (cursor.par() == cursor.par()
-                   && cursor.pos() <= beginningOfMainBody(bview->buffer(), cursor.par())) {
+               if (cursor.pos() <= beginningOfMainBody(bview->buffer(),
+                                                       cursor.par())) {
                        charInserted();
                        return;
                }