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.
26 #include "buffer_funcs.h"
27 #include "BufferList.h"
28 #include "BufferParams.h"
29 #include "BufferView.h"
34 #include "CutAndPaste.h"
36 #include "DispatchResult.h"
37 #include "ErrorList.h"
38 #include "FuncRequest.h"
45 #include "Paragraph.h"
46 #include "paragraph_funcs.h"
47 #include "ParagraphParameters.h"
48 #include "ParIterator.h"
50 #include "ServerSocket.h"
51 #include "TextMetrics.h"
54 #include "frontends/FontMetrics.h"
56 #include "insets/InsetEnvironment.h"
58 #include "mathed/InsetMathHull.h"
60 #include "support/textutils.h"
62 #include <boost/current_function.hpp>
63 #include <boost/next_prior.hpp>
68 using std::ostringstream;
72 using std::istringstream;
77 : autoBreakRows_(false)
81 bool Text::isMainText(Buffer const & buffer) const
83 return &buffer.text() == this;
87 Font Text::getLayoutFont(Buffer const & buffer, pit_type const pit) const
89 LayoutPtr const & layout = pars_[pit].layout();
91 if (!pars_[pit].getDepth()) {
92 Font lf = layout->resfont;
93 // In case the default family has been customized
94 if (layout->font.family() == Font::INHERIT_FAMILY)
95 lf.setFamily(buffer.params().getFont().family());
99 Font font = layout->font;
100 // Realize with the fonts of lesser depth.
101 //font.realize(outerFont(pit, paragraphs()));
102 font.realize(buffer.params().getFont());
108 Font Text::getLabelFont(Buffer const & buffer, Paragraph const & par) const
110 LayoutPtr const & layout = par.layout();
112 if (!par.getDepth()) {
113 Font lf = layout->reslabelfont;
114 // In case the default family has been customized
115 if (layout->labelfont.family() == Font::INHERIT_FAMILY)
116 lf.setFamily(buffer.params().getFont().family());
120 Font font = layout->labelfont;
121 // Realize with the fonts of lesser depth.
122 font.realize(buffer.params().getFont());
128 void Text::setCharFont(Buffer const & buffer, pit_type pit,
129 pos_type pos, Font const & fnt, Font const & display_font)
132 LayoutPtr 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
156 if (!isMainText(buffer))
157 layoutfont.realize(display_font);
159 layoutfont.realize(buffer.params().getFont());
161 // Now, reduce font against full layout font
162 font.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 BOOST_ASSERT(pars_[pit].isInset(pos) &&
172 pars_[pit].getInset(pos)->noFontChange());
174 Inset * const inset = pars_[pit].getInset(pos);
175 CursorSlice::idx_type endidx = inset->nargs();
176 for (CursorSlice cs(*inset); cs.idx() != endidx; ++cs.idx()) {
177 Text * text = cs.text();
179 // last position of the cell
180 CursorSlice cellend = cs;
181 cellend.pit() = cellend.lastpit();
182 cellend.pos() = cellend.lastpos();
183 text->setFont(bv, cs, cellend, font, toggleall);
189 // return past-the-last paragraph influenced by a layout change on pit
190 pit_type Text::undoSpan(pit_type pit)
192 pit_type end = paragraphs().size();
193 pit_type nextpit = pit + 1;
196 //because of parindents
197 if (!pars_[pit].getDepth())
198 return boost::next(nextpit);
199 //because of depth constrains
200 for (; nextpit != end; ++pit, ++nextpit) {
201 if (!pars_[pit].getDepth())
208 void Text::setLayout(Buffer const & buffer, pit_type start, pit_type end,
209 docstring const & layout)
211 BOOST_ASSERT(start != end);
213 BufferParams const & bufparams = buffer.params();
214 LayoutPtr const & lyxlayout = bufparams.getTextClass()[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.translateIfPossible(
221 lyxlayout->labelstring(), buffer.params()));
226 // set layout over selection and make a total rebreak of those paragraphs
227 void Text::setLayout(Cursor & cur, docstring const & layout)
229 BOOST_ASSERT(this == cur.text());
230 // special handling of new environment insets
231 BufferView & bv = cur.bv();
232 BufferParams const & params = bv.buffer().params();
233 LayoutPtr const & lyxlayout = params.getTextClass()[layout];
234 if (lyxlayout->is_environment) {
235 // move everything in a new environment inset
236 LYXERR(Debug::DEBUG) << "setting layout " << to_utf8(layout) << endl;
237 lyx::dispatch(FuncRequest(LFUN_LINE_BEGIN));
238 lyx::dispatch(FuncRequest(LFUN_LINE_END_SELECT));
239 lyx::dispatch(FuncRequest(LFUN_CUT));
240 Inset * inset = new InsetEnvironment(params, layout);
241 insertInset(cur, inset);
242 //inset->edit(cur, true);
243 //lyx::dispatch(FuncRequest(LFUN_PASTE));
247 pit_type start = cur.selBegin().pit();
248 pit_type end = cur.selEnd().pit() + 1;
249 pit_type undopit = undoSpan(end - 1);
250 recUndo(cur, start, undopit - 1);
251 setLayout(cur.buffer(), start, end, layout);
252 updateLabels(cur.buffer());
256 static bool changeDepthAllowed(Text::DEPTH_CHANGE type,
257 Paragraph const & par, int max_depth)
259 if (par.layout()->labeltype == LABEL_BIBLIO)
261 int const depth = par.params().depth();
262 if (type == Text::INC_DEPTH && depth < max_depth)
264 if (type == Text::DEC_DEPTH && depth > 0)
270 bool Text::changeDepthAllowed(Cursor & cur, DEPTH_CHANGE type) const
272 BOOST_ASSERT(this == cur.text());
273 // this happens when selecting several cells in tabular (bug 2630)
274 if (cur.selBegin().idx() != cur.selEnd().idx())
277 pit_type const beg = cur.selBegin().pit();
278 pit_type const end = cur.selEnd().pit() + 1;
279 int max_depth = (beg != 0 ? pars_[beg - 1].getMaxDepthAfter() : 0);
281 for (pit_type pit = beg; pit != end; ++pit) {
282 if (lyx::changeDepthAllowed(type, pars_[pit], max_depth))
284 max_depth = pars_[pit].getMaxDepthAfter();
290 void Text::changeDepth(Cursor & cur, DEPTH_CHANGE type)
292 BOOST_ASSERT(this == cur.text());
293 pit_type const beg = cur.selBegin().pit();
294 pit_type const end = cur.selEnd().pit() + 1;
295 cur.recordUndoSelection();
296 int max_depth = (beg != 0 ? pars_[beg - 1].getMaxDepthAfter() : 0);
298 for (pit_type pit = beg; pit != end; ++pit) {
299 Paragraph & par = pars_[pit];
300 if (lyx::changeDepthAllowed(type, par, max_depth)) {
301 int const depth = par.params().depth();
302 if (type == INC_DEPTH)
303 par.params().depth(depth + 1);
305 par.params().depth(depth - 1);
307 max_depth = par.getMaxDepthAfter();
309 // this handles the counter labels, and also fixes up
310 // depth values for follow-on (child) paragraphs
311 updateLabels(cur.buffer());
315 void Text::setFont(Cursor & cur, Font const & font, bool toggleall)
317 BOOST_ASSERT(this == cur.text());
318 // Set the current_font
319 // Determine basis font
321 pit_type pit = cur.pit();
322 if (cur.pos() < pars_[pit].beginOfBody())
323 layoutfont = getLabelFont(cur.buffer(), pars_[pit]);
325 layoutfont = getLayoutFont(cur.buffer(), pit);
327 // Update current font
328 cur.real_current_font.update(font,
329 cur.buffer().params().language,
332 // Reduce to implicit settings
333 cur.current_font = cur.real_current_font;
334 cur.current_font.reduce(layoutfont);
335 // And resolve it completely
336 cur.real_current_font.realize(layoutfont);
338 // if there is no selection that's all we need to do
339 if (!cur.selection())
342 // Ok, we have a selection.
343 cur.recordUndoSelection();
345 setFont(cur.bv(), cur.selectionBegin().top(),
346 cur.selectionEnd().top(), font, toggleall);
350 void Text::setFont(BufferView const & bv, CursorSlice const & begin,
351 CursorSlice const & end, Font const & font,
354 Buffer const & buffer = bv.buffer();
356 // Don't use forwardChar here as ditend might have
357 // pos() == lastpos() and forwardChar would miss it.
358 // Can't use forwardPos either as this descends into
360 Language const * language = buffer.params().language;
361 for (CursorSlice dit = begin; dit != end; dit.forwardPos()) {
362 if (dit.pos() != dit.lastpos()) {
363 pit_type const pit = dit.pit();
364 pos_type const pos = dit.pos();
365 if (pars_[pit].isInset(pos) &&
366 pars_[pit].getInset(pos)->noFontChange())
367 // We need to propagate the font change to all
368 // text cells of the inset (bug 1973).
369 // FIXME: This should change, see documentation
370 // of noFontChange in Inset.h
371 setInsetFont(bv, pit, pos, font, toggleall);
372 TextMetrics const & tm = bv.textMetrics(this);
373 Font f = tm.getDisplayFont(pit, pos);
374 f.update(font, language, toggleall);
375 setCharFont(buffer, pit, pos, f, tm.font_);
381 bool Text::cursorTop(Cursor & cur)
383 BOOST_ASSERT(this == cur.text());
384 return setCursor(cur, 0, 0);
388 bool Text::cursorBottom(Cursor & cur)
390 BOOST_ASSERT(this == cur.text());
391 return setCursor(cur, cur.lastpit(), boost::prior(paragraphs().end())->size());
395 void Text::toggleFree(Cursor & cur, Font const & font, bool toggleall)
397 BOOST_ASSERT(this == cur.text());
398 // If the mask is completely neutral, tell user
399 if (font == Font(Font::ALL_IGNORE)) {
400 // Could only happen with user style
401 cur.message(_("No font change defined."));
405 // Try implicit word selection
406 // If there is a change in the language the implicit word selection
408 CursorSlice resetCursor = cur.top();
409 bool implicitSelection =
410 font.language() == ignore_language
411 && font.number() == Font::IGNORE
412 && selectWordWhenUnderCursor(cur, WHOLE_WORD_STRICT);
415 setFont(cur, font, toggleall);
417 // Implicit selections are cleared afterwards
418 // and cursor is set to the original position.
419 if (implicitSelection) {
420 cur.clearSelection();
421 cur.top() = resetCursor;
427 docstring Text::getStringToIndex(Cursor const & cur)
429 BOOST_ASSERT(this == cur.text());
433 idxstring = cur.selectionAsString(false);
435 // Try implicit word selection. If there is a change
436 // in the language the implicit word selection is
439 selectWord(tmpcur, PREVIOUS_WORD);
441 if (!tmpcur.selection())
442 cur.message(_("Nothing to index!"));
443 else if (tmpcur.selBegin().pit() != tmpcur.selEnd().pit())
444 cur.message(_("Cannot index more than one paragraph!"));
446 idxstring = tmpcur.selectionAsString(false);
453 void Text::setParagraphs(Cursor & cur, docstring arg, bool merge)
455 BOOST_ASSERT(cur.text());
456 // make sure that the depth behind the selection are restored, too
457 pit_type undopit = undoSpan(cur.selEnd().pit());
458 recUndo(cur, cur.selBegin().pit(), undopit - 1);
460 for (pit_type pit = cur.selBegin().pit(), end = cur.selEnd().pit();
462 Paragraph & par = pars_[pit];
463 ParagraphParameters params = par.params();
464 params.read(to_utf8(arg), merge);
465 Layout const & layout = *(par.layout());
466 par.params().apply(params, layout);
471 //FIXME This is a little redundant now, but it's probably worth keeping,
472 //especially if we're going to go away from using serialization internally
474 void Text::setParagraphs(Cursor & cur, ParagraphParameters const & p)
476 BOOST_ASSERT(cur.text());
477 // make sure that the depth behind the selection are restored, too
478 pit_type undopit = undoSpan(cur.selEnd().pit());
479 recUndo(cur, cur.selBegin().pit(), undopit - 1);
481 for (pit_type pit = cur.selBegin().pit(), end = cur.selEnd().pit();
483 Paragraph & par = pars_[pit];
484 Layout const & layout = *(par.layout());
485 par.params().apply(p, layout);
490 // this really should just insert the inset and not move the cursor.
491 void Text::insertInset(Cursor & cur, Inset * inset)
493 BOOST_ASSERT(this == cur.text());
495 cur.paragraph().insertInset(cur.pos(), inset, cur.current_font,
496 Change(cur.buffer().params().trackChanges ?
497 Change::INSERTED : Change::UNCHANGED));
501 // needed to insert the selection
502 void Text::insertStringAsLines(Cursor & cur, docstring const & str)
504 cur.buffer().insertStringAsLines(pars_, cur.pit(), cur.pos(),
505 cur.current_font, str, autoBreakRows_);
509 // turn double CR to single CR, others are converted into one
510 // blank. Then insertStringAsLines is called
511 void Text::insertStringAsParagraphs(Cursor & cur, docstring const & str)
513 docstring linestr = str;
514 bool newline_inserted = false;
516 for (string::size_type i = 0, siz = linestr.size(); i < siz; ++i) {
517 if (linestr[i] == '\n') {
518 if (newline_inserted) {
519 // we know that \r will be ignored by
520 // insertStringAsLines. Of course, it is a dirty
521 // trick, but it works...
522 linestr[i - 1] = '\r';
526 newline_inserted = true;
528 } else if (isPrintable(linestr[i])) {
529 newline_inserted = false;
532 insertStringAsLines(cur, linestr);
536 bool Text::setCursor(Cursor & cur, pit_type par, pos_type pos,
537 bool setfont, bool boundary)
540 setCursorIntern(cur, par, pos, setfont, boundary);
541 return cur.bv().checkDepm(cur, old);
545 void Text::setCursor(CursorSlice & cur, pit_type par, pos_type pos)
547 BOOST_ASSERT(par != int(paragraphs().size()));
551 // now some strict checking
552 Paragraph & para = getPar(par);
554 // None of these should happen, but we're scaredy-cats
556 lyxerr << "dont like -1" << endl;
560 if (pos > para.size()) {
561 lyxerr << "dont like 1, pos: " << pos
562 << " size: " << para.size()
563 << " par: " << par << endl;
569 void Text::setCursorIntern(Cursor & cur,
570 pit_type par, pos_type pos, bool setfont, bool boundary)
572 BOOST_ASSERT(this == cur.text());
573 cur.boundary(boundary);
574 setCursor(cur.top(), par, pos);
576 cur.setCurrentFont();
580 bool Text::checkAndActivateInset(Cursor & cur, bool front)
584 if (front && cur.pos() == cur.lastpos())
586 if (!front && cur.pos() == 0)
588 Inset * inset = front ? cur.nextInset() : cur.prevInset();
589 if (!inset || inset->editable() != Inset::HIGHLY_EDITABLE)
592 * Apparently, when entering an inset we are expected to be positioned
593 * *before* it in the containing paragraph, regardless of the direction
594 * from which we are entering. Otherwise, cursor placement goes awry,
595 * and when we exit from the beginning, we'll be placed *after* the
600 inset->edit(cur, front);
605 bool Text::cursorBackward(Cursor & cur)
607 // Tell BufferView to test for FitCursor in any case!
608 cur.updateFlags(Update::FitCursor);
610 // not at paragraph start?
612 // if on right side of boundary (i.e. not at paragraph end, but line end)
613 // -> skip it, i.e. set boundary to true, i.e. go only logically left
614 // there are some exceptions to ignore this: lineseps, newlines, spaces
616 // some effectless debug code to see the values in the debugger
617 bool bound = cur.boundary();
618 int rowpos = cur.textRow().pos();
620 bool sep = cur.paragraph().isSeparator(cur.pos() - 1);
621 bool newline = cur.paragraph().isNewline(cur.pos() - 1);
622 bool linesep = cur.paragraph().isLineSeparator(cur.pos() - 1);
624 if (!cur.boundary() &&
625 cur.textRow().pos() == cur.pos() &&
626 !cur.paragraph().isLineSeparator(cur.pos() - 1) &&
627 !cur.paragraph().isNewline(cur.pos() - 1) &&
628 !cur.paragraph().isSeparator(cur.pos() - 1)) {
629 return setCursor(cur, cur.pit(), cur.pos(), true, true);
632 // go left and try to enter inset
633 if (checkAndActivateInset(cur, false))
636 // normal character left
637 return setCursor(cur, cur.pit(), cur.pos() - 1, true, false);
640 // move to the previous paragraph or do nothing
642 return setCursor(cur, cur.pit() - 1, getPar(cur.pit() - 1).size(), true, false);
647 bool Text::cursorForward(Cursor & cur)
649 // Tell BufferView to test for FitCursor in any case!
650 cur.updateFlags(Update::FitCursor);
652 // not at paragraph end?
653 if (cur.pos() != cur.lastpos()) {
654 // in front of editable inset, i.e. jump into it?
655 if (checkAndActivateInset(cur, true))
658 TextMetrics const & tm = cur.bv().textMetrics(this);
659 // if left of boundary -> just jump to right side
660 // but for RTL boundaries don't, because: abc|DDEEFFghi -> abcDDEEF|Fghi
661 if (cur.boundary() && !tm.isRTLBoundary(cur.pit(), cur.pos()))
662 return setCursor(cur, cur.pit(), cur.pos(), true, false);
664 // next position is left of boundary,
665 // but go to next line for special cases like space, newline, linesep
667 // some effectless debug code to see the values in the debugger
668 int endpos = cur.textRow().endpos();
669 int lastpos = cur.lastpos();
671 bool linesep = cur.paragraph().isLineSeparator(cur.pos());
672 bool newline = cur.paragraph().isNewline(cur.pos());
673 bool sep = cur.paragraph().isSeparator(cur.pos());
674 if (cur.pos() != cur.lastpos()) {
675 bool linesep2 = cur.paragraph().isLineSeparator(cur.pos()+1);
676 bool newline2 = cur.paragraph().isNewline(cur.pos()+1);
677 bool sep2 = cur.paragraph().isSeparator(cur.pos()+1);
680 if (cur.textRow().endpos() == cur.pos() + 1 &&
681 cur.textRow().endpos() != cur.lastpos() &&
682 !cur.paragraph().isNewline(cur.pos()) &&
683 !cur.paragraph().isLineSeparator(cur.pos()) &&
684 !cur.paragraph().isSeparator(cur.pos())) {
685 return setCursor(cur, cur.pit(), cur.pos() + 1, true, true);
688 // in front of RTL boundary? Stay on this side of the boundary because:
689 // ab|cDDEEFFghi -> abc|DDEEFFghi
690 if (tm.isRTLBoundary(cur.pit(), cur.pos() + 1))
691 return setCursor(cur, cur.pit(), cur.pos() + 1, true, true);
694 return setCursor(cur, cur.pit(), cur.pos() + 1, true, false);
697 // move to next paragraph
698 if (cur.pit() != cur.lastpit())
699 return setCursor(cur, cur.pit() + 1, 0, true, false);
704 bool Text::cursorUpParagraph(Cursor & cur)
706 bool updated = false;
708 updated = setCursor(cur, cur.pit(), 0);
709 else if (cur.pit() != 0)
710 updated = setCursor(cur, cur.pit() - 1, 0);
715 bool Text::cursorDownParagraph(Cursor & cur)
717 bool updated = false;
718 if (cur.pit() != cur.lastpit())
719 updated = setCursor(cur, cur.pit() + 1, 0);
721 updated = setCursor(cur, cur.pit(), cur.lastpos());
726 // fix the cursor `cur' after a characters has been deleted at `where'
727 // position. Called by deleteEmptyParagraphMechanism
728 void Text::fixCursorAfterDelete(CursorSlice & cur, CursorSlice const & where)
730 // Do nothing if cursor is not in the paragraph where the
732 if (cur.pit() != where.pit())
735 // If cursor position is after the deletion place update it
736 if (cur.pos() > where.pos())
739 // Check also if we don't want to set the cursor on a spot behind the
740 // pagragraph because we erased the last character.
741 if (cur.pos() > cur.lastpos())
742 cur.pos() = cur.lastpos();
746 bool Text::deleteEmptyParagraphMechanism(Cursor & cur,
747 Cursor & old, bool & need_anchor_change)
749 //LYXERR(Debug::DEBUG) << "DEPM: cur:\n" << cur << "old:\n" << old << endl;
751 Paragraph & oldpar = old.paragraph();
753 // We allow all kinds of "mumbo-jumbo" when freespacing.
754 if (oldpar.isFreeSpacing())
757 /* Ok I'll put some comments here about what is missing.
758 There are still some small problems that can lead to
759 double spaces stored in the document file or space at
760 the beginning of paragraphs(). This happens if you have
761 the cursor between to spaces and then save. Or if you
762 cut and paste and the selection have a space at the
763 beginning and then save right after the paste. (Lgb)
766 // If old.pos() == 0 and old.pos()(1) == LineSeparator
767 // delete the LineSeparator.
770 // If old.pos() == 1 and old.pos()(0) == LineSeparator
771 // delete the LineSeparator.
774 bool const same_inset = &old.inset() == &cur.inset();
775 bool const same_par = same_inset && old.pit() == cur.pit();
776 bool const same_par_pos = same_par && old.pos() == cur.pos();
778 // If the chars around the old cursor were spaces, delete one of them.
780 // Only if the cursor has really moved.
782 && old.pos() < oldpar.size()
783 && oldpar.isLineSeparator(old.pos())
784 && oldpar.isLineSeparator(old.pos() - 1)
785 && !oldpar.isDeleted(old.pos() - 1)
786 && !oldpar.isDeleted(old.pos())) {
787 oldpar.eraseChar(old.pos() - 1, cur.buffer().params().trackChanges);
788 // FIXME: This will not work anymore when we have multiple views of the same buffer
789 // In this case, we will have to correct also the cursors held by
790 // other bufferviews. It will probably be easier to do that in a more
791 // automated way in CursorSlice code. (JMarc 26/09/2001)
792 // correct all cursor parts
794 fixCursorAfterDelete(cur.top(), old.top());
795 need_anchor_change = true;
801 // only do our magic if we changed paragraph
805 // don't delete anything if this is the ONLY paragraph!
806 if (old.lastpit() == 0)
809 // Do not delete empty paragraphs with keepempty set.
810 if (oldpar.allowEmpty())
813 if (oldpar.empty() || (oldpar.size() == 1 && oldpar.isLineSeparator(0))) {
815 old.recordUndo(ATOMIC_UNDO,
816 max(old.pit() - 1, pit_type(0)),
817 min(old.pit() + 1, old.lastpit()));
818 ParagraphList & plist = old.text()->paragraphs();
819 bool const soa = oldpar.params().startOfAppendix();
820 plist.erase(boost::next(plist.begin(), old.pit()));
821 // do not lose start of appendix marker (bug 4212)
823 plist[old.pit()].params().startOfAppendix(true);
825 // see #warning (FIXME?) above
826 if (cur.depth() >= old.depth()) {
827 CursorSlice & curslice = cur[old.depth() - 1];
828 if (&curslice.inset() == &old.inset()
829 && curslice.pit() > old.pit()) {
831 // since a paragraph has been deleted, all the
832 // insets after `old' have been copied and
833 // their address has changed. Therefore we
834 // need to `regenerate' cur. (JMarc)
835 cur.updateInsets(&(cur.bottom().inset()));
836 need_anchor_change = true;
842 if (oldpar.stripLeadingSpaces(cur.buffer().params().trackChanges)) {
843 need_anchor_change = true;
844 // We return true here because the Paragraph contents changed and
845 // we need a redraw before further action is processed.
853 void Text::deleteEmptyParagraphMechanism(pit_type first, pit_type last, bool trackChanges)
855 BOOST_ASSERT(first >= 0 && first <= last && last < (int) pars_.size());
857 for (pit_type pit = first; pit <= last; ++pit) {
858 Paragraph & par = pars_[pit];
860 // We allow all kinds of "mumbo-jumbo" when freespacing.
861 if (par.isFreeSpacing())
864 for (pos_type pos = 1; pos < par.size(); ++pos) {
865 if (par.isLineSeparator(pos) && par.isLineSeparator(pos - 1)
866 && !par.isDeleted(pos - 1)) {
867 if (par.eraseChar(pos - 1, trackChanges)) {
873 // don't delete anything if this is the only remaining paragraph within the given range
874 // note: Text::acceptOrRejectChanges() sets the cursor to 'first' after calling DEPM
878 // don't delete empty paragraphs with keepempty set
879 if (par.allowEmpty())
882 if (par.empty() || (par.size() == 1 && par.isLineSeparator(0))) {
883 pars_.erase(boost::next(pars_.begin(), pit));
889 par.stripLeadingSpaces(trackChanges);
894 void Text::recUndo(Cursor & cur, pit_type first, pit_type last) const
896 cur.recordUndo(ATOMIC_UNDO, first, last);
900 void Text::recUndo(Cursor & cur, pit_type par) const
902 cur.recordUndo(ATOMIC_UNDO, par, par);