]> git.lyx.org Git - features.git/commitdiff
add and LyXText::undoSpan to compute the influence of a layout change.
authorAlfredo Braunstein <abraunst@lyx.org>
Fri, 9 Jan 2004 09:04:33 +0000 (09:04 +0000)
committerAlfredo Braunstein <abraunst@lyx.org>
Fri, 9 Jan 2004 09:04:33 +0000 (09:04 +0000)
Fix Bug 578.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8331 a592a061-630c-0410-9148-cb99ea01b6c8

src/ChangeLog
src/lyxtext.h
src/text.C
src/text2.C

index fdc6b66a3a14aa47486d5dc3aa8a6e6043b7e66d..ada751cce9eb09cbc40fd636de1395fed2d403dc 100644 (file)
@@ -1,3 +1,8 @@
+2004-01-08  Alfredo Braunstein  <abraunst@lyx.org>
+
+       * text2.C (undoSpan): add and use
+       * text.C (breakParagraph): use undoSpan (fix bug 578)
+       * lyxtext.h: adjust
 
 2004-01-08  Angus Leeming  <leeming@lyx.org>
 
index fdd54a0cd4ca36ee0979fe4a8fbc542b5bc49078..949566c3e04f633500e58e9d714c3f08be4ba61c 100644 (file)
@@ -441,6 +441,10 @@ public:
 
 
 private:
+       /// return past-the-last paragraph influenced by a layout
+       /// change on pit
+       ParagraphList::iterator undoSpan(ParagraphList::iterator pit);
+       
        /// rebreaks the given par
        void redoParagraphInternal(ParagraphList::iterator pit);
        /// used in setlayout
index 398df844801a7488062fd726ebe19166f352c4cc..bf177b290e52937b49ed735668939e7133359000 100644 (file)
@@ -596,9 +596,10 @@ void LyXText::setHeightOfRow(ParagraphList::iterator pit, Row & row)
        // are taken from the layoutfont. Nicer on the screen :)
        LyXLayout_ptr const & layout = pit->layout();
 
-       // as max get the first character of this row then it can increase but not
-       // decrease the height. Just some point to start with so we don't have to
-       // do the assignment below too often.
+       // as max get the first character of this row then it can
+       // increase but not decrease the height. Just some point to
+       // start with so we don't have to do the assignment below too
+       // often.
        LyXFont font = getFont(pit, row.pos());
        LyXFont::FONT_SIZE const tmpsize = font.size();
        font = getLayoutFont(pit);
@@ -760,16 +761,16 @@ void LyXText::breakParagraph(ParagraphList & paragraphs, char keep_layout)
                bv()->buffer()->params().getLyXTextClass();
        LyXLayout_ptr const & layout = cpit->layout();
 
-       // this is only allowed, if the current paragraph is not empty or caption
-       // and if it has not the keepempty flag active
+       // this is only allowed, if the current paragraph is not empty
+       // or caption and if it has not the keepempty flag active
        if (cpit->empty() && !cpit->allowEmpty()
           && layout->labeltype != LABEL_SENSITIVE)
                return;
 
-       recUndo(cursor.par());
+       // a layout change may affect also the following paragraph
+       recUndo(cursor.par(), parOffset(undoSpan(cpit)) - 1);
 
        // Always break behind a space
-       //
        // It is better to erase the space (Dekel)
        if (cursor.pos() < cpit->size() && cpit->isLineSeparator(cursor.pos()))
                cpit->erase(cursor.pos());
