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"
26 #include "InsetIterator.h"
27 #include "InsetList.h"
33 #include "TextClassList.h"
34 #include "Paragraph.h"
35 #include "paragraph_funcs.h"
36 #include "ParagraphParameters.h"
37 #include "ParIterator.h"
40 #include "insets/InsetFlex.h"
41 #include "insets/InsetGraphics.h"
42 #include "insets/InsetGraphicsParams.h"
43 #include "insets/InsetTabular.h"
45 #include "mathed/MathData.h"
46 #include "mathed/InsetMath.h"
47 #include "mathed/MathSupport.h"
49 #include "support/debug.h"
50 #include "support/docstream.h"
51 #include "support/gettext.h"
52 #include "support/limited_stack.h"
53 #include "support/lstrings.h"
55 #include "frontends/Clipboard.h"
56 #include "frontends/Selection.h"
58 #include <boost/tuple/tuple.hpp>
59 #include <boost/next_prior.hpp>
64 using namespace lyx::support;
65 using lyx::frontend::Clipboard;
71 typedef pair<pit_type, int> PitPosPair;
73 typedef limited_stack<pair<ParagraphList, TextClassPtr> > CutStack;
76 // persistent selection, cleared until the next selection
77 CutStack selectionBuffer(1);
79 // store whether the tabular stack is newer than the normal copy stack
80 // FIXME: this is a workaround for bug 1919. Should be removed for 1.5,
81 // when we (hopefully) have a one-for-all paste mechanism.
82 bool dirty_tabular_stack_ = false;
85 void region(CursorSlice const & i1, CursorSlice const & i2,
86 Inset::row_type & r1, Inset::row_type & r2,
87 Inset::col_type & c1, Inset::col_type & c2)
89 Inset & p = i1.inset();
101 bool checkPastePossible(int index)
103 return size_t(index) < theCuts.size() && !theCuts[index].first.empty();
107 pair<PitPosPair, pit_type>
108 pasteSelectionHelper(Cursor & cur, ParagraphList const & parlist,
109 TextClassPtr textclass, ErrorList & errorlist)
111 Buffer const & buffer = cur.buffer();
112 pit_type pit = cur.pit();
113 pos_type pos = cur.pos();
114 ParagraphList & pars = cur.text()->paragraphs();
117 return make_pair(PitPosPair(pit, pos), pit);
119 BOOST_ASSERT (pos <= pars[pit].size());
121 // Make a copy of the CaP paragraphs.
122 ParagraphList insertion = parlist;
123 TextClassPtr const tc = buffer.params().getTextClassPtr();
125 // Now remove all out of the pars which is NOT allowed in the
126 // new environment and set also another font if that is required.
128 // Convert newline to paragraph break in ERT inset.
129 // This should not be here!
130 Inset * inset = pars[pit].inInset();
131 if (inset && (inset->lyxCode() == ERT_CODE ||
132 inset->lyxCode() == LISTINGS_CODE)) {
133 for (size_t i = 0; i != insertion.size(); ++i) {
134 for (pos_type j = 0; j != insertion[i].size(); ++j) {
135 if (insertion[i].isNewline(j)) {
136 // do not track deletion of newline
137 insertion[i].eraseChar(j, false);
138 breakParagraphConservative(
146 // set the paragraphs to empty layout if necessary
147 // note that we are doing this if the empty layout is
148 // supposed to be the default, not just if it is forced
149 if (cur.inset().useEmptyLayout()) {
150 LayoutPtr const layout =
151 buffer.params().getTextClass().emptyLayout();
152 ParagraphList::iterator const end = insertion.end();
153 for (ParagraphList::iterator par = insertion.begin();
155 par->setLayout(layout);
158 // Make sure there is no class difference.
160 // This works without copying any paragraph data because we have
161 // a specialized swap method for ParagraphList. This is important
162 // since we store pointers to insets at some places and we don't
163 // want to invalidate them.
164 insertion.swap(in.paragraphs());
165 cap::switchBetweenClasses(textclass, tc, in, errorlist);
166 insertion.swap(in.paragraphs());
168 ParagraphList::iterator tmpbuf = insertion.begin();
169 int depth_delta = pars[pit].params().depth() - tmpbuf->params().depth();
171 depth_type max_depth = pars[pit].getMaxDepthAfter();
173 for (; tmpbuf != insertion.end(); ++tmpbuf) {
174 // If we have a negative jump so that the depth would
175 // go below 0 depth then we have to redo the delta to
176 // this new max depth level so that subsequent
177 // paragraphs are aligned correctly to this paragraph
179 if (int(tmpbuf->params().depth()) + depth_delta < 0)
182 // Set the right depth so that we are not too deep or shallow.
183 tmpbuf->params().depth(tmpbuf->params().depth() + depth_delta);
184 if (tmpbuf->params().depth() > max_depth)
185 tmpbuf->params().depth(max_depth);
187 // Only set this from the 2nd on as the 2nd depends
188 // for maxDepth still on pit.
189 if (tmpbuf != insertion.begin())
190 max_depth = tmpbuf->getMaxDepthAfter();
192 // Set the inset owner of this paragraph.
193 tmpbuf->setInsetOwner(pars[pit].inInset());
194 for (pos_type i = 0; i < tmpbuf->size(); ++i) {
195 // do not track deletion of invalid insets
196 if (Inset * inset = tmpbuf->getInset(i))
197 if (!pars[pit].insetAllowed(inset->lyxCode()))
198 tmpbuf->eraseChar(i--, false);
201 tmpbuf->setChange(Change(buffer.params().trackChanges ?
202 Change::INSERTED : Change::UNCHANGED));
205 bool const empty = pars[pit].empty();
207 // Make the buf exactly the same layout as the cursor
209 insertion.begin()->makeSameLayout(pars[pit]);
212 // Prepare the paragraphs and insets for insertion.
213 // A couple of insets store buffer references so need updating.
214 insertion.swap(in.paragraphs());
216 ParIterator fpit = par_iterator_begin(in);
217 ParIterator fend = par_iterator_end(in);
219 for (; fpit != fend; ++fpit) {
220 InsetList::const_iterator it = fpit->insetList().begin();
221 InsetList::const_iterator et = fpit->insetList().end();
222 for (; it != et; ++it)
223 it->inset->setBuffer(const_cast<Buffer *>(&buffer));
225 insertion.swap(in.paragraphs());
227 // Split the paragraph for inserting the buf if necessary.
229 breakParagraphConservative(buffer.params(), pars, pit, pos);
233 pars.insert(boost::next(pars.begin(), pit),
237 // merge the empty par with the last par of the insertion
238 mergeParagraph(buffer.params(), pars,
239 pit + insertion.size() - 1);
241 pars.insert(boost::next(pars.begin(), pit + 1),
245 // merge the first par of the insertion with the current par
246 mergeParagraph(buffer.params(), pars, pit);
249 pit_type last_paste = pit + insertion.size() - 1;
251 // Store the new cursor position.
253 pos = pars[last_paste].size();
255 // Join (conditionally) last pasted paragraph with next one, i.e.,
256 // the tail of the spliced document paragraph
257 if (!empty && last_paste + 1 != pit_type(pars.size())) {
258 if (pars[last_paste + 1].hasSameLayout(pars[last_paste])) {
259 mergeParagraph(buffer.params(), pars, last_paste);
260 } else if (pars[last_paste + 1].empty()) {
261 pars[last_paste + 1].makeSameLayout(pars[last_paste]);
262 mergeParagraph(buffer.params(), pars, last_paste);
263 } else if (pars[last_paste].empty()) {
264 pars[last_paste].makeSameLayout(pars[last_paste + 1]);
265 mergeParagraph(buffer.params(), pars, last_paste);
267 pars[last_paste + 1].stripLeadingSpaces(buffer.params().trackChanges);
272 return make_pair(PitPosPair(pit, pos), last_paste + 1);
276 PitPosPair eraseSelectionHelper(BufferParams const & params,
277 ParagraphList & pars,
278 pit_type startpit, pit_type endpit,
279 int startpos, int endpos)
281 // Start of selection is really invalid.
282 if (startpit == pit_type(pars.size()) ||
283 (startpos > pars[startpit].size()))
284 return PitPosPair(endpit, endpos);
286 // Start and end is inside same paragraph
287 if (endpit == pit_type(pars.size()) || startpit == endpit) {
288 endpos -= pars[startpit].eraseChars(startpos, endpos, params.trackChanges);
289 return PitPosPair(endpit, endpos);
292 for (pit_type pit = startpit; pit != endpit + 1;) {
293 pos_type const left = (pit == startpit ? startpos : 0);
294 pos_type right = (pit == endpit ? endpos : pars[pit].size() + 1);
295 bool const merge = pars[pit].isMergedOnEndOfParDeletion(params.trackChanges);
297 // Logically erase only, including the end-of-paragraph character
298 pars[pit].eraseChars(left, right, params.trackChanges);
300 // Separate handling of paragraph break:
301 if (merge && pit != endpit &&
303 || pars[pit].hasSameLayout(pars[endpit])
304 || pars[endpit].size() == endpos)) {
305 if (pit + 1 == endpit)
306 endpos += pars[pit].size();
307 mergeParagraph(params, pars, pit);
313 // Ensure legal cursor pos:
316 return PitPosPair(endpit, endpos);
320 void putClipboard(ParagraphList const & paragraphs, TextClassPtr textclass,
321 docstring const & plaintext)
323 // For some strange reason gcc 3.2 and 3.3 do not accept
324 // Buffer buffer(string(), false);
325 Buffer buffer("", false);
326 buffer.setUnnamed(true);
327 buffer.paragraphs() = paragraphs;
328 buffer.params().setTextClass(textclass);
330 if (buffer.write(lyx))
331 theClipboard().put(lyx.str(), plaintext);
333 theClipboard().put(string(), plaintext);
337 void copySelectionHelper(Buffer const & buf, ParagraphList & pars,
338 pit_type startpit, pit_type endpit,
339 int start, int end, TextClassPtr tc, CutStack & cutstack)
341 BOOST_ASSERT(0 <= start && start <= pars[startpit].size());
342 BOOST_ASSERT(0 <= end && end <= pars[endpit].size());
343 BOOST_ASSERT(startpit != endpit || start <= end);
345 // Clone the paragraphs within the selection.
346 ParagraphList copy_pars(boost::next(pars.begin(), startpit),
347 boost::next(pars.begin(), endpit + 1));
349 // Remove the end of the last paragraph; afterwards, remove the
350 // beginning of the first paragraph. Keep this order - there may only
351 // be one paragraph! Do not track deletions here; this is an internal
352 // action not visible to the user
354 Paragraph & back = copy_pars.back();
355 back.eraseChars(end, back.size(), false);
356 Paragraph & front = copy_pars.front();
357 front.eraseChars(0, start, false);
359 ParagraphList::iterator it = copy_pars.begin();
360 ParagraphList::iterator it_end = copy_pars.end();
362 for (; it != it_end; it++) {
363 // ERT paragraphs have the Language latex_language.
364 // This is invalid outside of ERT, so we need to change it
365 // to the buffer language.
366 if (it->ownerCode() == ERT_CODE || it->ownerCode() == LISTINGS_CODE) {
367 it->changeLanguage(buf.params(), latex_language, buf.language());
369 it->setInsetOwner(0);
372 // do not copy text (also nested in insets) which is marked as deleted
373 acceptChanges(copy_pars, buf.params());
375 cutstack.push(make_pair(copy_pars, tc));
385 docstring grabAndEraseSelection(Cursor & cur)
387 if (!cur.selection())
389 docstring res = grabSelection(cur);
395 void switchBetweenClasses(TextClassPtr const & oldone,
396 TextClassPtr const & newone, InsetText & in, ErrorList & errorlist)
400 BOOST_ASSERT(!in.paragraphs().empty());
401 if (oldone == newone)
404 TextClass const & oldtc = *oldone;
405 TextClass const & newtc = *newone;
408 ParIterator end = par_iterator_end(in);
409 for (ParIterator it = par_iterator_begin(in); it != end; ++it) {
410 docstring const name = it->layout()->name();
411 bool hasLayout = newtc.hasLayout(name);
414 it->setLayout(newtc[name]);
416 it->setLayout(newtc.defaultLayout());
418 if (!hasLayout && name != oldtc.defaultLayoutName()) {
419 docstring const s = bformat(
420 _("Layout had to be changed from\n%1$s to %2$s\n"
421 "because of class conversion from\n%3$s to %4$s"),
422 name, it->layout()->name(),
423 from_utf8(oldtc.name()), from_utf8(newtc.name()));
424 // To warn the user that something had to be done.
425 errorlist.push_back(ErrorItem(_("Changed Layout"), s,
432 InsetIterator const i_end = inset_iterator_end(in);
433 for (InsetIterator it = inset_iterator_begin(in); it != i_end; ++it) {
434 InsetCollapsable * inset = it->asInsetCollapsable();
437 if (inset->lyxCode() != FLEX_CODE)
438 // FIXME: Should we verify all InsetCollapsable?
440 inset->setLayout(newone);
441 if (!inset->undefined())
443 // The flex inset is undefined in newtc
444 docstring const s = bformat(_(
445 "Flex inset %1$s is "
446 "undefined because of class "
447 "conversion from\n%2$s to %3$s"),
448 inset->name(), from_utf8(oldtc.name()),
449 from_utf8(newtc.name()));
450 // To warn the user that something had to be done.
451 errorlist.push_back(ErrorItem(
452 _("Undefined flex inset"),
453 s, it.paragraph().id(), it.pos(), it.pos() + 1));
458 vector<docstring> const availableSelections(Buffer const & buffer)
460 vector<docstring> selList;
462 CutStack::const_iterator cit = theCuts.begin();
463 CutStack::const_iterator end = theCuts.end();
464 for (; cit != end; ++cit) {
465 // we do not use cit-> here because gcc 2.9x does not
467 ParagraphList const & pars = (*cit).first;
469 ParagraphList::const_iterator pit = pars.begin();
470 ParagraphList::const_iterator pend = pars.end();
471 for (; pit != pend; ++pit) {
472 asciiSel += pit->asString(buffer, false);
473 if (asciiSel.size() > 25) {
474 asciiSel.replace(22, docstring::npos,
480 selList.push_back(asciiSel);
487 size_type numberOfSelections()
489 return theCuts.size();
493 void cutSelection(Cursor & cur, bool doclear, bool realcut)
495 // This doesn't make sense, if there is no selection
496 if (!cur.selection())
499 // OK, we have a selection. This is always between cur.selBegin()
502 if (cur.inTexted()) {
503 Text * text = cur.text();
508 // make sure that the depth behind the selection are restored, too
509 cur.recordUndoSelection();
510 pit_type begpit = cur.selBegin().pit();
511 pit_type endpit = cur.selEnd().pit();
513 int endpos = cur.selEnd().pos();
515 BufferParams const & bp = cur.buffer().params();
517 copySelectionHelper(cur.buffer(),
520 cur.selBegin().pos(), endpos,
521 bp.getTextClassPtr(), theCuts);
522 // Stuff what we got on the clipboard.
523 // Even if there is no selection.
524 putClipboard(theCuts[0].first, theCuts[0].second,
525 cur.selectionAsString(true));
528 boost::tie(endpit, endpos) =
529 eraseSelectionHelper(bp,
532 cur.selBegin().pos(), endpos);
534 // cutSelection can invalidate the cursor so we need to set
536 // we prefer the end for when tracking changes
540 // sometimes necessary
542 && text->paragraphs()[begpit].stripLeadingSpaces(bp.trackChanges))
545 // need a valid cursor. (Lgb)
546 cur.clearSelection();
547 updateLabels(cur.buffer());
549 // tell tabular that a recent copy happened
550 dirtyTabularStack(false);
553 if (cur.inMathed()) {
554 if (cur.selBegin().idx() != cur.selEnd().idx()) {
555 // The current selection spans more than one cell.
557 cur.recordUndoInset();
559 // Record only the current cell to avoid a jumping
570 void copySelection(Cursor & cur)
572 copySelection(cur, cur.selectionAsString(true));
578 void copySelectionToStack(Cursor & cur, CutStack & cutstack)
580 // this doesn't make sense, if there is no selection
581 if (!cur.selection())
584 // copySelection can not yet handle the case of cross idx selection
585 if (cur.selBegin().idx() != cur.selEnd().idx())
588 if (cur.inTexted()) {
589 Text * text = cur.text();
591 // ok we have a selection. This is always between cur.selBegin()
592 // and sel_end cursor
594 // copy behind a space if there is one
595 ParagraphList & pars = text->paragraphs();
596 pos_type pos = cur.selBegin().pos();
597 pit_type par = cur.selBegin().pit();
598 while (pos < pars[par].size() &&
599 pars[par].isLineSeparator(pos) &&
600 (par != cur.selEnd().pit() || pos < cur.selEnd().pos()))
603 copySelectionHelper(cur.buffer(), pars, par, cur.selEnd().pit(),
604 pos, cur.selEnd().pos(),
605 cur.buffer().params().getTextClassPtr(), cutstack);
606 dirtyTabularStack(false);
609 if (cur.inMathed()) {
610 //lyxerr << "copySelection in mathed" << endl;
613 BufferParams const & bp = cur.buffer().params();
614 par.setLayout(bp.getTextClass().defaultLayout());
615 par.insert(0, grabSelection(cur), Font(), Change(Change::UNCHANGED));
617 cutstack.push(make_pair(pars, bp.getTextClassPtr()));
624 void copySelectionToStack()
626 if (!selectionBuffer.empty())
627 theCuts.push(selectionBuffer[0]);
631 void copySelection(Cursor & cur, docstring const & plaintext)
633 // In tablemode, because copy and paste actually use special table stack
634 // we do not attempt to get selected paragraphs under cursor. Instead, a
635 // paragraph with the plain text version is generated so that table cells
636 // can be pasted as pure text somewhere else.
637 if (cur.selBegin().idx() != cur.selEnd().idx()) {
640 BufferParams const & bp = cur.buffer().params();
641 par.setLayout(bp.getTextClass().defaultLayout());
642 par.insert(0, plaintext, Font(), Change(Change::UNCHANGED));
644 theCuts.push(make_pair(pars, bp.getTextClassPtr()));
646 copySelectionToStack(cur, theCuts);
649 // stuff the selection onto the X clipboard, from an explicit copy request
650 putClipboard(theCuts[0].first, theCuts[0].second, plaintext);
654 void saveSelection(Cursor & cur)
656 // This function is called, not when a selection is formed, but when
657 // a selection is cleared. Therefore, multiple keyboard selection
658 // will not repeatively trigger this function (bug 3877).
660 && cur.selBegin() == cur.bv().cursor().selBegin()
661 && cur.selEnd() == cur.bv().cursor().selEnd()) {
662 LYXERR(Debug::ACTION, "'" << cur.selectionAsString(true) << "'");
663 copySelectionToStack(cur, selectionBuffer);
670 return !selectionBuffer.empty();
674 void clearSelection()
676 selectionBuffer.clear();
686 docstring getSelection(Buffer const & buf, size_t sel_index)
688 return sel_index < theCuts.size()
689 ? theCuts[sel_index].first.back().asString(buf, false)
694 void pasteParagraphList(Cursor & cur, ParagraphList const & parlist,
695 TextClassPtr textclass, ErrorList & errorList)
697 if (cur.inTexted()) {
698 Text * text = cur.text();
704 boost::tie(ppp, endpit) =
705 pasteSelectionHelper(cur, parlist,
706 textclass, errorList);
707 updateLabels(cur.buffer());
708 cur.clearSelection();
709 text->setCursor(cur, ppp.first, ppp.second);
712 // mathed is handled in InsetMathNest/InsetMathGrid
713 BOOST_ASSERT(!cur.inMathed());
717 void pasteFromStack(Cursor & cur, ErrorList & errorList, size_t sel_index)
719 // this does not make sense, if there is nothing to paste
720 if (!checkPastePossible(sel_index))
724 pasteParagraphList(cur, theCuts[sel_index].first,
725 theCuts[sel_index].second, errorList);
730 void pasteClipboardText(Cursor & cur, ErrorList & errorList, bool asParagraphs)
732 // Use internal clipboard if it is the most recent one
733 if (theClipboard().isInternal()) {
734 pasteFromStack(cur, errorList, 0);
738 // First try LyX format
739 if (theClipboard().hasLyXContents()) {
740 string lyx = theClipboard().getAsLyX();
742 // For some strange reason gcc 3.2 and 3.3 do not accept
743 // Buffer buffer(string(), false);
744 Buffer buffer("", false);
745 buffer.setUnnamed(true);
746 if (buffer.readString(lyx)) {
748 pasteParagraphList(cur, buffer.paragraphs(),
749 buffer.params().getTextClassPtr(), errorList);
756 // Then try plain text
757 docstring const text = theClipboard().getAsText();
762 cur.text()->insertStringAsParagraphs(cur, text);
764 cur.text()->insertStringAsLines(cur, text);
768 void pasteClipboardGraphics(Cursor & cur, ErrorList & errorList,
769 Clipboard::GraphicsType preferedType)
771 BOOST_ASSERT(theClipboard().hasGraphicsContents(preferedType));
773 // get picture from clipboard
774 FileName filename = theClipboard().getAsGraphics(cur, preferedType);
775 if (filename.empty())
778 // create inset for graphic
779 InsetGraphics * inset = new InsetGraphics;
780 InsetGraphicsParams params;
781 params.filename = EmbeddedFile(filename.absFilename(), cur.buffer().filePath());
782 inset->setParams(params);
788 void pasteSelection(Cursor & cur, ErrorList & errorList)
790 if (selectionBuffer.empty())
793 pasteParagraphList(cur, selectionBuffer[0].first,
794 selectionBuffer[0].second, errorList);
798 void replaceSelectionWithString(Cursor & cur, docstring const & str, bool backwards)
801 DocIterator selbeg = cur.selectionBegin();
803 // Get font setting before we cut
805 selbeg.paragraph().getFontSettings(cur.buffer().params(), selbeg.pos());
807 // Insert the new string
808 pos_type pos = cur.selEnd().pos();
809 Paragraph & par = cur.selEnd().paragraph();
810 docstring::const_iterator cit = str.begin();
811 docstring::const_iterator end = str.end();
812 for (; cit != end; ++cit, ++pos)
813 par.insertChar(pos, *cit, font, cur.buffer().params().trackChanges);
816 cutSelection(cur, true, false);
818 // select the replacement
820 selbeg.pos() += str.length();
821 cur.setSelection(selbeg, -int(str.length()));
823 cur.setSelection(selbeg, str.length());
827 void replaceSelection(Cursor & cur)
830 cutSelection(cur, true, false);
834 void eraseSelection(Cursor & cur)
836 //lyxerr << "cap::eraseSelection begin: " << cur << endl;
837 CursorSlice const & i1 = cur.selBegin();
838 CursorSlice const & i2 = cur.selEnd();
839 if (i1.inset().asInsetMath()) {
842 if (i1.idx() == i2.idx()) {
843 i1.cell().erase(i1.pos(), i2.pos());
844 // We may have deleted i1.cell(cur.pos()).
845 // Make sure that pos is valid.
846 if (cur.pos() > cur.lastpos())
847 cur.pos() = cur.lastpos();
849 InsetMath * p = i1.asInsetMath();
850 Inset::row_type r1, r2;
851 Inset::col_type c1, c2;
852 region(i1, i2, r1, r2, c1, c2);
853 for (Inset::row_type row = r1; row <= r2; ++row)
854 for (Inset::col_type col = c1; col <= c2; ++col)
855 p->cell(p->index(row, col)).clear();
856 // We've deleted the whole cell. Only pos 0 is valid.
859 // need a valid cursor. (Lgb)
860 cur.clearSelection();
862 lyxerr << "can't erase this selection 1" << endl;
864 //lyxerr << "cap::eraseSelection end: " << cur << endl;
868 void selDel(Cursor & cur)
870 //lyxerr << "cap::selDel" << endl;
876 void selClearOrDel(Cursor & cur)
878 //lyxerr << "cap::selClearOrDel" << endl;
879 if (lyxrc.auto_region_delete)
882 cur.selection() = false;
886 docstring grabSelection(Cursor const & cur)
888 if (!cur.selection())
891 // FIXME: What is wrong with the following?
894 for (DocIterator dit = cur.selectionBegin();
895 dit != cur.selectionEnd(); dit.forwardPos())
896 os << asString(dit.cell());
900 CursorSlice i1 = cur.selBegin();
901 CursorSlice i2 = cur.selEnd();
903 if (i1.idx() == i2.idx()) {
904 if (i1.inset().asInsetMath()) {
905 MathData::const_iterator it = i1.cell().begin();
906 return asString(MathData(it + i1.pos(), it + i2.pos()));
908 return from_ascii("unknown selection 1");
912 Inset::row_type r1, r2;
913 Inset::col_type c1, c2;
914 region(i1, i2, r1, r2, c1, c2);
917 if (i1.inset().asInsetMath()) {
918 for (Inset::row_type row = r1; row <= r2; ++row) {
921 for (Inset::col_type col = c1; col <= c2; ++col) {
924 data += asString(i1.asInsetMath()->
925 cell(i1.asInsetMath()->index(row, col)));
929 data = from_ascii("unknown selection 2");
935 void dirtyTabularStack(bool b)
937 dirty_tabular_stack_ = b;
941 bool tabularStackDirty()
943 return dirty_tabular_stack_;