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 if (pars[pit].inInset() &&
131 (pars[pit].inInset()->lyxCode() == ERT_CODE ||
132 pars[pit].inInset()->lyxCode() == LISTINGS_CODE)) {
133 for (ParagraphList::size_type 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();
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 lit = fpit->insetList().begin();
221 InsetList::const_iterator eit = fpit->insetList().end();
223 for (; lit != eit; ++lit) {
224 switch (lit->inset->lyxCode()) {
226 InsetTabular * it = static_cast<InsetTabular*>(lit->inset);
236 insertion.swap(in.paragraphs());
238 // Split the paragraph for inserting the buf if necessary.
240 breakParagraphConservative(buffer.params(), pars, pit, pos);
244 pars.insert(boost::next(pars.begin(), pit),
248 // merge the empty par with the last par of the insertion
249 mergeParagraph(buffer.params(), pars,
250 pit + insertion.size() - 1);
252 pars.insert(boost::next(pars.begin(), pit + 1),
256 // merge the first par of the insertion with the current par
257 mergeParagraph(buffer.params(), pars, pit);
260 pit_type last_paste = pit + insertion.size() - 1;
262 // Store the new cursor position.
264 pos = pars[last_paste].size();
266 // Join (conditionally) last pasted paragraph with next one, i.e.,
267 // the tail of the spliced document paragraph
268 if (!empty && last_paste + 1 != pit_type(pars.size())) {
269 if (pars[last_paste + 1].hasSameLayout(pars[last_paste])) {
270 mergeParagraph(buffer.params(), pars, last_paste);
271 } else if (pars[last_paste + 1].empty()) {
272 pars[last_paste + 1].makeSameLayout(pars[last_paste]);
273 mergeParagraph(buffer.params(), pars, last_paste);
274 } else if (pars[last_paste].empty()) {
275 pars[last_paste].makeSameLayout(pars[last_paste + 1]);
276 mergeParagraph(buffer.params(), pars, last_paste);
278 pars[last_paste + 1].stripLeadingSpaces(buffer.params().trackChanges);
283 return make_pair(PitPosPair(pit, pos), last_paste + 1);
287 PitPosPair eraseSelectionHelper(BufferParams const & params,
288 ParagraphList & pars,
289 pit_type startpit, pit_type endpit,
290 int startpos, int endpos)
292 // Start of selection is really invalid.
293 if (startpit == pit_type(pars.size()) ||
294 (startpos > pars[startpit].size()))
295 return PitPosPair(endpit, endpos);
297 // Start and end is inside same paragraph
298 if (endpit == pit_type(pars.size()) || startpit == endpit) {
299 endpos -= pars[startpit].eraseChars(startpos, endpos, params.trackChanges);
300 return PitPosPair(endpit, endpos);
303 for (pit_type pit = startpit; pit != endpit + 1;) {
304 pos_type const left = (pit == startpit ? startpos : 0);
305 pos_type right = (pit == endpit ? endpos : pars[pit].size() + 1);
306 bool const merge = pars[pit].isMergedOnEndOfParDeletion(params.trackChanges);
308 // Logically erase only, including the end-of-paragraph character
309 pars[pit].eraseChars(left, right, params.trackChanges);
311 // Separate handling of paragraph break:
312 if (merge && pit != endpit &&
313 (pit + 1 != endpit || pars[pit].hasSameLayout(pars[endpit]))) {
314 if (pit + 1 == endpit)
315 endpos += pars[pit].size();
316 mergeParagraph(params, pars, pit);
322 // Ensure legal cursor pos:
325 return PitPosPair(endpit, endpos);
329 void putClipboard(ParagraphList const & paragraphs, TextClassPtr textclass,
330 docstring const & plaintext)
332 // For some strange reason gcc 3.2 and 3.3 do not accept
333 // Buffer buffer(string(), false);
334 Buffer buffer("", false);
335 buffer.setUnnamed(true);
336 buffer.paragraphs() = paragraphs;
337 buffer.params().setTextClass(textclass);
339 if (buffer.write(lyx))
340 theClipboard().put(lyx.str(), plaintext);
342 theClipboard().put(string(), plaintext);
346 void copySelectionHelper(Buffer const & buf, ParagraphList & pars,
347 pit_type startpit, pit_type endpit,
348 int start, int end, TextClassPtr tc, CutStack & cutstack)
350 BOOST_ASSERT(0 <= start && start <= pars[startpit].size());
351 BOOST_ASSERT(0 <= end && end <= pars[endpit].size());
352 BOOST_ASSERT(startpit != endpit || start <= end);
354 // Clone the paragraphs within the selection.
355 ParagraphList copy_pars(boost::next(pars.begin(), startpit),
356 boost::next(pars.begin(), endpit + 1));
358 // Remove the end of the last paragraph; afterwards, remove the
359 // beginning of the first paragraph. Keep this order - there may only
360 // be one paragraph! Do not track deletions here; this is an internal
361 // action not visible to the user
363 Paragraph & back = copy_pars.back();
364 back.eraseChars(end, back.size(), false);
365 Paragraph & front = copy_pars.front();
366 front.eraseChars(0, start, false);
368 ParagraphList::iterator it = copy_pars.begin();
369 ParagraphList::iterator it_end = copy_pars.end();
371 for (; it != it_end; it++) {
372 // ERT paragraphs have the Language latex_language.
373 // This is invalid outside of ERT, so we need to change it
374 // to the buffer language.
375 if (it->ownerCode() == ERT_CODE || it->ownerCode() == LISTINGS_CODE) {
376 it->changeLanguage(buf.params(), latex_language, buf.language());
378 it->setInsetOwner(0);
381 // do not copy text (also nested in insets) which is marked as deleted
382 acceptChanges(copy_pars, buf.params());
384 cutstack.push(make_pair(copy_pars, tc));
394 docstring grabAndEraseSelection(Cursor & cur)
396 if (!cur.selection())
398 docstring res = grabSelection(cur);
404 void switchBetweenClasses(TextClassPtr const & oldone,
405 TextClassPtr const & newone, InsetText & in, ErrorList & errorlist)
409 BOOST_ASSERT(!in.paragraphs().empty());
410 if (oldone == newone)
413 TextClass const & oldtc = *oldone;
414 TextClass const & newtc = *newone;
417 ParIterator end = par_iterator_end(in);
418 for (ParIterator it = par_iterator_begin(in); it != end; ++it) {
419 docstring const name = it->layout()->name();
420 bool hasLayout = newtc.hasLayout(name);
423 it->layout(newtc[name]);
425 it->layout(newtc.defaultLayout());
427 if (!hasLayout && name != oldtc.defaultLayoutName()) {
428 docstring const s = bformat(
429 _("Layout had to be changed from\n%1$s to %2$s\n"
430 "because of class conversion from\n%3$s to %4$s"),
431 name, it->layout()->name(),
432 from_utf8(oldtc.name()), from_utf8(newtc.name()));
433 // To warn the user that something had to be done.
434 errorlist.push_back(ErrorItem(_("Changed Layout"), s,
441 InsetIterator const i_end = inset_iterator_end(in);
442 for (InsetIterator it = inset_iterator_begin(in); it != i_end; ++it) {
443 InsetCollapsable * inset = it->asInsetCollapsable();
446 if (inset->lyxCode() != FLEX_CODE)
447 // FIXME: Should we verify all InsetCollapsable?
449 inset->setLayout(newone);
450 if (inset->getLayout().labelstring != from_utf8("UNDEFINED"))
452 // The flex inset is undefined in newtc
453 docstring const s = bformat(_(
454 "Flex inset %1$s is "
455 "undefined because of class "
456 "conversion from\n%2$s to %3$s"),
457 inset->name(), from_utf8(oldtc.name()),
458 from_utf8(newtc.name()));
459 // To warn the user that something had to be done.
460 errorlist.push_back(ErrorItem(
461 _("Undefined flex inset"),
462 s, it.paragraph().id(), it.pos(), it.pos() + 1));
467 vector<docstring> const availableSelections(Buffer const & buffer)
469 vector<docstring> selList;
471 CutStack::const_iterator cit = theCuts.begin();
472 CutStack::const_iterator end = theCuts.end();
473 for (; cit != end; ++cit) {
474 // we do not use cit-> here because gcc 2.9x does not
476 ParagraphList const & pars = (*cit).first;
478 ParagraphList::const_iterator pit = pars.begin();
479 ParagraphList::const_iterator pend = pars.end();
480 for (; pit != pend; ++pit) {
481 asciiSel += pit->asString(buffer, false);
482 if (asciiSel.size() > 25) {
483 asciiSel.replace(22, docstring::npos,
489 selList.push_back(asciiSel);
496 size_type numberOfSelections()
498 return theCuts.size();
502 void cutSelection(Cursor & cur, bool doclear, bool realcut)
504 // This doesn't make sense, if there is no selection
505 if (!cur.selection())
508 // OK, we have a selection. This is always between cur.selBegin()
511 if (cur.inTexted()) {
512 Text * text = cur.text();
517 // make sure that the depth behind the selection are restored, too
518 cur.recordUndoSelection();
519 pit_type begpit = cur.selBegin().pit();
520 pit_type endpit = cur.selEnd().pit();
522 int endpos = cur.selEnd().pos();
524 BufferParams const & bp = cur.buffer().params();
526 copySelectionHelper(cur.buffer(),
529 cur.selBegin().pos(), endpos,
530 bp.getTextClassPtr(), theCuts);
531 // Stuff what we got on the clipboard.
532 // Even if there is no selection.
533 putClipboard(theCuts[0].first, theCuts[0].second,
534 cur.selectionAsString(true));
537 boost::tie(endpit, endpos) =
538 eraseSelectionHelper(bp,
541 cur.selBegin().pos(), endpos);
543 // cutSelection can invalidate the cursor so we need to set
545 // we prefer the end for when tracking changes
549 // sometimes necessary
551 && text->paragraphs()[begpit].stripLeadingSpaces(bp.trackChanges))
554 // need a valid cursor. (Lgb)
555 cur.clearSelection();
556 updateLabels(cur.buffer());
558 // tell tabular that a recent copy happened
559 dirtyTabularStack(false);
562 if (cur.inMathed()) {
563 if (cur.selBegin().idx() != cur.selEnd().idx()) {
564 // The current selection spans more than one cell.
566 cur.recordUndoInset();
568 // Record only the current cell to avoid a jumping
579 void copySelection(Cursor & cur)
581 copySelection(cur, cur.selectionAsString(true));
587 void copySelectionToStack(Cursor & cur, CutStack & cutstack)
589 // this doesn't make sense, if there is no selection
590 if (!cur.selection())
593 // copySelection can not yet handle the case of cross idx selection
594 if (cur.selBegin().idx() != cur.selEnd().idx())
597 if (cur.inTexted()) {
598 Text * text = cur.text();
600 // ok we have a selection. This is always between cur.selBegin()
601 // and sel_end cursor
603 // copy behind a space if there is one
604 ParagraphList & pars = text->paragraphs();
605 pos_type pos = cur.selBegin().pos();
606 pit_type par = cur.selBegin().pit();
607 while (pos < pars[par].size() &&
608 pars[par].isLineSeparator(pos) &&
609 (par != cur.selEnd().pit() || pos < cur.selEnd().pos()))
612 copySelectionHelper(cur.buffer(), pars, par, cur.selEnd().pit(),
613 pos, cur.selEnd().pos(),
614 cur.buffer().params().getTextClassPtr(), cutstack);
615 dirtyTabularStack(false);
618 if (cur.inMathed()) {
619 //lyxerr << "copySelection in mathed" << endl;
622 BufferParams const & bp = cur.buffer().params();
623 par.layout(bp.getTextClass().defaultLayout());
624 par.insert(0, grabSelection(cur), Font(), Change(Change::UNCHANGED));
626 cutstack.push(make_pair(pars, bp.getTextClassPtr()));
633 void copySelectionToStack()
635 if (!selectionBuffer.empty())
636 theCuts.push(selectionBuffer[0]);
640 void copySelection(Cursor & cur, docstring const & plaintext)
642 // In tablemode, because copy and paste actually use special table stack
643 // we do not attempt to get selected paragraphs under cursor. Instead, a
644 // paragraph with the plain text version is generated so that table cells
645 // can be pasted as pure text somewhere else.
646 if (cur.selBegin().idx() != cur.selEnd().idx()) {
649 BufferParams const & bp = cur.buffer().params();
650 par.layout(bp.getTextClass().defaultLayout());
651 par.insert(0, plaintext, Font(), Change(Change::UNCHANGED));
653 theCuts.push(make_pair(pars, bp.getTextClassPtr()));
655 copySelectionToStack(cur, theCuts);
658 // stuff the selection onto the X clipboard, from an explicit copy request
659 putClipboard(theCuts[0].first, theCuts[0].second, plaintext);
663 void saveSelection(Cursor & cur)
665 // This function is called, not when a selection is formed, but when
666 // a selection is cleared. Therefore, multiple keyboard selection
667 // will not repeatively trigger this function (bug 3877).
669 && cur.selBegin() == cur.bv().cursor().selBegin()
670 && cur.selEnd() == cur.bv().cursor().selEnd()) {
671 LYXERR(Debug::ACTION, "'" << cur.selectionAsString(true) << "'");
672 copySelectionToStack(cur, selectionBuffer);
679 return !selectionBuffer.empty();
683 void clearSelection()
685 selectionBuffer.clear();
695 docstring getSelection(Buffer const & buf, size_t sel_index)
697 return sel_index < theCuts.size()
698 ? theCuts[sel_index].first.back().asString(buf, false)
703 void pasteParagraphList(Cursor & cur, ParagraphList const & parlist,
704 TextClassPtr textclass, ErrorList & errorList)
706 if (cur.inTexted()) {
707 Text * text = cur.text();
713 boost::tie(ppp, endpit) =
714 pasteSelectionHelper(cur, parlist,
715 textclass, errorList);
716 updateLabels(cur.buffer());
717 cur.clearSelection();
718 text->setCursor(cur, ppp.first, ppp.second);
721 // mathed is handled in InsetMathNest/InsetMathGrid
722 BOOST_ASSERT(!cur.inMathed());
726 void pasteFromStack(Cursor & cur, ErrorList & errorList, size_t sel_index)
728 // this does not make sense, if there is nothing to paste
729 if (!checkPastePossible(sel_index))
733 pasteParagraphList(cur, theCuts[sel_index].first,
734 theCuts[sel_index].second, errorList);
739 void pasteClipboardText(Cursor & cur, ErrorList & errorList, bool asParagraphs)
741 // Use internal clipboard if it is the most recent one
742 if (theClipboard().isInternal()) {
743 pasteFromStack(cur, errorList, 0);
747 // First try LyX format
748 if (theClipboard().hasLyXContents()) {
749 string lyx = theClipboard().getAsLyX();
751 // For some strange reason gcc 3.2 and 3.3 do not accept
752 // Buffer buffer(string(), false);
753 Buffer buffer("", false);
754 buffer.setUnnamed(true);
755 if (buffer.readString(lyx)) {
757 pasteParagraphList(cur, buffer.paragraphs(),
758 buffer.params().getTextClassPtr(), errorList);
765 // Then try plain text
766 docstring const text = theClipboard().getAsText();
771 cur.text()->insertStringAsParagraphs(cur, text);
773 cur.text()->insertStringAsLines(cur, text);
777 void pasteClipboardGraphics(Cursor & cur, ErrorList & errorList,
778 Clipboard::GraphicsType preferedType)
780 BOOST_ASSERT(theClipboard().hasGraphicsContents(preferedType));
782 // get picture from clipboard
783 FileName filename = theClipboard().getAsGraphics(cur, preferedType);
784 if (filename.empty())
787 // create inset for graphic
788 InsetGraphics * inset = new InsetGraphics;
789 InsetGraphicsParams params;
790 params.filename = EmbeddedFile(filename.absFilename(), cur.buffer().filePath());
791 inset->setParams(params);
797 void pasteSelection(Cursor & cur, ErrorList & errorList)
799 if (selectionBuffer.empty())
802 pasteParagraphList(cur, selectionBuffer[0].first,
803 selectionBuffer[0].second, errorList);
807 void replaceSelectionWithString(Cursor & cur, docstring const & str, bool backwards)
810 DocIterator selbeg = cur.selectionBegin();
812 // Get font setting before we cut
814 selbeg.paragraph().getFontSettings(cur.buffer().params(), selbeg.pos());
816 // Insert the new string
817 pos_type pos = cur.selEnd().pos();
818 Paragraph & par = cur.selEnd().paragraph();
819 docstring::const_iterator cit = str.begin();
820 docstring::const_iterator end = str.end();
821 for (; cit != end; ++cit, ++pos)
822 par.insertChar(pos, *cit, font, cur.buffer().params().trackChanges);
825 cutSelection(cur, true, false);
827 // select the replacement
829 selbeg.pos() += str.length();
830 cur.setSelection(selbeg, -int(str.length()));
832 cur.setSelection(selbeg, str.length());
836 void replaceSelection(Cursor & cur)
839 cutSelection(cur, true, false);
843 void eraseSelection(Cursor & cur)
845 //lyxerr << "cap::eraseSelection begin: " << cur << endl;
846 CursorSlice const & i1 = cur.selBegin();
847 CursorSlice const & i2 = cur.selEnd();
848 if (i1.inset().asInsetMath()) {
851 if (i1.idx() == i2.idx()) {
852 i1.cell().erase(i1.pos(), i2.pos());
853 // We may have deleted i1.cell(cur.pos()).
854 // Make sure that pos is valid.
855 if (cur.pos() > cur.lastpos())
856 cur.pos() = cur.lastpos();
858 InsetMath * p = i1.asInsetMath();
859 Inset::row_type r1, r2;
860 Inset::col_type c1, c2;
861 region(i1, i2, r1, r2, c1, c2);
862 for (Inset::row_type row = r1; row <= r2; ++row)
863 for (Inset::col_type col = c1; col <= c2; ++col)
864 p->cell(p->index(row, col)).clear();
865 // We've deleted the whole cell. Only pos 0 is valid.
868 // need a valid cursor. (Lgb)
869 cur.clearSelection();
871 lyxerr << "can't erase this selection 1" << endl;
873 //lyxerr << "cap::eraseSelection end: " << cur << endl;
877 void selDel(Cursor & cur)
879 //lyxerr << "cap::selDel" << endl;
885 void selClearOrDel(Cursor & cur)
887 //lyxerr << "cap::selClearOrDel" << endl;
888 if (lyxrc.auto_region_delete)
891 cur.selection() = false;
895 docstring grabSelection(Cursor const & cur)
897 if (!cur.selection())
900 // FIXME: What is wrong with the following?
903 for (DocIterator dit = cur.selectionBegin();
904 dit != cur.selectionEnd(); dit.forwardPos())
905 os << asString(dit.cell());
909 CursorSlice i1 = cur.selBegin();
910 CursorSlice i2 = cur.selEnd();
912 if (i1.idx() == i2.idx()) {
913 if (i1.inset().asInsetMath()) {
914 MathData::const_iterator it = i1.cell().begin();
915 return asString(MathData(it + i1.pos(), it + i2.pos()));
917 return from_ascii("unknown selection 1");
921 Inset::row_type r1, r2;
922 Inset::col_type c1, c2;
923 region(i1, i2, r1, r2, c1, c2);
926 if (i1.inset().asInsetMath()) {
927 for (Inset::row_type row = r1; row <= r2; ++row) {
930 for (Inset::col_type col = c1; col <= c2; ++col) {
933 data += asString(i1.asInsetMath()->
934 cell(i1.asInsetMath()->index(row, col)));
938 data = from_ascii("unknown selection 2");
944 void dirtyTabularStack(bool b)
946 dirty_tabular_stack_ = b;
950 bool tabularStackDirty()
952 return dirty_tabular_stack_;