]> git.lyx.org Git - lyx.git/blob - src/CutAndPaste.C
b6b7abd280e8204c5dcff53e5d8dcdae76df5ba7
[lyx.git] / src / CutAndPaste.C
1 /*
2  * \file CutAndPaste.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Jürgen Vigna
7  * \author Lars Gullik Bjønnes
8  * \author Alfredo Braunstein
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #include <config.h>
14
15 #include "CutAndPaste.h"
16
17 #include "buffer.h"
18 #include "buffer_funcs.h"
19 #include "bufferparams.h"
20 #include "BufferView.h"
21 #include "cursor.h"
22 #include "debug.h"
23 #include "errorlist.h"
24 #include "funcrequest.h"
25 #include "gettext.h"
26 #include "lfuns.h"
27 #include "lyxrc.h"
28 #include "lyxtext.h"
29 #include "lyxtextclasslist.h"
30 #include "paragraph.h"
31 #include "paragraph_funcs.h"
32 #include "ParagraphParameters.h"
33 #include "ParagraphList_fwd.h"
34 #include "pariterator.h"
35 #include "undo.h"
36
37 #include "insets/insettabular.h"
38
39 #include "mathed/math_data.h"
40 #include "mathed/math_inset.h"
41 #include "mathed/math_support.h"
42
43 #include "support/lstrings.h"
44
45 #include <boost/tuple/tuple.hpp>
46
47 using lyx::pos_type;
48 using lyx::pit_type;
49 using lyx::textclass_type;
50
51 using lyx::support::bformat;
52
53 using std::endl;
54 using std::for_each;
55 using std::make_pair;
56 using std::pair;
57 using std::vector;
58 using std::string;
59
60
61 namespace {
62
63 typedef std::pair<lyx::pit_type, int> PitPosPair;
64
65 typedef limited_stack<pair<ParagraphList, textclass_type> > CutStack;
66
67 CutStack theCuts(10);
68
69 class resetOwnerAndChanges : public std::unary_function<Paragraph, void> {
70 public:
71         void operator()(Paragraph & p) const {
72                 p.cleanChanges();
73                 p.setInsetOwner(0);
74         }
75 };
76
77
78 void region(CursorSlice const & i1, CursorSlice const & i2,
79         InsetBase::row_type & r1, InsetBase::row_type & r2,
80         InsetBase::col_type & c1, InsetBase::col_type & c2)
81 {
82         InsetBase & p = i1.inset();
83         c1 = p.col(i1.idx());
84         c2 = p.col(i2.idx());
85         if (c1 > c2)
86                 std::swap(c1, c2);
87         r1 = p.row(i1.idx());
88         r2 = p.row(i2.idx());
89         if (r1 > r2)
90                 std::swap(r1, r2);
91 }
92
93
94 bool checkPastePossible(int index)
95 {
96         return size_t(index) < theCuts.size() && !theCuts[index].first.empty();
97 }
98
99
100 pair<PitPosPair, pit_type>
101 pasteSelectionHelper(Buffer const & buffer, ParagraphList & pars,
102         pit_type pit, int pos,
103         textclass_type tc, size_t cut_index, ErrorList & errorlist)
104 {
105         if (!checkPastePossible(cut_index))
106                 return make_pair(PitPosPair(pit, pos), pit);
107
108         BOOST_ASSERT (pos <= pars[pit].size());
109
110         // Make a copy of the CaP paragraphs.
111         ParagraphList insertion = theCuts[cut_index].first;
112         textclass_type const textclass = theCuts[cut_index].second;
113
114         // Now remove all out of the pars which is NOT allowed in the
115         // new environment and set also another font if that is required.
116
117         // Convert newline to paragraph break in ERT inset.
118         // This should not be here!
119         if (pars[pit].inInset()->lyxCode() == InsetBase::ERT_CODE) {
120                 for (ParagraphList::size_type i = 0; i < insertion.size(); ++i) {
121                         for (pos_type j = 0; j < insertion[i].size(); ++j) {
122                                 if (insertion[i].isNewline(j)) {
123                                         insertion[i].erase(j);
124                                         breakParagraphConservative(
125                                                         buffer.params(),
126                                                         insertion, i, j);
127                                 }
128                         }
129                 }
130         }
131
132         // Make sure there is no class difference.
133         lyx::cap::SwitchLayoutsBetweenClasses(textclass, tc, insertion,
134                                     errorlist);
135
136         ParagraphList::iterator tmpbuf = insertion.begin();
137         int depth_delta = pars[pit].params().depth() - tmpbuf->params().depth();
138
139         Paragraph::depth_type max_depth = pars[pit].getMaxDepthAfter();
140
141         for (; tmpbuf != insertion.end(); ++tmpbuf) {
142                 // If we have a negative jump so that the depth would
143                 // go below 0 depth then we have to redo the delta to
144                 // this new max depth level so that subsequent
145                 // paragraphs are aligned correctly to this paragraph
146                 // at level 0.
147                 if (int(tmpbuf->params().depth()) + depth_delta < 0)
148                         depth_delta = 0;
149
150                 // Set the right depth so that we are not too deep or shallow.
151                 tmpbuf->params().depth(tmpbuf->params().depth() + depth_delta);
152                 if (tmpbuf->params().depth() > max_depth)
153                         tmpbuf->params().depth(max_depth);
154
155                 // Only set this from the 2nd on as the 2nd depends
156                 // for maxDepth still on pit.
157                 if (tmpbuf != insertion.begin())
158                         max_depth = tmpbuf->getMaxDepthAfter();
159
160                 // Set the inset owner of this paragraph.
161                 tmpbuf->setInsetOwner(pars[pit].inInset());
162                 for (pos_type i = 0; i < tmpbuf->size(); ++i) {
163                         if (tmpbuf->getChar(i) == Paragraph::META_INSET &&
164                             !pars[pit].insetAllowed(tmpbuf->getInset(i)->lyxCode()))
165                                 tmpbuf->erase(i--);
166                 }
167         }
168
169         bool const empty = pars[pit].empty();
170         if (!empty) {
171                 // Make the buf exactly the same layout as the cursor
172                 // paragraph.
173                 insertion.begin()->makeSameLayout(pars[pit]);
174         }
175
176         // Prepare the paragraphs and insets for insertion.
177         // A couple of insets store buffer references so need updating.
178         InsetText in;
179         std::swap(in.paragraphs(), insertion);
180
181         ParIterator fpit = par_iterator_begin(in);
182         ParIterator fend = par_iterator_end(in);
183
184         for (; fpit != fend; ++fpit) {
185                 InsetList::iterator lit = fpit->insetlist.begin();
186                 InsetList::iterator eit = fpit->insetlist.end();
187
188                 for (; lit != eit; ++lit) {
189                         switch (lit->inset->lyxCode()) {
190                         case InsetBase::TABULAR_CODE: {
191                                 InsetTabular * it = static_cast<InsetTabular*>(lit->inset);
192                                 it->buffer(&buffer);
193                                 break;
194                         }
195
196                         default:
197                                 break; // nothing
198                         }
199                 }
200         }
201         std::swap(in.paragraphs(), insertion);
202
203         // Split the paragraph for inserting the buf if necessary.
204         if (!empty)
205                 breakParagraphConservative(buffer.params(), pars, pit, pos);
206
207         // Paste it!
208         if (empty) {
209                 pars.insert(pars.begin() + pit, insertion.begin(),
210                             insertion.end());
211
212                 // merge the empty par with the last par of the insertion
213                 mergeParagraph(buffer.params(), pars,
214                                pit + insertion.size() - 1);
215         } else {
216                 pars.insert(pars.begin() + pit + 1, insertion.begin(),
217                             insertion.end());
218
219                 // merge the first par of the insertion with the current par
220                 mergeParagraph(buffer.params(), pars, pit);
221         }
222
223         pit_type last_paste = pit + insertion.size() - 1;
224
225         // Store the new cursor position.
226         pit = last_paste;
227         pos = pars[last_paste].size();
228
229         // Maybe some pasting.
230         if (!empty && last_paste + 1 != pit_type(pars.size())) {
231                 if (pars[last_paste + 1].hasSameLayout(pars[last_paste])) {
232                         mergeParagraph(buffer.params(), pars, last_paste);
233                 } else if (pars[last_paste + 1].empty()) {
234                         pars[last_paste + 1].makeSameLayout(pars[last_paste]);
235                         mergeParagraph(buffer.params(), pars, last_paste);
236                 } else if (pars[last_paste].empty()) {
237                         pars[last_paste].makeSameLayout(pars[last_paste + 1]);
238                         mergeParagraph(buffer.params(), pars, last_paste);
239                 } else {
240                         pars[last_paste + 1].stripLeadingSpaces();
241                         ++last_paste;
242                 }
243         }
244
245         return make_pair(PitPosPair(pit, pos), last_paste + 1);
246 }
247
248
249 PitPosPair eraseSelectionHelper(BufferParams const & params,
250         ParagraphList & pars,
251         pit_type startpit, pit_type endpit,
252         int startpos, int endpos, bool doclear)
253 {
254         if (startpit == pit_type(pars.size()) ||
255             (startpos > pars[startpit].size()))
256                 return PitPosPair(endpit, endpos);
257
258         if (endpit == pit_type(pars.size()) ||
259             startpit == endpit) {
260                 endpos -= pars[startpit].erase(startpos, endpos);
261                 return PitPosPair(endpit, endpos);
262         }
263
264         // clear end/begin fragments of the first/last par in selection
265         bool all_erased = true;
266
267         pars[startpit].erase(startpos, pars[startpit].size());
268         if (pars[startpit].size() != startpos)
269                 all_erased = false;
270
271         endpos -= pars[endpit].erase(0, endpos);
272         if (endpos != 0)
273                 all_erased = false;
274
275         // Loop through the deleted pars if any, erasing as needed
276         for (pit_type pit = startpit + 1; pit != endpit;) {
277                 // "erase" the contents of the par
278                 pars[pit].erase(0, pars[pit].size());
279                 if (!pars[pit].size()) {
280                         // remove the par if it's now empty
281                         pars.erase(pars.begin() + pit);
282                         --endpit;
283                 } else {
284                         ++pit;
285                         all_erased = false;
286                 }
287         }
288
289 #if 0 // FIXME: why for cut but not copy ?
290         // the cut selection should begin with standard layout
291         if (realcut) {
292                 buf->params().clear();
293                 buf->bibkey = 0;
294                 buf->layout(textclasslist[buffer->params.textclass].defaultLayoutName());
295         }
296 #endif
297
298         if (startpit + 1 == pit_type(pars.size()))
299                 return PitPosPair(endpit, endpos);
300
301         if (doclear) {
302                 pars[startpit + 1].stripLeadingSpaces();
303         }
304
305         // paste the paragraphs again, if possible
306         if (all_erased &&
307             (pars[startpit].hasSameLayout(pars[startpit + 1]) ||
308              pars[startpit + 1].empty())) {
309                 mergeParagraph(params, pars, startpit);
310                 // this because endpar gets deleted here!
311                 endpit = startpit;
312                 endpos = startpos;
313         }
314
315         return PitPosPair(endpit, endpos);
316
317 }
318
319
320 void copySelectionHelper(ParagraphList & pars,
321         pit_type startpit, pit_type endpit,
322         int start, int end, textclass_type tc)
323 {
324         BOOST_ASSERT(0 <= start && start <= pars[startpit].size());
325         BOOST_ASSERT(0 <= end && end <= pars[endpit].size());
326         BOOST_ASSERT(startpit != endpit || start <= end);
327
328         // Clone the paragraphs within the selection.
329         ParagraphList paragraphs(pars.begin() + startpit, pars.begin() + endpit + 1);
330         for_each(paragraphs.begin(), paragraphs.end(), resetOwnerAndChanges());
331
332         // Cut out the end of the last paragraph.
333         Paragraph & back = paragraphs.back();
334         back.erase(end, back.size());
335
336         // Cut out the begin of the first paragraph
337         Paragraph & front = paragraphs.front();
338         front.erase(0, start);
339
340         theCuts.push(make_pair(paragraphs, tc));
341 }
342
343
344
345 PitPosPair cutSelectionHelper(BufferParams const & params,
346         ParagraphList & pars, pit_type startpit, pit_type endpit,
347         int startpos, int endpos, textclass_type tc, bool doclear)
348 {
349         copySelectionHelper(pars, startpit, endpit, startpos, endpos, tc);
350         return eraseSelectionHelper(params, pars, startpit, endpit,
351                 startpos, endpos, doclear);
352 }
353
354
355 } // namespace anon
356
357
358
359
360 namespace lyx {
361 namespace cap {
362
363 string grabAndEraseSelection(LCursor & cur)
364 {
365         if (!cur.selection())
366                 return string();
367         string res = grabSelection(cur);
368         eraseSelection(cur);
369         cur.selection() = false;
370         return res;
371 }
372
373
374 int SwitchLayoutsBetweenClasses(textclass_type c1, textclass_type c2,
375         ParagraphList & pars, ErrorList & errorlist)
376 {
377         BOOST_ASSERT(!pars.empty());
378         int ret = 0;
379         if (c1 == c2)
380                 return ret;
381
382         LyXTextClass const & tclass1 = textclasslist[c1];
383         LyXTextClass const & tclass2 = textclasslist[c2];
384
385         InsetText in;
386         std::swap(in.paragraphs(), pars);
387
388         ParIterator end = par_iterator_end(in);
389         for (ParIterator it = par_iterator_begin(in); it != end; ++it) {
390                 string const name = it->layout()->name();
391                 bool hasLayout = tclass2.hasLayout(name);
392
393                 if (hasLayout)
394                         it->layout(tclass2[name]);
395                 else
396                         it->layout(tclass2.defaultLayout());
397
398                 if (!hasLayout && name != tclass1.defaultLayoutName()) {
399                         ++ret;
400                         string const s = bformat(
401                                 _("Layout had to be changed from\n%1$s to %2$s\n"
402                                 "because of class conversion from\n%3$s to %4$s"),
403                          name, it->layout()->name(), tclass1.name(), tclass2.name());
404                         // To warn the user that something had to be done.
405                         errorlist.push_back(ErrorItem("Changed Layout", s,
406                                                       it->id(), 0,
407                                                       it->size()));
408                 }
409         }
410         std::swap(in.paragraphs(), pars);
411         return ret;
412 }
413
414
415 std::vector<string> const availableSelections(Buffer const & buffer)
416 {
417         vector<string> selList;
418
419         CutStack::const_iterator cit = theCuts.begin();
420         CutStack::const_iterator end = theCuts.end();
421         for (; cit != end; ++cit) {
422                 // we do not use cit-> here because gcc 2.9x does not
423                 // like it (JMarc)
424                 ParagraphList const & pars = (*cit).first;
425                 string asciiSel;
426                 ParagraphList::const_iterator pit = pars.begin();
427                 ParagraphList::const_iterator pend = pars.end();
428                 for (; pit != pend; ++pit) {
429                         asciiSel += pit->asString(buffer, false);
430                         if (asciiSel.size() > 25) {
431                                 asciiSel.replace(22, string::npos, "...");
432                                 break;
433                         }
434                 }
435
436                 selList.push_back(asciiSel);
437         }
438
439         return selList;
440 }
441
442
443 int nrOfParagraphs()
444 {
445         return theCuts.empty() ? 0 : theCuts[0].first.size();
446 }
447
448
449 void cutSelection(LCursor & cur, bool doclear, bool realcut)
450 {
451         if (cur.inTexted()) {
452                 LyXText * text = cur.text();
453                 BOOST_ASSERT(text);
454                 // Stuff what we got on the clipboard. Even if there is no selection.
455
456                 // There is a problem with having the stuffing here in that the
457                 // larger the selection the slower LyX will get. This can be
458                 // solved by running the line below only when the selection has
459                 // finished. The solution used currently just works, to make it
460                 // faster we need to be more clever and probably also have more
461                 // calls to stuffClipboard. (Lgb)
462                 cur.bv().stuffClipboard(cur.selectionAsString(true));
463
464                 // This doesn't make sense, if there is no selection
465                 if (!cur.selection())
466                         return;
467
468                 // OK, we have a selection. This is always between cur.selBegin()
469                 // and cur.selEnd()
470
471                 // make sure that the depth behind the selection are restored, too
472                 recordUndoSelection(cur);
473                 pit_type begpit = cur.selBegin().pit();
474                 pit_type endpit = cur.selEnd().pit();
475
476                 int endpos = cur.selEnd().pos();
477
478                 BufferParams const & bp = cur.buffer().params();
479                 if (realcut) {
480                         copySelectionHelper(text->paragraphs(),
481                                 begpit, endpit,
482                                 cur.selBegin().pos(), endpos,
483                                 bp.textclass);
484                 }
485
486                 boost::tie(endpit, endpos) =
487                         eraseSelectionHelper(bp,
488                                 text->paragraphs(),
489                                 begpit, endpit,
490                                 cur.selBegin().pos(), endpos,
491                                 doclear);
492
493                 // sometimes necessary
494                 if (doclear)
495                         text->paragraphs()[begpit].stripLeadingSpaces();
496
497                 // cutSelection can invalidate the cursor so we need to set
498                 // it anew. (Lgb)
499                 // we prefer the end for when tracking changes
500                 cur.pos() = endpos;
501                 cur.pit() = endpit;
502
503                 // need a valid cursor. (Lgb)
504                 cur.clearSelection();
505                 text->updateCounters();
506         }
507
508         if (cur.inMathed()) {
509                 lyxerr << "cutSelection in mathed" << endl;
510                 LCursor tmp = cur;
511                 copySelection(cur);
512                 cur.selection() = false;
513                 eraseSelection(tmp);
514         }
515 }
516
517
518 void copySelection(LCursor & cur)
519 {
520         // stuff the selection onto the X clipboard, from an explicit copy request
521         cur.bv().stuffClipboard(cur.selectionAsString(true));
522
523         // this doesn't make sense, if there is no selection
524         if (!cur.selection())
525                 return;
526
527         if (cur.inTexted()) {
528                 LyXText * text = cur.text();
529                 BOOST_ASSERT(text);
530                 // ok we have a selection. This is always between cur.selBegin()
531                 // and sel_end cursor
532
533                 // copy behind a space if there is one
534                 ParagraphList & pars = text->paragraphs();
535                 pos_type pos = cur.selBegin().pos();
536                 pit_type par = cur.selBegin().pit();
537                 while (pos < pars[par].size()
538                                          && pars[par].isLineSeparator(pos)
539                                          && (par != cur.selEnd().pit() || pos < cur.selEnd().pos()))
540                         ++pos;
541
542                 copySelectionHelper(pars, par, cur.selEnd().pit(),
543                         pos, cur.selEnd().pos(), cur.buffer().params().textclass);
544         }
545
546         if (cur.inMathed()) {
547                 lyxerr << "copySelection in mathed" << endl;
548                 ParagraphList pars;
549                 pars.push_back(Paragraph());
550                 BufferParams const & bp = cur.buffer().params();
551                 pars.back().layout(bp.getLyXTextClass().defaultLayout());
552                 for_each(pars.begin(), pars.end(), resetOwnerAndChanges());
553                 pars.back().insert(0, grabSelection(cur), LyXFont());
554                 theCuts.push(make_pair(pars, bp.textclass));
555         }
556 }
557
558
559 std::string getSelection(Buffer const & buf, size_t sel_index)
560 {
561         return sel_index < theCuts.size()
562                 ? theCuts[sel_index].first.back().asString(buf, false)
563                 : string();
564 }
565
566
567 void pasteSelection(LCursor & cur, size_t sel_index)
568 {
569         // this does not make sense, if there is nothing to paste
570         lyxerr << "#### pasteSelection " << sel_index << endl;
571         if (!checkPastePossible(sel_index))
572                 return;
573
574         if (cur.inTexted()) {
575                 LyXText * text = cur.text();
576                 BOOST_ASSERT(text);
577
578                 recordUndo(cur);
579
580                 pit_type endpit;
581                 PitPosPair ppp;
582
583                 ErrorList el;
584
585                 boost::tie(ppp, endpit) =
586                         pasteSelectionHelper(cur.buffer(),
587                                                                 text->paragraphs(),
588                                                                 cur.pit(), cur.pos(),
589                                                                 cur.buffer().params().textclass,
590                                                                 sel_index, el);
591                 bufferErrors(cur.buffer(), el);
592                 cur.bv().showErrorList(_("Paste"));
593
594                 cur.clearSelection();
595                 cur.resetAnchor();
596                 text->setCursor(cur, ppp.first, ppp.second);
597                 cur.setSelection();
598                 text->updateCounters();
599         }
600
601         if (cur.inMathed()) {
602                 lyxerr << "### should be handled in MathNest/GridInset" << endl;
603         }
604 }
605
606
607 void setSelectionRange(LCursor & cur, pos_type length)
608 {
609         LyXText * text = cur.text();
610         BOOST_ASSERT(text);
611         if (!length)
612                 return;
613         cur.resetAnchor();
614         while (length--)
615                 text->cursorRight(cur);
616         cur.setSelection();
617 }
618
619
620 // simple replacing. The font of the first selected character is used
621 void replaceSelectionWithString(LCursor & cur, string const & str)
622 {
623         LyXText * text = cur.text();
624         BOOST_ASSERT(text);
625         recordUndo(cur);
626
627         // Get font setting before we cut
628         pos_type pos = cur.selEnd().pos();
629         Paragraph & par = text->getPar(cur.selEnd().pit());
630         LyXFont const font =
631                 par.getFontSettings(cur.buffer().params(), cur.selBegin().pos());
632
633         // Insert the new string
634         string::const_iterator cit = str.begin();
635         string::const_iterator end = str.end();
636         for (; cit != end; ++cit, ++pos)
637                 par.insertChar(pos, (*cit), font);
638
639         // Cut the selection
640         cutSelection(cur, true, false);
641 }
642
643
644 void replaceSelection(LCursor & cur)
645 {
646         if (cur.selection())
647                 cutSelection(cur, true, false);
648 }
649
650
651 // only used by the spellchecker
652 void replaceWord(LCursor & cur, string const & replacestring)
653 {
654         LyXText * text = cur.text();
655         BOOST_ASSERT(text);
656
657         replaceSelectionWithString(cur, replacestring);
658         setSelectionRange(cur, replacestring.length());
659
660         // Go back so that replacement string is also spellchecked
661         for (string::size_type i = 0; i < replacestring.length() + 1; ++i)
662                 text->cursorLeft(cur);
663 }
664
665
666 void eraseSelection(LCursor & cur)
667 {
668         //lyxerr << "LCursor::eraseSelection begin: " << cur << endl;
669         CursorSlice const & i1 = cur.selBegin();
670         CursorSlice const & i2 = cur.selEnd();
671         if (i1.inset().asMathInset()) {
672                 if (i1.idx() == i2.idx()) {
673                         i1.cell().erase(i1.pos(), i2.pos());
674                 } else {
675                         MathInset * p = i1.asMathInset();
676                         InsetBase::row_type r1, r2;
677                         InsetBase::col_type c1, c2;
678                         region(i1, i2, r1, r2, c1, c2);
679                         for (InsetBase::row_type row = r1; row <= r2; ++row)
680                                 for (InsetBase::col_type col = c1; col <= c2; ++col)
681                                         p->cell(p->index(row, col)).clear();
682                 }
683                 cur.back() = i1;
684                 cur.pos() = 0; // We've deleted the whole cell. Only pos 0 is valid.
685                 cur.resetAnchor();
686         } else {
687                 lyxerr << "can't erase this selection 1" << endl;
688         }
689         //lyxerr << "LCursor::eraseSelection end: " << cur << endl;
690 }
691
692
693 void selDel(LCursor & cur)
694 {
695         //lyxerr << "LCursor::selDel" << endl;
696         if (cur.selection()) {
697                 eraseSelection(cur);
698                 cur.selection() = false;
699         }
700 }
701
702
703 void selClearOrDel(LCursor & cur)
704 {
705         //lyxerr << "LCursor::selClearOrDel" << endl;
706         if (lyxrc.auto_region_delete)
707                 selDel(cur);
708         else
709                 cur.selection() = false;
710 }
711
712
713 string grabSelection(LCursor & cur)
714 {
715         if (!cur.selection())
716                 return string();
717
718         CursorSlice i1 = cur.selBegin();
719         CursorSlice i2 = cur.selEnd();
720
721         if (i1.idx() == i2.idx()) {
722                 if (i1.inset().asMathInset()) {
723                         MathArray::const_iterator it = i1.cell().begin();
724                         return asString(MathArray(it + i1.pos(), it + i2.pos()));
725                 } else {
726                         return "unknown selection 1";
727                 }
728         }
729
730         InsetBase::row_type r1, r2;
731         InsetBase::col_type c1, c2;
732         region(i1, i2, r1, r2, c1, c2);
733
734         string data;
735         if (i1.inset().asMathInset()) {
736                 for (InsetBase::row_type row = r1; row <= r2; ++row) {
737                         if (row > r1)
738                                 data += "\\\\";
739                         for (InsetBase::col_type col = c1; col <= c2; ++col) {
740                                 if (col > c1)
741                                         data += '&';
742                                 data += asString(i1.asMathInset()->
743                                         cell(i1.asMathInset()->index(row, col)));
744                         }
745                 }
746         } else {
747                 data = "unknown selection 2";
748         }
749         return data;
750 }
751
752
753 } // namespace cap
754 } // namespace lyx