Fix Bug 578.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8331
a592a061-630c-0410-9148-
cb99ea01b6c8
+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>
2004-01-08 Angus Leeming <leeming@lyx.org>
+ /// 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
/// rebreaks the given par
void redoParagraphInternal(ParagraphList::iterator pit);
/// used in setlayout
// are taken from the layoutfont. Nicer on the screen :)
LyXLayout_ptr const & layout = pit->layout();
// 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);
LyXFont font = getFont(pit, row.pos());
LyXFont::FONT_SIZE const tmpsize = font.size();
font = getLayoutFont(pit);
bv()->buffer()->params().getLyXTextClass();
LyXLayout_ptr const & layout = cpit->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;
if (cpit->empty() && !cpit->allowEmpty()
&& layout->labeltype != LABEL_SENSITIVE)
return;
+ // a layout change may affect also the following paragraph
+ recUndo(cursor.par(), parOffset(undoSpan(cpit)) - 1);
// Always break behind a space
// 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());
// It is better to erase the space (Dekel)
if (cursor.pos() < cpit->size() && cpit->isLineSeparator(cursor.pos()))
cpit->erase(cursor.pos());
pos_type lastpos = pit->size();
if (cursor.pos() == 0) {
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()))
// but it's not allowed unless it's new
if (pit->isChangeEdited(0, pit->size()))
// we may paste some paragraphs
// is it an empty paragraph?
// 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
if (lastpos == 0 || (lastpos == 1 && pit->isSeparator(0))) {
// This is an empty paragraph and we delete it just
// by moving the cursor one step
+// 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
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();
recUndo(parOffset(start), parOffset(undopit) - 1);
BufferParams const & bufparams = bv()->buffer()->params();
string const & labelwidthstring, bool noindent)
{
// make sure that the depth behind the selection are restored, too
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()));
ParagraphList::reverse_iterator pit(getPar(selEnd().par()));
ParagraphList::reverse_iterator beg(getPar(selStart().par()));
params.noindent(noindent);
}
params.noindent(noindent);
}
- redoParagraphs(getPar(selStart()), endpit);
+ redoParagraphs(getPar(selStart()), undopit);
// make sure that the depth behind the selection are restored, too
ParagraphList::iterator begpit = getPar(selStart().par());
ParagraphList::iterator endpit = getPar(selEnd().par());
// 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();
recUndo(selStart().par(), parOffset(undopit) - 1);
int endpos = selEnd().pos();