3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Asger Alstrup
7 * \author Lars Gullik Bjønnes
8 * \author Alfredo Braunstein
9 * \author Jean-Marc Lasgouttes
10 * \author Angus Leeming
12 * \author André Pönitz
14 * \author Stefan Schimanski
16 * \author Jürgen Vigna
18 * Full author contact details are available in file CREDITS.
27 #include "buffer_funcs.h"
28 #include "BufferList.h"
29 #include "BufferParams.h"
30 #include "BufferView.h"
33 #include "CutAndPaste.h"
34 #include "DispatchResult.h"
35 #include "ErrorList.h"
36 #include "FuncRequest.h"
42 #include "Paragraph.h"
43 #include "paragraph_funcs.h"
44 #include "ParagraphParameters.h"
45 #include "TextClass.h"
46 #include "TextMetrics.h"
49 #include "insets/InsetCollapsable.h"
51 #include "mathed/InsetMathHull.h"
53 #include "support/lassert.h"
54 #include "support/debug.h"
55 #include "support/gettext.h"
56 #include "support/textutils.h"
58 #include <boost/next_prior.hpp>
66 bool Text::isMainText() const
68 return &owner_->buffer().text() == this;
72 // Note that this is supposed to return a fully realized font.
73 FontInfo Text::layoutFont(pit_type const pit) const
75 Layout const & layout = pars_[pit].layout();
77 if (!pars_[pit].getDepth()) {
78 FontInfo lf = layout.resfont;
79 // In case the default family has been customized
80 if (layout.font.family() == INHERIT_FAMILY)
81 lf.setFamily(owner_->buffer().params().getFont().fontInfo().family());
83 // It ought to be possible here just to use Inset::getLayout() and skip
84 // the asInsetCollapsable() bit. Unfortunatley, that doesn't work right
85 // now, because Inset::getLayout() will return a default-constructed
86 // InsetLayout, and that e.g. sets the foreground color to red. So we
87 // need to do some work to make that possible.
88 InsetCollapsable const * icp = pars_[pit].inInset().asInsetCollapsable();
91 FontInfo icf = icp->getLayout().font();
96 FontInfo font = layout.font;
97 // Realize with the fonts of lesser depth.
98 //font.realize(outerFont(pit, paragraphs()));
99 font.realize(owner_->buffer().params().getFont().fontInfo());
105 // Note that this is supposed to return a fully realized font.
106 FontInfo Text::labelFont(Paragraph const & par) const
108 Buffer const & buffer = owner_->buffer();
109 Layout const & layout = par.layout();
111 if (!par.getDepth()) {
112 FontInfo lf = layout.reslabelfont;
113 // In case the default family has been customized
114 if (layout.labelfont.family() == INHERIT_FAMILY)
115 lf.setFamily(buffer.params().getFont().fontInfo().family());
119 FontInfo font = layout.labelfont;
120 // Realize with the fonts of lesser depth.
121 font.realize(buffer.params().getFont().fontInfo());
127 void Text::setCharFont(pit_type pit,
128 pos_type pos, Font const & fnt, Font const & display_font)
130 Buffer const & buffer = owner_->buffer();
132 Layout const & layout = pars_[pit].layout();
134 // Get concrete layout font to reduce against
137 if (pos < pars_[pit].beginOfBody())
138 layoutfont = layout.labelfont;
140 layoutfont = layout.font;
142 // Realize against environment font information
143 if (pars_[pit].getDepth()) {
145 while (!layoutfont.resolved() &&
146 tp != pit_type(paragraphs().size()) &&
147 pars_[tp].getDepth()) {
148 tp = outerHook(tp, paragraphs());
149 if (tp != pit_type(paragraphs().size()))
150 layoutfont.realize(pars_[tp].layout().font);
154 // Inside inset, apply the inset's font attributes if any
157 layoutfont.realize(display_font.fontInfo());
159 layoutfont.realize(buffer.params().getFont().fontInfo());
161 // Now, reduce font against full layout font
162 font.fontInfo().reduce(layoutfont);
164 pars_[pit].setFont(pos, font);
168 void Text::setInsetFont(BufferView const & bv, pit_type pit,
169 pos_type pos, Font const & font, bool toggleall)
171 Inset * const inset = pars_[pit].getInset(pos);
172 LASSERT(inset && inset->noFontChange(), /**/);
174 CursorSlice::idx_type endidx = inset->nargs();
175 for (CursorSlice cs(*inset); cs.idx() != endidx; ++cs.idx()) {
176 Text * text = cs.text();
178 // last position of the cell
179 CursorSlice cellend = cs;
180 cellend.pit() = cellend.lastpit();
181 cellend.pos() = cellend.lastpos();
182 text->setFont(bv, cs, cellend, font, toggleall);
188 // return past-the-last paragraph influenced by a layout change on pit
189 pit_type Text::undoSpan(pit_type pit)
191 pit_type const end = paragraphs().size();
192 pit_type nextpit = pit + 1;
195 //because of parindents
196 if (!pars_[pit].getDepth())
197 return boost::next(nextpit);
198 //because of depth constrains
199 for (; nextpit != end; ++pit, ++nextpit) {
200 if (!pars_[pit].getDepth())
207 void Text::setLayout(pit_type start, pit_type end,
208 docstring const & layout)
210 LASSERT(start != end, /**/);
212 Buffer const & buffer = owner_->buffer();
213 BufferParams const & bp = buffer.params();
214 Layout const & lyxlayout = bp.documentClass()[layout];
216 for (pit_type pit = start; pit != end; ++pit) {
217 Paragraph & par = pars_[pit];
218 par.applyLayout(lyxlayout);
219 if (lyxlayout.margintype == MARGIN_MANUAL)
220 par.setLabelWidthString(par.expandLabel(lyxlayout, bp));
225 // set layout over selection and make a total rebreak of those paragraphs
226 void Text::setLayout(Cursor & cur, docstring const & layout)
228 LASSERT(this == cur.text(), /**/);
230 pit_type start = cur.selBegin().pit();
231 pit_type end = cur.selEnd().pit() + 1;
232 pit_type undopit = undoSpan(end - 1);
233 recUndo(cur, start, undopit - 1);
234 setLayout(start, end, layout);
235 cur.buffer()->updateLabels();
239 static bool changeDepthAllowed(Text::DEPTH_CHANGE type,
240 Paragraph const & par, int max_depth)
242 if (par.layout().labeltype == LABEL_BIBLIO)
244 int const depth = par.params().depth();
245 if (type == Text::INC_DEPTH && depth < max_depth)
247 if (type == Text::DEC_DEPTH && depth > 0)
253 bool Text::changeDepthAllowed(Cursor & cur, DEPTH_CHANGE type) const
255 LASSERT(this == cur.text(), /**/);
256 // this happens when selecting several cells in tabular (bug 2630)
257 if (cur.selBegin().idx() != cur.selEnd().idx())
260 pit_type const beg = cur.selBegin().pit();
261 pit_type const end = cur.selEnd().pit() + 1;
262 int max_depth = (beg != 0 ? pars_[beg - 1].getMaxDepthAfter() : 0);
264 for (pit_type pit = beg; pit != end; ++pit) {
265 if (lyx::changeDepthAllowed(type, pars_[pit], max_depth))
267 max_depth = pars_[pit].getMaxDepthAfter();
273 void Text::changeDepth(Cursor & cur, DEPTH_CHANGE type)
275 LASSERT(this == cur.text(), /**/);
276 pit_type const beg = cur.selBegin().pit();
277 pit_type const end = cur.selEnd().pit() + 1;
278 cur.recordUndoSelection();
279 int max_depth = (beg != 0 ? pars_[beg - 1].getMaxDepthAfter() : 0);
281 for (pit_type pit = beg; pit != end; ++pit) {
282 Paragraph & par = pars_[pit];
283 if (lyx::changeDepthAllowed(type, par, max_depth)) {
284 int const depth = par.params().depth();
285 if (type == INC_DEPTH)
286 par.params().depth(depth + 1);
288 par.params().depth(depth - 1);
290 max_depth = par.getMaxDepthAfter();
292 // this handles the counter labels, and also fixes up
293 // depth values for follow-on (child) paragraphs
294 cur.buffer()->updateLabels();
298 void Text::setFont(Cursor & cur, Font const & font, bool toggleall)
300 LASSERT(this == cur.text(), /**/);
301 // Set the current_font
302 // Determine basis font
304 pit_type pit = cur.pit();
305 if (cur.pos() < pars_[pit].beginOfBody())
306 layoutfont = labelFont(pars_[pit]);
308 layoutfont = layoutFont(pit);
310 // Update current font
311 cur.real_current_font.update(font,
312 cur.buffer()->params().language,
315 // Reduce to implicit settings
316 cur.current_font = cur.real_current_font;
317 cur.current_font.fontInfo().reduce(layoutfont);
318 // And resolve it completely
319 cur.real_current_font.fontInfo().realize(layoutfont);
321 // if there is no selection that's all we need to do
322 if (!cur.selection())
325 // Ok, we have a selection.
326 cur.recordUndoSelection();
328 setFont(cur.bv(), cur.selectionBegin().top(),
329 cur.selectionEnd().top(), font, toggleall);
333 void Text::setFont(BufferView const & bv, CursorSlice const & begin,
334 CursorSlice const & end, Font const & font,
337 Buffer const & buffer = bv.buffer();
339 // Don't use forwardChar here as ditend might have
340 // pos() == lastpos() and forwardChar would miss it.
341 // Can't use forwardPos either as this descends into
343 Language const * language = buffer.params().language;
344 for (CursorSlice dit = begin; dit != end; dit.forwardPos()) {
345 if (dit.pos() == dit.lastpos())
347 pit_type const pit = dit.pit();
348 pos_type const pos = dit.pos();
349 Inset * inset = pars_[pit].getInset(pos);
350 if (inset && inset->noFontChange()) {
351 // We need to propagate the font change to all
352 // text cells of the inset (bug 1973).
353 // FIXME: This should change, see documentation
354 // of noFontChange in Inset.h
355 setInsetFont(bv, pit, pos, font, toggleall);
357 TextMetrics const & tm = bv.textMetrics(this);
358 Font f = tm.displayFont(pit, pos);
359 f.update(font, language, toggleall);
360 setCharFont(pit, pos, f, tm.font_);
365 bool Text::cursorTop(Cursor & cur)
367 LASSERT(this == cur.text(), /**/);
368 return setCursor(cur, 0, 0);
372 bool Text::cursorBottom(Cursor & cur)
374 LASSERT(this == cur.text(), /**/);
375 return setCursor(cur, cur.lastpit(), boost::prior(paragraphs().end())->size());
379 void Text::toggleFree(Cursor & cur, Font const & font, bool toggleall)
381 LASSERT(this == cur.text(), /**/);
382 // If the mask is completely neutral, tell user
383 if (font.fontInfo() == ignore_font && font.language() == ignore_language) {
384 // Could only happen with user style
385 cur.message(_("No font change defined."));
389 // Try implicit word selection
390 // If there is a change in the language the implicit word selection
392 CursorSlice const resetCursor = cur.top();
393 bool const implicitSelection =
394 font.language() == ignore_language
395 && font.fontInfo().number() == FONT_IGNORE
396 && selectWordWhenUnderCursor(cur, WHOLE_WORD_STRICT);
399 setFont(cur, font, toggleall);
401 // Implicit selections are cleared afterwards
402 // and cursor is set to the original position.
403 if (implicitSelection) {
404 cur.clearSelection();
405 cur.top() = resetCursor;
411 docstring Text::getStringToIndex(Cursor const & cur)
413 LASSERT(this == cur.text(), /**/);
416 return cur.selectionAsString(false);
418 // Try implicit word selection. If there is a change
419 // in the language the implicit word selection is
422 selectWord(tmpcur, PREVIOUS_WORD);
424 if (!tmpcur.selection())
425 cur.message(_("Nothing to index!"));
426 else if (tmpcur.selBegin().pit() != tmpcur.selEnd().pit())
427 cur.message(_("Cannot index more than one paragraph!"));
429 return tmpcur.selectionAsString(false);
435 void Text::setParagraphs(Cursor & cur, docstring arg, bool merge)
437 LASSERT(cur.text(), /**/);
438 // make sure that the depth behind the selection are restored, too
439 pit_type undopit = undoSpan(cur.selEnd().pit());
440 recUndo(cur, cur.selBegin().pit(), undopit - 1);
443 string const argument = to_utf8(arg);
444 depth_type priordepth = -1;
446 for (pit_type pit = cur.selBegin().pit(), end = cur.selEnd().pit();
448 Paragraph & par = pars_[pit];
449 ParagraphParameters params = par.params();
450 params.read(argument, merge);
451 // Changes to label width string apply to all paragraphs
452 // with same layout in a sequence.
453 // Do this only once for a selected range of paragraphs
454 // of the same layout and depth.
455 if (par.getDepth() != priordepth || par.layout() != priorlayout)
456 setLabelWidthStringToSequence(pit, pars_,
457 params.labelWidthString());
458 par.params().apply(params, par.layout());
459 priordepth = par.getDepth();
460 priorlayout = par.layout();
465 //FIXME This is a little redundant now, but it's probably worth keeping,
466 //especially if we're going to go away from using serialization internally
468 void Text::setParagraphs(Cursor & cur, ParagraphParameters const & p)
470 LASSERT(cur.text(), /**/);
471 // make sure that the depth behind the selection are restored, too
472 pit_type undopit = undoSpan(cur.selEnd().pit());
473 recUndo(cur, cur.selBegin().pit(), undopit - 1);
475 depth_type priordepth = -1;
477 for (pit_type pit = cur.selBegin().pit(), end = cur.selEnd().pit();
479 Paragraph & par = pars_[pit];
480 // Changes to label width string apply to all paragraphs
481 // with same layout in a sequence.
482 // Do this only once for a selected range of paragraphs
483 // of the same layout and depth.
484 if (par.getDepth() != priordepth || par.layout() != priorlayout)
485 setLabelWidthStringToSequence(pit, pars_,
486 par.params().labelWidthString());
487 par.params().apply(p, par.layout());
488 priordepth = par.getDepth();
489 priorlayout = par.layout();
494 // this really should just insert the inset and not move the cursor.
495 void Text::insertInset(Cursor & cur, Inset * inset)
497 LASSERT(this == cur.text(), /**/);
498 LASSERT(inset, /**/);
499 cur.paragraph().insertInset(cur.pos(), inset, cur.current_font,
500 Change(cur.buffer()->params().trackChanges
501 ? Change::INSERTED : Change::UNCHANGED));
505 // needed to insert the selection
506 void Text::insertStringAsLines(Cursor & cur, docstring const & str)
508 cur.buffer()->insertStringAsLines(pars_, cur.pit(), cur.pos(),
509 cur.current_font, str, autoBreakRows_);
513 // turn double CR to single CR, others are converted into one
514 // blank. Then insertStringAsLines is called
515 void Text::insertStringAsParagraphs(Cursor & cur, docstring const & str)
517 docstring linestr = str;
518 bool newline_inserted = false;
520 for (string::size_type i = 0, siz = linestr.size(); i < siz; ++i) {
521 if (linestr[i] == '\n') {
522 if (newline_inserted) {
523 // we know that \r will be ignored by
524 // insertStringAsLines. Of course, it is a dirty
525 // trick, but it works...
526 linestr[i - 1] = '\r';
530 newline_inserted = true;
532 } else if (isPrintable(linestr[i])) {
533 newline_inserted = false;
536 insertStringAsLines(cur, linestr);
540 bool Text::setCursor(Cursor & cur, pit_type par, pos_type pos,
541 bool setfont, bool boundary)
543 TextMetrics const & tm = cur.bv().textMetrics(this);
544 bool const update_needed = !tm.contains(par);
546 setCursorIntern(cur, par, pos, setfont, boundary);
547 return cur.bv().checkDepm(cur, old) || update_needed;
551 void Text::setCursor(CursorSlice & cur, pit_type par, pos_type pos)
553 LASSERT(par != int(paragraphs().size()), /**/);
557 // now some strict checking
558 Paragraph & para = getPar(par);
560 // None of these should happen, but we're scaredy-cats
562 lyxerr << "dont like -1" << endl;
563 LASSERT(false, /**/);
566 if (pos > para.size()) {
567 lyxerr << "dont like 1, pos: " << pos
568 << " size: " << para.size()
569 << " par: " << par << endl;
570 LASSERT(false, /**/);
575 void Text::setCursorIntern(Cursor & cur,
576 pit_type par, pos_type pos, bool setfont, bool boundary)
578 LASSERT(this == cur.text(), /**/);
579 cur.boundary(boundary);
580 setCursor(cur.top(), par, pos);
582 cur.setCurrentFont();
586 bool Text::checkAndActivateInset(Cursor & cur, bool front)
590 if (front && cur.pos() == cur.lastpos())
592 if (!front && cur.pos() == 0)
594 Inset * inset = front ? cur.nextInset() : cur.prevInset();
595 if (!inset || !inset->editable())
598 * Apparently, when entering an inset we are expected to be positioned
599 * *before* it in the containing paragraph, regardless of the direction
600 * from which we are entering. Otherwise, cursor placement goes awry,
601 * and when we exit from the beginning, we'll be placed *after* the
606 inset->edit(cur, front);
611 bool Text::checkAndActivateInsetVisual(Cursor & cur, bool movingForward, bool movingLeft)
617 if (cur.pos() == cur.lastpos())
619 Paragraph & par = cur.paragraph();
620 Inset * inset = par.isInset(cur.pos()) ? par.getInset(cur.pos()) : 0;
621 if (!inset || !inset->editable())
623 inset->edit(cur, movingForward,
624 movingLeft ? Inset::ENTRY_DIRECTION_RIGHT : Inset::ENTRY_DIRECTION_LEFT);
629 bool Text::cursorBackward(Cursor & cur)
631 // Tell BufferView to test for FitCursor in any case!
632 cur.updateFlags(Update::FitCursor);
634 // not at paragraph start?
636 // if on right side of boundary (i.e. not at paragraph end, but line end)
637 // -> skip it, i.e. set boundary to true, i.e. go only logically left
638 // there are some exceptions to ignore this: lineseps, newlines, spaces
640 // some effectless debug code to see the values in the debugger
641 bool bound = cur.boundary();
642 int rowpos = cur.textRow().pos();
644 bool sep = cur.paragraph().isSeparator(cur.pos() - 1);
645 bool newline = cur.paragraph().isNewline(cur.pos() - 1);
646 bool linesep = cur.paragraph().isLineSeparator(cur.pos() - 1);
648 if (!cur.boundary() &&
649 cur.textRow().pos() == cur.pos() &&
650 !cur.paragraph().isLineSeparator(cur.pos() - 1) &&
651 !cur.paragraph().isNewline(cur.pos() - 1) &&
652 !cur.paragraph().isSeparator(cur.pos() - 1)) {
653 return setCursor(cur, cur.pit(), cur.pos(), true, true);
656 // go left and try to enter inset
657 if (checkAndActivateInset(cur, false))
660 // normal character left
661 return setCursor(cur, cur.pit(), cur.pos() - 1, true, false);
664 // move to the previous paragraph or do nothing
666 return setCursor(cur, cur.pit() - 1, getPar(cur.pit() - 1).size(), true, false);
671 bool Text::cursorVisLeft(Cursor & cur, bool skip_inset)
673 Cursor temp_cur = cur;
674 temp_cur.posVisLeft(skip_inset);
675 if (temp_cur.depth() > cur.depth()) {
679 return setCursor(cur, temp_cur.pit(), temp_cur.pos(),
680 true, temp_cur.boundary());
684 bool Text::cursorVisRight(Cursor & cur, bool skip_inset)
686 Cursor temp_cur = cur;
687 temp_cur.posVisRight(skip_inset);
688 if (temp_cur.depth() > cur.depth()) {
692 return setCursor(cur, temp_cur.pit(), temp_cur.pos(),
693 true, temp_cur.boundary());
697 bool Text::cursorForward(Cursor & cur)
699 // Tell BufferView to test for FitCursor in any case!
700 cur.updateFlags(Update::FitCursor);
702 // not at paragraph end?
703 if (cur.pos() != cur.lastpos()) {
704 // in front of editable inset, i.e. jump into it?
705 if (checkAndActivateInset(cur, true))
708 TextMetrics const & tm = cur.bv().textMetrics(this);
709 // if left of boundary -> just jump to right side
710 // but for RTL boundaries don't, because: abc|DDEEFFghi -> abcDDEEF|Fghi
711 if (cur.boundary() && !tm.isRTLBoundary(cur.pit(), cur.pos()))
712 return setCursor(cur, cur.pit(), cur.pos(), true, false);
714 // next position is left of boundary,
715 // but go to next line for special cases like space, newline, linesep
717 // some effectless debug code to see the values in the debugger
718 int endpos = cur.textRow().endpos();
719 int lastpos = cur.lastpos();
721 bool linesep = cur.paragraph().isLineSeparator(cur.pos());
722 bool newline = cur.paragraph().isNewline(cur.pos());
723 bool sep = cur.paragraph().isSeparator(cur.pos());
724 if (cur.pos() != cur.lastpos()) {
725 bool linesep2 = cur.paragraph().isLineSeparator(cur.pos()+1);
726 bool newline2 = cur.paragraph().isNewline(cur.pos()+1);
727 bool sep2 = cur.paragraph().isSeparator(cur.pos()+1);
730 if (cur.textRow().endpos() == cur.pos() + 1 &&
731 cur.textRow().endpos() != cur.lastpos() &&
732 !cur.paragraph().isNewline(cur.pos()) &&
733 !cur.paragraph().isLineSeparator(cur.pos()) &&
734 !cur.paragraph().isSeparator(cur.pos())) {
735 return setCursor(cur, cur.pit(), cur.pos() + 1, true, true);
738 // in front of RTL boundary? Stay on this side of the boundary because:
739 // ab|cDDEEFFghi -> abc|DDEEFFghi
740 if (tm.isRTLBoundary(cur.pit(), cur.pos() + 1))
741 return setCursor(cur, cur.pit(), cur.pos() + 1, true, true);
744 return setCursor(cur, cur.pit(), cur.pos() + 1, true, false);
747 // move to next paragraph
748 if (cur.pit() != cur.lastpit())
749 return setCursor(cur, cur.pit() + 1, 0, true, false);
754 bool Text::cursorUpParagraph(Cursor & cur)
756 bool updated = false;
758 updated = setCursor(cur, cur.pit(), 0);
759 else if (cur.pit() != 0)
760 updated = setCursor(cur, cur.pit() - 1, 0);
765 bool Text::cursorDownParagraph(Cursor & cur)
767 bool updated = false;
768 if (cur.pit() != cur.lastpit())
769 updated = setCursor(cur, cur.pit() + 1, 0);
771 updated = setCursor(cur, cur.pit(), cur.lastpos());
776 // fix the cursor `cur' after a characters has been deleted at `where'
777 // position. Called by deleteEmptyParagraphMechanism
778 void Text::fixCursorAfterDelete(CursorSlice & cur, CursorSlice const & where)
780 // Do nothing if cursor is not in the paragraph where the
782 if (cur.pit() != where.pit())
785 // If cursor position is after the deletion place update it
786 if (cur.pos() > where.pos())
789 // Check also if we don't want to set the cursor on a spot behind the
790 // pagragraph because we erased the last character.
791 if (cur.pos() > cur.lastpos())
792 cur.pos() = cur.lastpos();
796 bool Text::deleteEmptyParagraphMechanism(Cursor & cur,
797 Cursor & old, bool & need_anchor_change)
799 //LYXERR(Debug::DEBUG, "DEPM: cur:\n" << cur << "old:\n" << old);
801 Paragraph & oldpar = old.paragraph();
803 // We allow all kinds of "mumbo-jumbo" when freespacing.
804 if (oldpar.isFreeSpacing())
807 /* Ok I'll put some comments here about what is missing.
808 There are still some small problems that can lead to
809 double spaces stored in the document file or space at
810 the beginning of paragraphs(). This happens if you have
811 the cursor between to spaces and then save. Or if you
812 cut and paste and the selection have a space at the
813 beginning and then save right after the paste. (Lgb)
816 // If old.pos() == 0 and old.pos()(1) == LineSeparator
817 // delete the LineSeparator.
820 // If old.pos() == 1 and old.pos()(0) == LineSeparator
821 // delete the LineSeparator.
824 // Find a common inset and the corresponding depth.
826 for (; depth < cur.depth(); ++depth)
827 if (&old.inset() == &cur[depth].inset())
830 // Whether a common inset is found and whether the cursor is still in
831 // the same paragraph (possibly nested).
832 bool const same_par = depth < cur.depth() && old.pit() == cur[depth].pit();
833 bool const same_par_pos = depth == cur.depth() - 1 && same_par
834 && old.pos() == cur[depth].pos();
836 // If the chars around the old cursor were spaces, delete one of them.
838 // Only if the cursor has really moved.
840 && old.pos() < oldpar.size()
841 && oldpar.isLineSeparator(old.pos())
842 && oldpar.isLineSeparator(old.pos() - 1)
843 && !oldpar.isDeleted(old.pos() - 1)
844 && !oldpar.isDeleted(old.pos())) {
845 oldpar.eraseChar(old.pos() - 1, cur.buffer()->params().trackChanges);
846 // FIXME: This will not work anymore when we have multiple views of the same buffer
847 // In this case, we will have to correct also the cursors held by
848 // other bufferviews. It will probably be easier to do that in a more
849 // automated way in CursorSlice code. (JMarc 26/09/2001)
850 // correct all cursor parts
852 fixCursorAfterDelete(cur[depth], old.top());
853 need_anchor_change = true;
859 // only do our magic if we changed paragraph
863 // don't delete anything if this is the ONLY paragraph!
864 if (old.lastpit() == 0)
867 // Do not delete empty paragraphs with keepempty set.
868 if (oldpar.allowEmpty())
871 if (oldpar.empty() || (oldpar.size() == 1 && oldpar.isLineSeparator(0))) {
873 old.recordUndo(ATOMIC_UNDO,
874 max(old.pit() - 1, pit_type(0)),
875 min(old.pit() + 1, old.lastpit()));
876 ParagraphList & plist = old.text()->paragraphs();
877 bool const soa = oldpar.params().startOfAppendix();
878 plist.erase(boost::next(plist.begin(), old.pit()));
879 // do not lose start of appendix marker (bug 4212)
880 if (soa && old.pit() < pit_type(plist.size()))
881 plist[old.pit()].params().startOfAppendix(true);
883 // see #warning (FIXME?) above
884 if (cur.depth() >= old.depth()) {
885 CursorSlice & curslice = cur[old.depth() - 1];
886 if (&curslice.inset() == &old.inset()
887 && curslice.pit() > old.pit()) {
889 // since a paragraph has been deleted, all the
890 // insets after `old' have been copied and
891 // their address has changed. Therefore we
892 // need to `regenerate' cur. (JMarc)
893 cur.updateInsets(&(cur.bottom().inset()));
894 need_anchor_change = true;
900 if (oldpar.stripLeadingSpaces(cur.buffer()->params().trackChanges)) {
901 need_anchor_change = true;
902 // We return true here because the Paragraph contents changed and
903 // we need a redraw before further action is processed.
911 void Text::deleteEmptyParagraphMechanism(pit_type first, pit_type last, bool trackChanges)
913 LASSERT(first >= 0 && first <= last && last < (int) pars_.size(), /**/);
915 for (pit_type pit = first; pit <= last; ++pit) {
916 Paragraph & par = pars_[pit];
918 // We allow all kinds of "mumbo-jumbo" when freespacing.
919 if (par.isFreeSpacing())
922 for (pos_type pos = 1; pos < par.size(); ++pos) {
923 if (par.isLineSeparator(pos) && par.isLineSeparator(pos - 1)
924 && !par.isDeleted(pos - 1)) {
925 if (par.eraseChar(pos - 1, trackChanges)) {
931 // don't delete anything if this is the only remaining paragraph within the given range
932 // note: Text::acceptOrRejectChanges() sets the cursor to 'first' after calling DEPM
936 // don't delete empty paragraphs with keepempty set
937 if (par.allowEmpty())
940 if (par.empty() || (par.size() == 1 && par.isLineSeparator(0))) {
941 pars_.erase(boost::next(pars_.begin(), pit));
947 par.stripLeadingSpaces(trackChanges);
952 void Text::recUndo(Cursor & cur, pit_type first, pit_type last) const
954 cur.recordUndo(ATOMIC_UNDO, first, last);
958 void Text::recUndo(Cursor & cur, pit_type par) const
960 cur.recordUndo(ATOMIC_UNDO, par, par);