@@ -1289,8 +1290,9 @@ void LyXText::backspace()
        pos_type lastpos = pit->size();
 
        if (cursor.pos() == 0) {
-               // The cursor is at the beginning of a paragraph,
-               // so the the backspace will collapse two paragraphs into one.
+               // The cursor is at the beginning of a paragraph, so
+               // the the backspace will collapse two paragraphs into
+               // one.
 
                // but it's not allowed unless it's new
                if (pit->isChangeEdited(0, pit->size()))
@@ -1299,7 +1301,6 @@ void LyXText::backspace()
                // we may paste some paragraphs
 
                // is it an empty paragraph?
-
                if (lastpos == 0 || (lastpos == 1 && pit->isSeparator(0))) {
                        // This is an empty paragraph and we delete it just
                        // by moving the cursor one step
index 91c22d4088d0a383e57ac56d4a75e94bba388733..d34562a8a8a1e52d8367a7f73d5fe96b546af8c5 100644 (file)
@@ -268,19 +268,33 @@ void LyXText::makeFontEntriesLayoutSpecific(BufferParams const & params,
 }
 
 
+// return past-the-last paragraph influenced by a layout change on pit
+ParagraphList::iterator
+LyXText::undoSpan(ParagraphList::iterator pit)
+{
+       ParagraphList::iterator end = paragraphs().end();
+       ParagraphList::iterator nextpit = boost::next(pit);
+       if (nextpit == end)
+               return nextpit;
+       //because of parindents
+       if (!pit->getDepth())
+               return boost::next(nextpit);
+       //because of depth constrains
+       for (; nextpit != end; ++pit, ++nextpit) {
+               if (!pit->getDepth())
+                       break;
+       }
+       return nextpit;
+}
+
+
 ParagraphList::iterator
 LyXText::setLayout(ParagraphList::iterator start,
                   ParagraphList::iterator end,
                   string const & layout)
 {
-       ParagraphList::iterator undopit = end;
-       ParagraphList::iterator pars_end = paragraphs().end();
-
-       while (undopit != pars_end && undopit->getDepth())
-               ++undopit;
-       //because of parindets etc
-       if (undopit != pars_end)
-               ++undopit;
+       BOOST_ASSERT(start != end);
+       ParagraphList::iterator undopit = undoSpan(boost::prior(end));
        recUndo(parOffset(start), parOffset(undopit) - 1);
 
        BufferParams const & bufparams = bv()->buffer()->params();
@@ -582,16 +596,8 @@ void LyXText::setParagraph(Spacing const & spacing, LyXAlignment align,
        string const & labelwidthstring, bool noindent)
 {
        // make sure that the depth behind the selection are restored, too
-       ParagraphList::iterator endpit = boost::next(getPar(selEnd()));
-       ParagraphList::iterator pars_end = paragraphs().end();
-
-       while (endpit != pars_end && endpit->getDepth())
-               ++endpit;
-       // because of parindents etc.
-       if (endpit != pars_end)
-               ++endpit;
-
-       recUndo(selStart().par(), parOffset(endpit) - 1);
+       ParagraphList::iterator undopit = undoSpan(getPar(selEnd()));
+       recUndo(selStart().par(), parOffset(undopit) - 1);
 
        ParagraphList::reverse_iterator pit(getPar(selEnd().par()));
        ParagraphList::reverse_iterator beg(getPar(selStart().par()));
@@ -615,7 +621,7 @@ void LyXText::setParagraph(Spacing const & spacing, LyXAlignment align,
                params.noindent(noindent);
        }
 
-       redoParagraphs(getPar(selStart()), endpit);
+       redoParagraphs(getPar(selStart()), undopit);
 }
 
 
@@ -952,14 +958,7 @@ void LyXText::cutSelection(bool doclear, bool realcut)
        // make sure that the depth behind the selection are restored, too
        ParagraphList::iterator begpit = getPar(selStart().par());
        ParagraphList::iterator endpit = getPar(selEnd().par());
-       ParagraphList::iterator undopit = boost::next(endpit);
-       ParagraphList::iterator pars_end = paragraphs().end();
-
-       while (undopit != pars_end && undopit->getDepth())
-               ++undopit;
-       //because of parindents etc.
-       if (undopit != pars_end)
-               ++undopit;
+       ParagraphList::iterator undopit = undoSpan(endpit);
        recUndo(selStart().par(), parOffset(undopit) - 1);
 
        int endpos = selEnd().pos();