I introduced a regression in
c14b9e67 for pasting images:
If an image is on the clipboard both as PNG and HTML with just an url,
but no plain text, pasting would fail. The reason for this was that
text contents was detected (the HTML code), nd preferred, but actually
pasting it resulted in an empty string, since the HTML import could not
handle the url This error was not checked.
The solution is first to try text paste if both text and image content
is present, and then try image paste if the text failed.
-void pasteFromStack(Cursor & cur, ErrorList & errorList, size_t sel_index)
+bool pasteFromStack(Cursor & cur, ErrorList & errorList, size_t sel_index)
{
// this does not make sense, if there is nothing to paste
if (!checkPastePossible(sel_index))
{
// this does not make sense, if there is nothing to paste
if (!checkPastePossible(sel_index))
cur.recordUndo();
pasteParagraphList(cur, theCuts[sel_index].first,
theCuts[sel_index].second, errorList);
cur.recordUndo();
pasteParagraphList(cur, theCuts[sel_index].first,
theCuts[sel_index].second, errorList);
-void pasteClipboardText(Cursor & cur, ErrorList & errorList, bool asParagraphs,
+bool pasteClipboardText(Cursor & cur, ErrorList & errorList, bool asParagraphs,
Clipboard::TextType type)
{
// Use internal clipboard if it is the most recent one
// This overrides asParagraphs and type on purpose!
Clipboard::TextType type)
{
// Use internal clipboard if it is the most recent one
// This overrides asParagraphs and type on purpose!
- if (theClipboard().isInternal()) {
- pasteFromStack(cur, errorList, 0);
- return;
- }
+ if (theClipboard().isInternal())
+ return pasteFromStack(cur, errorList, 0);
// First try LyX format
if ((type == Clipboard::LyXTextType ||
// First try LyX format
if ((type == Clipboard::LyXTextType ||
cur.recordUndo();
pasteParagraphList(cur, buffer.paragraphs(),
buffer.params().documentClassPtr(), errorList);
cur.recordUndo();
pasteParagraphList(cur, buffer.paragraphs(),
buffer.params().documentClassPtr(), errorList);
// Buffer buffer(string(), false);
Buffer buffer("", false);
buffer.setUnnamed(true);
// Buffer buffer(string(), false);
Buffer buffer("", false);
buffer.setUnnamed(true);
- if (buffer.importString(names[i], text, errorList)) {
+ available = buffer.importString(names[i], text, errorList);
+ if (available)
+ available = !buffer.paragraphs().empty();
+ if (available && !buffer.paragraphs()[0].empty()) {
cur.recordUndo();
pasteParagraphList(cur, buffer.paragraphs(),
buffer.params().documentClassPtr(), errorList);
cur.recordUndo();
pasteParagraphList(cur, buffer.paragraphs(),
buffer.params().documentClassPtr(), errorList);
// Then try plain text
docstring const text = theClipboard().getAsText(Clipboard::PlainTextType);
if (text.empty())
// Then try plain text
docstring const text = theClipboard().getAsText(Clipboard::PlainTextType);
if (text.empty())
cur.recordUndo();
if (asParagraphs)
cur.text()->insertStringAsParagraphs(cur, text, cur.current_font);
else
cur.text()->insertStringAsLines(cur, text, cur.current_font);
cur.recordUndo();
if (asParagraphs)
cur.text()->insertStringAsParagraphs(cur, text, cur.current_font);
else
cur.text()->insertStringAsLines(cur, text, cur.current_font);
/// (internal or external: which is newer).
/// Does handle undo. Does only work in text, not mathed.
/// \p asParagraphs is only considered if plain text is pasted.
/// (internal or external: which is newer).
/// Does handle undo. Does only work in text, not mathed.
/// \p asParagraphs is only considered if plain text is pasted.
-void pasteClipboardText(Cursor & cur, ErrorList & errorList, bool asParagraphs,
+bool pasteClipboardText(Cursor & cur, ErrorList & errorList, bool asParagraphs,
Clipboard::TextType preferedType = Clipboard::LyXOrPlainTextType);
/// Replace the current selection with the clipboard contents as graphic.
/// Does handle undo. Does only work in text, not mathed.
Clipboard::TextType preferedType = Clipboard::LyXOrPlainTextType);
/// Replace the current selection with the clipboard contents as graphic.
/// Does handle undo. Does only work in text, not mathed.
Clipboard::GraphicsType preferedType = Clipboard::AnyGraphicsType);
/// Replace the current selection with cut buffer \c sel_index
/// Does handle undo. Does only work in text, not mathed.
Clipboard::GraphicsType preferedType = Clipboard::AnyGraphicsType);
/// Replace the current selection with cut buffer \c sel_index
/// Does handle undo. Does only work in text, not mathed.
-void pasteFromStack(Cursor & cur, ErrorList & errorList, size_t sel_index);
+bool pasteFromStack(Cursor & cur, ErrorList & errorList, size_t sel_index);
/// Paste the clipboard as simple text, removing any formatting
void pasteSimpleText(Cursor & cur, bool asParagraphs);
/// Paste the clipboard as simple text, removing any formatting
void pasteSimpleText(Cursor & cur, bool asParagraphs);
// without argument?
string const arg = to_utf8(cmd.argument());
if (arg.empty()) {
// without argument?
string const arg = to_utf8(cmd.argument());
if (arg.empty()) {
+ bool tryGraphics = true;
if (theClipboard().isInternal())
pasteFromStack(cur, bv->buffer().errorList("Paste"), 0);
if (theClipboard().isInternal())
pasteFromStack(cur, bv->buffer().errorList("Paste"), 0);
- else if (theClipboard().hasGraphicsContents()
- && !theClipboard().hasTextContents())
+ else if (theClipboard().hasTextContents()) {
+ if (pasteClipboardText(cur, bv->buffer().errorList("Paste"),
+ true, Clipboard::AnyTextType))
+ tryGraphics = false;
+ }
+ if (tryGraphics && theClipboard().hasGraphicsContents())
pasteClipboardGraphics(cur, bv->buffer().errorList("Paste"));
pasteClipboardGraphics(cur, bv->buffer().errorList("Paste"));
- else
- pasteClipboardText(cur, bv->buffer().errorList("Paste"), true);
} else if (isStrUnsignedInt(arg)) {
// we have a numerical argument
pasteFromStack(cur, bv->buffer().errorList("Paste"),
} else if (isStrUnsignedInt(arg)) {
// we have a numerical argument
pasteFromStack(cur, bv->buffer().errorList("Paste"),