[LyX/master] Store the AuthorList in the cut stack
Juergen Spitzmueller
spitz at lyx.org
Tue Feb 9 15:52:35 UTC 2021
commit e35574b3ce0fae8e449ed033d9902e9da125971b
Author: Juergen Spitzmueller <spitz at lyx.org>
Date: Tue Feb 9 16:54:21 2021 +0100
Store the AuthorList in the cut stack
Otherwise we crash when we paste text with markup into a different buffer
that has change tracking disabled (in this case, markup is now kept).
---
src/BufferView.cpp | 3 +-
src/CutAndPaste.cpp | 52 +++++++++++++++++++++++++----------------
src/CutAndPaste.h | 10 +++++--
src/Text.cpp | 1 +
src/lyxfind.cpp | 1 +
src/mathed/InsetMathGrid.cpp | 3 +-
src/mathed/InsetMathNest.cpp | 3 +-
7 files changed, 47 insertions(+), 26 deletions(-)
diff --git a/src/BufferView.cpp b/src/BufferView.cpp
index 8094c64..88400d7 100644
--- a/src/BufferView.cpp
+++ b/src/BufferView.cpp
@@ -2943,7 +2943,8 @@ void BufferView::insertLyXFile(FileName const & fname, bool const ignorelang)
buf.changeLanguage(buf.language(), d->cursor_.getFont().language());
buffer_.undo().recordUndo(d->cursor_);
cap::pasteParagraphList(d->cursor_, pars,
- buf.params().documentClassPtr(), el);
+ buf.params().documentClassPtr(),
+ buf.params().authors(), el);
res = _("Document %1$s inserted.");
} else {
res = _("Could not insert document %1$s");
diff --git a/src/CutAndPaste.cpp b/src/CutAndPaste.cpp
index 306be8b..150fd8a 100644
--- a/src/CutAndPaste.cpp
+++ b/src/CutAndPaste.cpp
@@ -77,8 +77,9 @@ namespace lyx {
namespace {
typedef pair<pit_type, int> PitPosPair;
+typedef pair<DocumentClassConstPtr, AuthorList > DocInfoPair;
-typedef limited_stack<pair<ParagraphList, DocumentClassConstPtr> > CutStack;
+typedef limited_stack<pair<ParagraphList, DocInfoPair > > CutStack;
CutStack theCuts(10);
// persistent selection, cleared until the next selection
@@ -601,10 +602,10 @@ Buffer * copyToTempBuffer(ParagraphList const & paragraphs, DocumentClassConstPt
void putClipboard(ParagraphList const & paragraphs,
- DocumentClassConstPtr docclass, docstring const & plaintext,
+ DocInfoPair docinfo, docstring const & plaintext,
BufferParams const & bp)
{
- Buffer * buffer = copyToTempBuffer(paragraphs, docclass);
+ Buffer * buffer = copyToTempBuffer(paragraphs, docinfo.first);
if (!buffer) // already asserted in copyToTempBuffer()
return;
@@ -613,11 +614,9 @@ void putClipboard(ParagraphList const & paragraphs,
// applications, the number that can parse it should go up in the future.
buffer->params().html_math_output = BufferParams::MathML;
- if (lyxrc.ct_markup_copied) {
- // Copy authors to the params. We need those pointers.
- for (Author const & a : bp.authors())
- buffer->params().authors().record(a);
- }
+ // Copy authors to the params. We need those pointers.
+ for (Author const & a : bp.authors())
+ buffer->params().authors().record(a);
// Make sure MarkAsExporting is deleted before buffer is
{
@@ -725,7 +724,7 @@ void copySelectionHelper(Buffer const & buf, Text const & text,
par.setInsetOwner(nullptr);
}
- cutstack.push(make_pair(copy_pars, dc));
+ cutstack.push(make_pair(copy_pars, make_pair(dc, buf.params().authors())));
}
} // namespace
@@ -1018,7 +1017,7 @@ void copyInset(Cursor const & cur, Inset * inset, docstring const & plaintext)
Font font(inherit_font, bp.language);
par.insertInset(0, inset, font, Change(Change::UNCHANGED));
pars.push_back(par);
- theCuts.push(make_pair(pars, bp.documentClassPtr()));
+ theCuts.push(make_pair(pars, make_pair(bp.documentClassPtr(), bp.authors())));
// stuff the selection onto the X clipboard, from an explicit copy request
putClipboard(theCuts[0].first, theCuts[0].second, plaintext, bp);
@@ -1065,7 +1064,7 @@ void copySelectionToStack(CursorData const & cur, CutStack & cutstack)
par.insert(0, grabSelection(cur), Font(sane_font, par.getParLanguage(bp)),
Change(Change::UNCHANGED));
pars.push_back(par);
- cutstack.push(make_pair(pars, bp.documentClassPtr()));
+ cutstack.push(make_pair(pars, make_pair(bp.documentClassPtr(), bp.authors())));
}
}
@@ -1123,7 +1122,7 @@ void copySelection(Cursor const & cur, docstring const & plaintext)
while (pars.size() > 1)
mergeParagraph(bp, pars, 0);
}
- theCuts.push(make_pair(pars, bp.documentClassPtr()));
+ theCuts.push(make_pair(pars, make_pair(bp.documentClassPtr(), bp.authors())));
} else {
copySelectionToStack(cur, theCuts);
}
@@ -1167,13 +1166,13 @@ void clearCutStack()
}
-docstring selection(size_t sel_index, DocumentClassConstPtr docclass, bool for_math)
+docstring selection(size_t sel_index, DocInfoPair docinfo, bool for_math)
{
if (sel_index >= theCuts.size())
return docstring();
unique_ptr<Buffer> buffer(copyToTempBuffer(theCuts[sel_index].first,
- docclass));
+ docinfo.first));
if (!buffer)
return docstring();
@@ -1186,9 +1185,14 @@ docstring selection(size_t sel_index, DocumentClassConstPtr docclass, bool for_m
void pasteParagraphList(Cursor & cur, ParagraphList const & parlist,
- DocumentClassConstPtr docclass, ErrorList & errorList,
+ DocumentClassConstPtr docclass, AuthorList const & authors,
+ ErrorList & errorList,
cap::BranchAction branchAction)
{
+ // Copy authors to the params. We need those pointers.
+ for (Author const & a : authors)
+ cur.buffer()->params().authors().record(a);
+
if (cur.inTexted()) {
Text * text = cur.text();
LBUFERR(text);
@@ -1213,7 +1217,8 @@ bool pasteFromStack(Cursor & cur, ErrorList & errorList, size_t sel_index)
cur.recordUndo();
pasteParagraphList(cur, theCuts[sel_index].first,
- theCuts[sel_index].second, errorList, BRANCH_ASK);
+ theCuts[sel_index].second.first, theCuts[sel_index].second.second,
+ errorList, BRANCH_ASK);
return true;
}
@@ -1226,7 +1231,8 @@ bool pasteFromTemp(Cursor & cur, ErrorList & errorList)
cur.recordUndo();
pasteParagraphList(cur, tempCut[0].first,
- tempCut[0].second, errorList, BRANCH_IGNORE);
+ tempCut[0].second.first, tempCut[0].second.second,
+ errorList, BRANCH_IGNORE);
return true;
}
@@ -1251,7 +1257,9 @@ bool pasteClipboardText(Cursor & cur, ErrorList & errorList, bool asParagraphs,
if (buffer.readString(lyx)) {
cur.recordUndo();
pasteParagraphList(cur, buffer.paragraphs(),
- buffer.params().documentClassPtr(), errorList);
+ buffer.params().documentClassPtr(),
+ buffer.params().authors(),
+ errorList);
return true;
}
}
@@ -1289,7 +1297,9 @@ bool pasteClipboardText(Cursor & cur, ErrorList & errorList, bool asParagraphs,
buffer.changeLanguage(buffer.language(), cur.getFont().language());
cur.recordUndo();
pasteParagraphList(cur, buffer.paragraphs(),
- buffer.params().documentClassPtr(), errorList);
+ buffer.params().documentClassPtr(),
+ buffer.params().authors(),
+ errorList);
return true;
}
}
@@ -1369,7 +1379,9 @@ void pasteSelection(Cursor & cur, ErrorList & errorList)
return;
cur.recordUndo();
pasteParagraphList(cur, selectionBuffer[0].first,
- selectionBuffer[0].second, errorList);
+ selectionBuffer[0].second.first,
+ selectionBuffer[0].second.second,
+ errorList);
}
diff --git a/src/CutAndPaste.h b/src/CutAndPaste.h
index 6ed17dc..e4ff08b 100644
--- a/src/CutAndPaste.h
+++ b/src/CutAndPaste.h
@@ -14,6 +14,7 @@
#ifndef CUTANDPASTE_H
#define CUTANDPASTE_H
+#include "Author.h"
#include "DocumentClassPtr.h"
#include "support/strfwd.h"
@@ -41,11 +42,13 @@ namespace cap {
std::vector<docstring> availableSelections(Buffer const *);
/// Get the number of available elements in the cut buffer.
size_type numberOfSelections();
+///
+typedef std::pair<DocumentClassConstPtr, AuthorList > DocInfoPair;
/**
* Get the sel_index-th element of the cut buffer in plain text format
* or, if \param for_math is true, in a format suitable for mathed.
*/
-docstring selection(size_t sel_index, DocumentClassConstPtr docclass, bool for_math = false);
+docstring selection(size_t sel_index, DocInfoPair docinfo, bool for_math = false);
/**
* Replace using the font of the first selected character and select
@@ -123,8 +126,9 @@ enum BranchAction {
/// Paste the paragraph list \p parlist at the position given by \p cur.
/// Does not handle undo. Does only work in text, not mathed.
void pasteParagraphList(Cursor & cur, ParagraphList const & parlist,
- DocumentClassConstPtr textclass, ErrorList & errorList,
- BranchAction branchAction = BRANCH_ASK);
+ DocumentClassConstPtr textclass, AuthorList const & authors,
+ ErrorList & errorList,
+ BranchAction branchAction = BRANCH_ASK);
/** Needed to switch between different classes. This works
diff --git a/src/Text.cpp b/src/Text.cpp
index f596f0d..579089d 100644
--- a/src/Text.cpp
+++ b/src/Text.cpp
@@ -1881,6 +1881,7 @@ bool Text::dissolveInset(Cursor & cur)
}
pasteParagraphList(cur, plist, b.params().documentClassPtr(),
+ b.params().authors(),
b.errorList("Paste"));
}
diff --git a/src/lyxfind.cpp b/src/lyxfind.cpp
index 8b39d8b..092375c 100644
--- a/src/lyxfind.cpp
+++ b/src/lyxfind.cpp
@@ -3999,6 +3999,7 @@ static int findAdvReplace(BufferView * bv, FindAndReplaceOptions const & opt, Ma
LYXERR(Debug::FIND, "Before pasteParagraphList() cur=" << cur << endl);
cap::pasteParagraphList(cur, repl_buffer.paragraphs(),
repl_buffer.params().documentClassPtr(),
+ repl_buffer.params().authors(),
bv->buffer().errorList("Paste"));
LYXERR(Debug::FIND, "After pasteParagraphList() cur=" << cur << endl);
sel_len = repl_buffer.paragraphs().begin()->size();
diff --git a/src/mathed/InsetMathGrid.cpp b/src/mathed/InsetMathGrid.cpp
index 3a8b376..90f53fd 100644
--- a/src/mathed/InsetMathGrid.cpp
+++ b/src/mathed/InsetMathGrid.cpp
@@ -1566,7 +1566,8 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
idocstringstream is(cmd.argument());
int n = 0;
is >> n;
- topaste = cap::selection(n, buffer().params().documentClassPtr(), true);
+ topaste = cap::selection(n, make_pair(buffer().params().documentClassPtr(),
+ buffer().params().authors()), true);
}
InsetMathGrid grid(buffer_, 1, 1);
if (!topaste.empty())
diff --git a/src/mathed/InsetMathNest.cpp b/src/mathed/InsetMathNest.cpp
index b999474..c6ea585 100644
--- a/src/mathed/InsetMathNest.cpp
+++ b/src/mathed/InsetMathNest.cpp
@@ -539,7 +539,8 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
size_t n = 0;
idocstringstream is(cmd.argument());
is >> n;
- topaste = cap::selection(n, buffer().params().documentClassPtr());
+ topaste = cap::selection(n, make_pair(buffer().params().documentClassPtr(),
+ buffer().params().authors()));
}
cur.niceInsert(topaste, parseflg, false);
cur.clearSelection(); // bug 393
More information about the lyx-cvs
mailing list