2 * \file CutAndPaste.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Lars Gullik Bjønnes
8 * \author Alfredo Braunstein
11 * Full author contact details are available in file CREDITS.
16 #include "CutAndPaste.h"
19 #include "buffer_funcs.h"
20 #include "BufferParams.h"
21 #include "BufferView.h"
24 #include "ErrorList.h"
25 #include "FuncRequest.h"
27 #include "InsetIterator.h"
33 #include "TextClass_ptr.h"
34 #include "TextClassList.h"
35 #include "Paragraph.h"
36 #include "paragraph_funcs.h"
37 #include "ParagraphParameters.h"
38 #include "ParIterator.h"
41 #include "insets/InsetCharStyle.h"
42 #include "insets/InsetTabular.h"
44 #include "mathed/MathData.h"
45 #include "mathed/InsetMath.h"
46 #include "mathed/MathSupport.h"
48 #include "support/lstrings.h"
50 #include "frontends/Clipboard.h"
51 #include "frontends/Selection.h"
53 #include <boost/current_function.hpp>
54 #include <boost/tuple/tuple.hpp>
68 using support::bformat;
69 using frontend::Clipboard;
73 typedef std::pair<pit_type, int> PitPosPair;
75 typedef limited_stack<pair<ParagraphList, TextClass_ptr> > CutStack;
78 // persistent selection, cleared until the next selection
79 CutStack selectionBuffer(1);
81 // store whether the tabular stack is newer than the normal copy stack
82 // FIXME: this is a workaround for bug 1919. Should be removed for 1.5,
83 // when we (hopefully) have a one-for-all paste mechanism.
84 bool dirty_tabular_stack_ = false;
87 void region(CursorSlice const & i1, CursorSlice const & i2,
88 Inset::row_type & r1, Inset::row_type & r2,
89 Inset::col_type & c1, Inset::col_type & c2)
91 Inset & p = i1.inset();
103 bool checkPastePossible(int index)
105 return size_t(index) < theCuts.size() && !theCuts[index].first.empty();
109 pair<PitPosPair, pit_type>
110 pasteSelectionHelper(Cursor & cur, ParagraphList const & parlist,
111 TextClass_ptr textclass, ErrorList & errorlist)
113 Buffer const & buffer = cur.buffer();
114 pit_type pit = cur.pit();
115 pos_type pos = cur.pos();
116 ParagraphList & pars = cur.text()->paragraphs();
119 return make_pair(PitPosPair(pit, pos), pit);
121 BOOST_ASSERT (pos <= pars[pit].size());
123 // Make a copy of the CaP paragraphs.
124 ParagraphList insertion = parlist;
125 TextClass_ptr const tc = buffer.params().getTextClass_ptr();
127 // Now remove all out of the pars which is NOT allowed in the
128 // new environment and set also another font if that is required.
130 // Convert newline to paragraph break in ERT inset.
131 // This should not be here!
132 if (pars[pit].inInset() &&
133 (pars[pit].inInset()->lyxCode() == Inset::ERT_CODE ||
134 pars[pit].inInset()->lyxCode() == Inset::LISTINGS_CODE)) {
135 for (ParagraphList::size_type i = 0; i < insertion.size(); ++i) {
136 for (pos_type j = 0; j < insertion[i].size(); ++j) {
137 if (insertion[i].isNewline(j)) {
138 // do not track deletion of newline
139 insertion[i].eraseChar(j, false);
140 breakParagraphConservative(
148 // If we are in an inset which returns forceDefaultParagraphs,
149 // set the paragraphs to default
150 if (cur.inset().forceDefaultParagraphs(cur.idx())) {
151 LayoutPtr const layout =
152 buffer.params().getTextClass().defaultLayout();
153 ParagraphList::iterator const end = insertion.end();
154 for (ParagraphList::iterator par = insertion.begin();
159 // Make sure there is no class difference.
161 // This works without copying any paragraph data because we have
162 // a specialized swap method for ParagraphList. This is important
163 // since we store pointers to insets at some places and we don't
164 // want to invalidate them.
165 insertion.swap(in.paragraphs());
166 cap::switchBetweenClasses(textclass, tc, in, errorlist);
167 insertion.swap(in.paragraphs());
169 ParagraphList::iterator tmpbuf = insertion.begin();
170 int depth_delta = pars[pit].params().depth() - tmpbuf->params().depth();
172 depth_type max_depth = pars[pit].getMaxDepthAfter();
174 for (; tmpbuf != insertion.end(); ++tmpbuf) {
175 // If we have a negative jump so that the depth would
176 // go below 0 depth then we have to redo the delta to
177 // this new max depth level so that subsequent
178 // paragraphs are aligned correctly to this paragraph
180 if (int(tmpbuf->params().depth()) + depth_delta < 0)
183 // Set the right depth so that we are not too deep or shallow.
184 tmpbuf->params().depth(tmpbuf->params().depth() + depth_delta);
185 if (tmpbuf->params().depth() > max_depth)
186 tmpbuf->params().depth(max_depth);
188 // Only set this from the 2nd on as the 2nd depends
189 // for maxDepth still on pit.
190 if (tmpbuf != insertion.begin())
191 max_depth = tmpbuf->getMaxDepthAfter();
193 // Set the inset owner of this paragraph.
194 tmpbuf->setInsetOwner(pars[pit].inInset());
195 for (pos_type i = 0; i < tmpbuf->size(); ++i) {
196 if (tmpbuf->getChar(i) == Paragraph::META_INSET &&
197 !pars[pit].insetAllowed(tmpbuf->getInset(i)->lyxCode()))
198 // do not track deletion of invalid insets
199 tmpbuf->eraseChar(i--, false);
202 tmpbuf->setChange(Change(buffer.params().trackChanges ?
203 Change::INSERTED : Change::UNCHANGED));
206 bool const empty = pars[pit].empty();
208 // Make the buf exactly the same layout as the cursor
210 insertion.begin()->makeSameLayout(pars[pit]);
213 // Prepare the paragraphs and insets for insertion.
214 // A couple of insets store buffer references so need updating.
215 insertion.swap(in.paragraphs());
217 ParIterator fpit = par_iterator_begin(in);
218 ParIterator fend = par_iterator_end(in);
220 for (; fpit != fend; ++fpit) {
221 InsetList::const_iterator lit = fpit->insetlist.begin();
222 InsetList::const_iterator eit = fpit->insetlist.end();
224 for (; lit != eit; ++lit) {
225 switch (lit->inset->lyxCode()) {
226 case Inset::TABULAR_CODE: {
227 InsetTabular * it = static_cast<InsetTabular*>(lit->inset);
237 insertion.swap(in.paragraphs());
239 // Split the paragraph for inserting the buf if necessary.
241 breakParagraphConservative(buffer.params(), pars, pit, pos);
245 pars.insert(boost::next(pars.begin(), pit),
249 // merge the empty par with the last par of the insertion
250 mergeParagraph(buffer.params(), pars,
251 pit + insertion.size() - 1);
253 pars.insert(boost::next(pars.begin(), pit + 1),
257 // merge the first par of the insertion with the current par
258 mergeParagraph(buffer.params(), pars, pit);
261 pit_type last_paste = pit + insertion.size() - 1;
263 // Store the new cursor position.
265 pos = pars[last_paste].size();
267 // Join (conditionally) last pasted paragraph with next one, i.e.,
268 // the tail of the spliced document paragraph
269 if (!empty && last_paste + 1 != pit_type(pars.size())) {
270 if (pars[last_paste + 1].hasSameLayout(pars[last_paste])) {
271 mergeParagraph(buffer.params(), pars, last_paste);
272 } else if (pars[last_paste + 1].empty()) {
273 pars[last_paste + 1].makeSameLayout(pars[last_paste]);
274 mergeParagraph(buffer.params(), pars, last_paste);
275 } else if (pars[last_paste].empty()) {
276 pars[last_paste].makeSameLayout(pars[last_paste + 1]);
277 mergeParagraph(buffer.params(), pars, last_paste);
279 pars[last_paste + 1].stripLeadingSpaces(buffer.params().trackChanges);
284 return make_pair(PitPosPair(pit, pos), last_paste + 1);
288 PitPosPair eraseSelectionHelper(BufferParams const & params,
289 ParagraphList & pars,
290 pit_type startpit, pit_type endpit,
291 int startpos, int endpos, bool doclear)
293 // Start of selection is really invalid.
294 if (startpit == pit_type(pars.size()) ||
295 (startpos > pars[startpit].size()))
296 return PitPosPair(endpit, endpos);
298 // Start and end is inside same paragraph
299 if (endpit == pit_type(pars.size()) || startpit == endpit) {
300 endpos -= pars[startpit].eraseChars(startpos, endpos, params.trackChanges);
301 return PitPosPair(endpit, endpos);
304 for (pit_type pit = startpit; pit != endpit + 1;) {
305 pos_type const left = (pit == startpit ? startpos : 0);
306 pos_type right = (pit == endpit ? endpos : pars[pit].size() + 1);
307 // FIXME: this is a quick fix for bug 3600. It stops a crash but the problem
308 // still remains unsolved (e.g. the second example in the bug report).
309 // c.f. http://bugzilla.lyx.org/show_bug.cgi?id=3600
310 if (right > pars[pit].size() + 1)
311 right = pars[pit].size() + 1;
313 bool const merge = pars[pit].isMergedOnEndOfParDeletion(params.trackChanges);
315 // Logically erase only, including the end-of-paragraph character
316 pars[pit].eraseChars(left, right, params.trackChanges);
318 // Separate handling of paragraph break:
319 if (merge && pit != endpit &&
320 (pit + 1 != endpit || pars[pit].hasSameLayout(pars[pit + 1]))) {
321 pos_type const thissize = pars[pit].size();
323 pars[pit + 1].stripLeadingSpaces(params.trackChanges);
324 mergeParagraph(params, pars, pit);
332 // Ensure legal cursor pos:
335 return PitPosPair(endpit, endpos);
339 void putClipboard(ParagraphList const & paragraphs, TextClass_ptr textclass,
340 docstring const & plaintext)
342 // For some strange reason gcc 3.2 and 3.3 do not accept
343 // Buffer buffer(string(), false);
344 Buffer buffer("", false);
345 buffer.setUnnamed(true);
346 buffer.paragraphs() = paragraphs;
347 buffer.params().setTextClass(textclass);
348 std::ostringstream lyx;
349 if (buffer.write(lyx))
350 theClipboard().put(lyx.str(), plaintext);
352 theClipboard().put(string(), plaintext);
356 void copySelectionHelper(Buffer const & buf, ParagraphList & pars,
357 pit_type startpit, pit_type endpit,
358 int start, int end, TextClass_ptr tc, CutStack & cutstack)
360 BOOST_ASSERT(0 <= start && start <= pars[startpit].size());
361 BOOST_ASSERT(0 <= end && end <= pars[endpit].size());
362 BOOST_ASSERT(startpit != endpit || start <= end);
364 // Clone the paragraphs within the selection.
365 ParagraphList copy_pars(boost::next(pars.begin(), startpit),
366 boost::next(pars.begin(), endpit + 1));
368 // Remove the end of the last paragraph; afterwards, remove the
369 // beginning of the first paragraph. Keep this order - there may only
370 // be one paragraph! Do not track deletions here; this is an internal
371 // action not visible to the user
373 Paragraph & back = copy_pars.back();
374 back.eraseChars(end, back.size(), false);
375 Paragraph & front = copy_pars.front();
376 front.eraseChars(0, start, false);
378 ParagraphList::iterator it = copy_pars.begin();
379 ParagraphList::iterator it_end = copy_pars.end();
381 for (; it != it_end; it++) {
382 // ERT paragraphs have the Language latex_language.
383 // This is invalid outside of ERT, so we need to change it
384 // to the buffer language.
385 if (it->ownerCode() == Inset::ERT_CODE || it->ownerCode() == Inset::LISTINGS_CODE) {
386 it->changeLanguage(buf.params(), latex_language,
389 it->setInsetOwner(0);
392 // do not copy text (also nested in insets) which is marked as deleted
393 acceptChanges(copy_pars, buf.params());
395 cutstack.push(make_pair(copy_pars, tc));
405 docstring grabAndEraseSelection(Cursor & cur)
407 if (!cur.selection())
409 docstring res = grabSelection(cur);
415 void switchBetweenClasses(TextClass_ptr const & c1,
416 TextClass_ptr const & c2, InsetText & in, ErrorList & errorlist)
420 BOOST_ASSERT(!in.paragraphs().empty());
424 TextClass const & tclass1 = *c1;
425 TextClass const & tclass2 = *c2;
428 ParIterator end = par_iterator_end(in);
429 for (ParIterator it = par_iterator_begin(in); it != end; ++it) {
430 docstring const name = it->layout()->name();
431 bool hasLayout = tclass2.hasLayout(name);
434 it->layout(tclass2[name]);
436 it->layout(tclass2.defaultLayout());
438 if (!hasLayout && name != tclass1.defaultLayoutName()) {
439 docstring const s = bformat(
440 _("Layout had to be changed from\n%1$s to %2$s\n"
441 "because of class conversion from\n%3$s to %4$s"),
442 name, it->layout()->name(),
443 from_utf8(tclass1.name()), from_utf8(tclass2.name()));
444 // To warn the user that something had to be done.
445 errorlist.push_back(ErrorItem(_("Changed Layout"), s,
452 InsetIterator const i_end = inset_iterator_end(in);
453 for (InsetIterator it = inset_iterator_begin(in); it != i_end; ++it) {
454 if (it->lyxCode() == Inset::CHARSTYLE_CODE) {
455 InsetCharStyle & inset =
456 static_cast<InsetCharStyle &>(*it);
457 string const name = inset.params().name;
458 InsetLayout const il =
459 tclass2.insetlayout(from_utf8(name));
461 if (il.labelstring == from_utf8("UNDEFINED")) {
462 // The character style is undefined in tclass2
463 docstring const s = bformat(_(
464 "Character style %1$s is "
465 "undefined because of class "
466 "conversion from\n%2$s to %3$s"),
467 from_utf8(name), from_utf8(tclass1.name()),
468 from_utf8(tclass2.name()));
469 // To warn the user that something had to be done.
470 errorlist.push_back(ErrorItem(
471 _("Undefined character style"),
472 s, it.paragraph().id(), it.pos(), it.pos() + 1));
479 std::vector<docstring> const availableSelections(Buffer const & buffer)
481 vector<docstring> selList;
483 CutStack::const_iterator cit = theCuts.begin();
484 CutStack::const_iterator end = theCuts.end();
485 for (; cit != end; ++cit) {
486 // we do not use cit-> here because gcc 2.9x does not
488 ParagraphList const & pars = (*cit).first;
490 ParagraphList::const_iterator pit = pars.begin();
491 ParagraphList::const_iterator pend = pars.end();
492 for (; pit != pend; ++pit) {
493 asciiSel += pit->asString(buffer, false);
494 if (asciiSel.size() > 25) {
495 asciiSel.replace(22, docstring::npos,
501 selList.push_back(asciiSel);
508 size_type numberOfSelections()
510 return theCuts.size();
514 void cutSelection(Cursor & cur, bool doclear, bool realcut)
516 // This doesn't make sense, if there is no selection
517 if (!cur.selection())
520 // OK, we have a selection. This is always between cur.selBegin()
523 if (cur.inTexted()) {
524 Text * text = cur.text();
529 // make sure that the depth behind the selection are restored, too
530 recordUndoSelection(cur);
531 pit_type begpit = cur.selBegin().pit();
532 pit_type endpit = cur.selEnd().pit();
534 int endpos = cur.selEnd().pos();
536 BufferParams const & bp = cur.buffer().params();
538 copySelectionHelper(cur.buffer(),
541 cur.selBegin().pos(), endpos,
542 bp.getTextClass_ptr(), theCuts);
543 // Stuff what we got on the clipboard.
544 // Even if there is no selection.
545 putClipboard(theCuts[0].first, theCuts[0].second,
546 cur.selectionAsString(true));
549 boost::tie(endpit, endpos) =
550 eraseSelectionHelper(bp,
553 cur.selBegin().pos(), endpos,
556 // cutSelection can invalidate the cursor so we need to set
558 // we prefer the end for when tracking changes
562 // sometimes necessary
564 && text->paragraphs()[begpit].stripLeadingSpaces(bp.trackChanges))
567 // need a valid cursor. (Lgb)
568 cur.clearSelection();
569 updateLabels(cur.buffer());
571 // tell tabular that a recent copy happened
572 dirtyTabularStack(false);
575 if (cur.inMathed()) {
576 if (cur.selBegin().idx() != cur.selEnd().idx()) {
577 // The current selection spans more than one cell.
579 recordUndoInset(cur);
581 // Record only the current cell to avoid a jumping
592 void copySelection(Cursor & cur)
594 copySelection(cur, cur.selectionAsString(true));
600 void copySelectionToStack(Cursor & cur, CutStack & cutstack)
602 // this doesn't make sense, if there is no selection
603 if (!cur.selection())
606 // copySelection can not yet handle the case of cross idx selection
607 if (cur.selBegin().idx() != cur.selEnd().idx())
610 if (cur.inTexted()) {
611 Text * text = cur.text();
613 // ok we have a selection. This is always between cur.selBegin()
614 // and sel_end cursor
616 // copy behind a space if there is one
617 ParagraphList & pars = text->paragraphs();
618 pos_type pos = cur.selBegin().pos();
619 pit_type par = cur.selBegin().pit();
620 while (pos < pars[par].size() &&
621 pars[par].isLineSeparator(pos) &&
622 (par != cur.selEnd().pit() || pos < cur.selEnd().pos()))
625 copySelectionHelper(cur.buffer(), pars, par, cur.selEnd().pit(),
626 pos, cur.selEnd().pos(),
627 cur.buffer().params().getTextClass_ptr(), cutstack);
628 dirtyTabularStack(false);
631 if (cur.inMathed()) {
632 //lyxerr << "copySelection in mathed" << endl;
635 BufferParams const & bp = cur.buffer().params();
636 par.layout(bp.getTextClass().defaultLayout());
637 par.insert(0, grabSelection(cur), Font(), Change(Change::UNCHANGED));
639 cutstack.push(make_pair(pars, bp.getTextClass_ptr()));
646 void copySelectionToStack()
648 if (!selectionBuffer.empty())
649 theCuts.push(selectionBuffer[0]);
653 void copySelection(Cursor & cur, docstring const & plaintext)
655 // In tablemode, because copy and paste actually use special table stack
656 // we do not attemp to get selected paragraphs under cursor. Instead, a
657 // paragraph with the plain text version is generated so that table cells
658 // can be pasted as pure text somewhere else.
659 if (cur.selBegin().idx() != cur.selEnd().idx()) {
662 BufferParams const & bp = cur.buffer().params();
663 par.layout(bp.getTextClass().defaultLayout());
664 par.insert(0, plaintext, Font(), Change(Change::UNCHANGED));
666 theCuts.push(make_pair(pars, bp.getTextClass_ptr()));
668 copySelectionToStack(cur, theCuts);
670 // stuff the selection onto the X clipboard, from an explicit copy request
671 putClipboard(theCuts[0].first, theCuts[0].second, plaintext);
675 void saveSelection(Cursor & cur)
677 // This function is called, not when a selection is formed, but when
678 // a selection is cleared. Therefore, multiple keyboard selection
679 // will not repeatively trigger this function (bug 3877).
681 && cur.selBegin() == cur.bv().cursor().selBegin()
682 && cur.selEnd() == cur.bv().cursor().selEnd()) {
683 LYXERR(Debug::ACTION) << BOOST_CURRENT_FUNCTION << ": `"
684 << to_utf8(cur.selectionAsString(true)) << "'."
686 copySelectionToStack(cur, selectionBuffer);
693 return !selectionBuffer.empty();
697 void clearSelection()
699 selectionBuffer.clear();
703 docstring getSelection(Buffer const & buf, size_t sel_index)
705 return sel_index < theCuts.size()
706 ? theCuts[sel_index].first.back().asString(buf, false)
711 void pasteParagraphList(Cursor & cur, ParagraphList const & parlist,
712 TextClass_ptr textclass, ErrorList & errorList)
714 if (cur.inTexted()) {
715 Text * text = cur.text();
721 boost::tie(ppp, endpit) =
722 pasteSelectionHelper(cur, parlist,
723 textclass, errorList);
724 updateLabels(cur.buffer());
725 cur.clearSelection();
726 text->setCursor(cur, ppp.first, ppp.second);
729 // mathed is handled in InsetMathNest/InsetMathGrid
730 BOOST_ASSERT(!cur.inMathed());
734 void pasteFromStack(Cursor & cur, ErrorList & errorList, size_t sel_index)
736 // this does not make sense, if there is nothing to paste
737 if (!checkPastePossible(sel_index))
741 pasteParagraphList(cur, theCuts[sel_index].first,
742 theCuts[sel_index].second, errorList);
747 void pasteClipboard(Cursor & cur, ErrorList & errorList, bool asParagraphs)
749 // Use internal clipboard if it is the most recent one
750 if (theClipboard().isInternal()) {
751 pasteFromStack(cur, errorList, 0);
755 // First try LyX format
756 if (theClipboard().hasLyXContents()) {
757 string lyx = theClipboard().getAsLyX();
759 // For some strange reason gcc 3.2 and 3.3 do not accept
760 // Buffer buffer(string(), false);
761 Buffer buffer("", false);
762 buffer.setUnnamed(true);
763 if (buffer.readString(lyx)) {
765 pasteParagraphList(cur, buffer.paragraphs(),
766 buffer.params().getTextClass_ptr(), errorList);
773 // Then try plain text
774 docstring const text = theClipboard().getAsText();
779 cur.text()->insertStringAsParagraphs(cur, text);
781 cur.text()->insertStringAsLines(cur, text);
785 void pasteSelection(Cursor & cur, ErrorList & errorList)
787 if (selectionBuffer.empty())
790 pasteParagraphList(cur, selectionBuffer[0].first,
791 selectionBuffer[0].second, errorList);
795 void replaceSelectionWithString(Cursor & cur, docstring const & str, bool backwards)
798 DocIterator selbeg = cur.selectionBegin();
800 // Get font setting before we cut
802 selbeg.paragraph().getFontSettings(cur.buffer().params(), selbeg.pos());
804 // Insert the new string
805 pos_type pos = cur.selEnd().pos();
806 Paragraph & par = cur.selEnd().paragraph();
807 docstring::const_iterator cit = str.begin();
808 docstring::const_iterator end = str.end();
809 for (; cit != end; ++cit, ++pos)
810 par.insertChar(pos, *cit, font, cur.buffer().params().trackChanges);
813 cutSelection(cur, true, false);
815 // select the replacement
817 selbeg.pos() += str.length();
818 cur.setSelection(selbeg, -int(str.length()));
820 cur.setSelection(selbeg, str.length());
824 void replaceSelection(Cursor & cur)
827 cutSelection(cur, true, false);
831 void eraseSelection(Cursor & cur)
833 //lyxerr << "cap::eraseSelection begin: " << cur << endl;
834 CursorSlice const & i1 = cur.selBegin();
835 CursorSlice const & i2 = cur.selEnd();
836 if (i1.inset().asInsetMath()) {
839 if (i1.idx() == i2.idx()) {
840 i1.cell().erase(i1.pos(), i2.pos());
841 // We may have deleted i1.cell(cur.pos()).
842 // Make sure that pos is valid.
843 if (cur.pos() > cur.lastpos())
844 cur.pos() = cur.lastpos();
846 InsetMath * p = i1.asInsetMath();
847 Inset::row_type r1, r2;
848 Inset::col_type c1, c2;
849 region(i1, i2, r1, r2, c1, c2);
850 for (Inset::row_type row = r1; row <= r2; ++row)
851 for (Inset::col_type col = c1; col <= c2; ++col)
852 p->cell(p->index(row, col)).clear();
853 // We've deleted the whole cell. Only pos 0 is valid.
856 // need a valid cursor. (Lgb)
857 cur.clearSelection();
859 lyxerr << "can't erase this selection 1" << endl;
861 //lyxerr << "cap::eraseSelection end: " << cur << endl;
865 void selDel(Cursor & cur)
867 //lyxerr << "cap::selDel" << endl;
873 void selClearOrDel(Cursor & cur)
875 //lyxerr << "cap::selClearOrDel" << endl;
876 if (lyxrc.auto_region_delete)
879 cur.selection() = false;
883 docstring grabSelection(Cursor const & cur)
885 if (!cur.selection())
888 // FIXME: What is wrong with the following?
890 std::ostringstream os;
891 for (DocIterator dit = cur.selectionBegin();
892 dit != cur.selectionEnd(); dit.forwardPos())
893 os << asString(dit.cell());
897 CursorSlice i1 = cur.selBegin();
898 CursorSlice i2 = cur.selEnd();
900 if (i1.idx() == i2.idx()) {
901 if (i1.inset().asInsetMath()) {
902 MathData::const_iterator it = i1.cell().begin();
903 return asString(MathData(it + i1.pos(), it + i2.pos()));
905 return from_ascii("unknown selection 1");
909 Inset::row_type r1, r2;
910 Inset::col_type c1, c2;
911 region(i1, i2, r1, r2, c1, c2);
914 if (i1.inset().asInsetMath()) {
915 for (Inset::row_type row = r1; row <= r2; ++row) {
918 for (Inset::col_type col = c1; col <= c2; ++col) {
921 data += asString(i1.asInsetMath()->
922 cell(i1.asInsetMath()->index(row, col)));
926 data = from_ascii("unknown selection 2");
932 void dirtyTabularStack(bool b)
934 dirty_tabular_stack_ = b;
938 bool tabularStackDirty()
940 return dirty_tabular_stack_;