]> git.lyx.org Git - lyx.git/blobdiff - src/CutAndPaste.cpp
Fix bug 5374
[lyx.git] / src / CutAndPaste.cpp
index 2cadd1deebf39073d75ede41c749179f9b13f9f1..2f1a715d084608ac194fb568e9c93e73cc3a3f72 100644 (file)
@@ -96,7 +96,13 @@ pasteSelectionHelper(Cursor & cur, ParagraphList const & parlist,
        Buffer const & buffer = cur.buffer();
        pit_type pit = cur.pit();
        pos_type pos = cur.pos();
-       ParagraphList & pars = cur.text()->paragraphs();
+       InsetText * target_inset = cur.inset().asInsetText();
+       if (!target_inset) {
+               InsetTabular * it = cur.inset().asInsetTabular();
+               target_inset = it? it->cell(cur.idx())->asInsetText() : 0;
+       }
+       LASSERT(target_inset, return make_pair(PitPosPair(pit, pos), pit));
+       ParagraphList & pars = target_inset->paragraphs();
 
        if (parlist.empty())
                return make_pair(PitPosPair(pit, pos), pit);
@@ -113,14 +119,14 @@ pasteSelectionHelper(Cursor & cur, ParagraphList const & parlist,
 
        // Convert newline to paragraph break in ERT inset.
        // This should not be here!
-       Inset * inset = pars[pit].inInset();
-       if (inset && (inset->lyxCode() == ERT_CODE ||
-                       inset->lyxCode() == LISTINGS_CODE)) {
+       InsetCode const code = target_inset->lyxCode();
+       if (code == ERT_CODE || code == LISTINGS_CODE) {
                for (size_t i = 0; i != insertion.size(); ++i) {
                        for (pos_type j = 0; j != insertion[i].size(); ++j) {
                                if (insertion[i].isNewline(j)) {
                                        // do not track deletion of newline
                                        insertion[i].eraseChar(j, false);
+                                       insertion[i].setInsetOwner(target_inset);
                                        breakParagraphConservative(
                                                        buffer.params(),
                                                        insertion, i, j);
@@ -190,11 +196,11 @@ pasteSelectionHelper(Cursor & cur, ParagraphList const & parlist,
                        max_depth = tmpbuf->getMaxDepthAfter();
 
                // Set the inset owner of this paragraph.
-               tmpbuf->setInsetOwner(pars[pit].inInset());
+               tmpbuf->setInsetOwner(target_inset);
                for (pos_type i = 0; i < tmpbuf->size(); ++i) {
                        // do not track deletion of invalid insets
                        if (Inset * inset = tmpbuf->getInset(i))
-                               if (!pars[pit].insetAllowed(inset->lyxCode()))
+                               if (!target_inset->insetAllowed(inset->lyxCode()))
                                        tmpbuf->eraseChar(i--, false);
                }
 
@@ -387,7 +393,7 @@ void putClipboard(ParagraphList const & paragraphs,
 }
 
 
-void copySelectionHelper(Buffer const & buf, ParagraphList & pars,
+void copySelectionHelper(Buffer const & buf, ParagraphList const & pars,
        pit_type startpit, pit_type endpit,
        int start, int end, DocumentClass const * const dc, CutStack & cutstack)
 {
@@ -675,7 +681,7 @@ void cutSelection(Cursor & cur, bool doclear, bool realcut)
 }
 
 
-void copySelection(Cursor & cur)
+void copySelection(Cursor const & cur)
 {
        copySelection(cur, cur.selectionAsString(true));
 }
@@ -683,7 +689,7 @@ void copySelection(Cursor & cur)
 
 namespace {
 
-void copySelectionToStack(Cursor & cur, CutStack & cutstack)
+void copySelectionToStack(Cursor const & cur, CutStack & cutstack)
 {
        // this doesn't make sense, if there is no selection
        if (!cur.selection())
@@ -737,7 +743,7 @@ void copySelectionToStack()
 }
 
 
-void copySelection(Cursor & cur, docstring const & plaintext)
+void copySelection(Cursor const & cur, docstring const & plaintext)
 {
        // In tablemode, because copy and paste actually use special table stack
        // we do not attempt to get selected paragraphs under cursor. Instead, a
@@ -760,7 +766,7 @@ void copySelection(Cursor & cur, docstring const & plaintext)
 }
 
 
-void saveSelection(Cursor & cur)
+void saveSelection(Cursor const & cur)
 {
        // This function is called, not when a selection is formed, but when
        // a selection is cleared. Therefore, multiple keyboard selection
@@ -795,7 +801,7 @@ void clearCutStack()
 docstring selection(size_t sel_index)
 {
        return sel_index < theCuts.size()
-               ? theCuts[sel_index].first.back().asString(AS_STR_INSETS)
+               ? theCuts[sel_index].first.back().asString(AS_STR_INSETS | AS_STR_NEWLINES)
                : docstring();
 }
 
@@ -909,7 +915,7 @@ void replaceSelectionWithString(Cursor & cur, docstring const & str, bool backwa
        DocIterator selbeg = cur.selectionBegin();
 
        // Get font setting before we cut
-       Font const font =
+       Font const font =
                selbeg.paragraph().getFontSettings(cur.buffer().params(), selbeg.pos());
 
        // Insert the new string
@@ -987,7 +993,7 @@ void selClearOrDel(Cursor & cur)
        if (lyxrc.auto_region_delete)
                selDel(cur);
        else
-               cur.selection() = false;
+               cur.setSelection(false);
 }