From: Alfredo Braunstein Date: Fri, 9 Jan 2004 09:04:33 +0000 (+0000) Subject: add and LyXText::undoSpan to compute the influence of a layout change. X-Git-Tag: 1.6.10~15587 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=80296aac5015662a4c23ee7a818d5fde34f363bd;p=features.git add and LyXText::undoSpan to compute the influence of a layout change. Fix Bug 578. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8331 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/ChangeLog b/src/ChangeLog index fdc6b66a3a..ada751cce9 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2004-01-08 Alfredo Braunstein + + * text2.C (undoSpan): add and use + * text.C (breakParagraph): use undoSpan (fix bug 578) + * lyxtext.h: adjust 2004-01-08 Angus Leeming diff --git a/src/lyxtext.h b/src/lyxtext.h index fdd54a0cd4..949566c3e0 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -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 diff --git a/src/text.C b/src/text.C index 398df84480..bf177b290e 100644 --- a/src/text.C +++ b/src/text.C @@ -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 diff --git a/src/text2.C b/src/text2.C index 91c22d4088..d34562a8a8 100644 --- a/src/text2.C +++ b/src/text2.C @@ -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();