From: Georg Baum Date: Sat, 13 Jul 2013 08:29:54 +0000 (+0200) Subject: Fix image pasting regression X-Git-Tag: 2.1.0beta1~4 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=c0ea37f33791515a1991151581021092b2022595;p=features.git Fix image pasting regression 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. --- diff --git a/src/CutAndPaste.cpp b/src/CutAndPaste.cpp index ce6164d4ad..874b3411a5 100644 --- a/src/CutAndPaste.cpp +++ b/src/CutAndPaste.cpp @@ -1053,27 +1053,26 @@ void pasteParagraphList(Cursor & cur, ParagraphList const & parlist, } -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)) - return; + return false; cur.recordUndo(); pasteParagraphList(cur, theCuts[sel_index].first, theCuts[sel_index].second, errorList); + return true; } -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! - if (theClipboard().isInternal()) { - pasteFromStack(cur, errorList, 0); - return; - } + if (theClipboard().isInternal()) + return pasteFromStack(cur, errorList, 0); // First try LyX format if ((type == Clipboard::LyXTextType || @@ -1090,7 +1089,7 @@ void pasteClipboardText(Cursor & cur, ErrorList & errorList, bool asParagraphs, cur.recordUndo(); pasteParagraphList(cur, buffer.paragraphs(), buffer.params().documentClassPtr(), errorList); - return; + return true; } } } @@ -1119,11 +1118,14 @@ void pasteClipboardText(Cursor & cur, ErrorList & errorList, bool asParagraphs, // 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); - return; + return true; } } } @@ -1132,12 +1134,13 @@ void pasteClipboardText(Cursor & cur, ErrorList & errorList, bool asParagraphs, // Then try plain text docstring const text = theClipboard().getAsText(Clipboard::PlainTextType); if (text.empty()) - return; + return false; cur.recordUndo(); if (asParagraphs) cur.text()->insertStringAsParagraphs(cur, text, cur.current_font); else cur.text()->insertStringAsLines(cur, text, cur.current_font); + return true; } diff --git a/src/CutAndPaste.h b/src/CutAndPaste.h index 802319d0d3..4149f1983b 100644 --- a/src/CutAndPaste.h +++ b/src/CutAndPaste.h @@ -88,7 +88,7 @@ void pasteSelection(Cursor & cur, ErrorList &); /// (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. @@ -96,7 +96,7 @@ void pasteClipboardGraphics(Cursor & cur, ErrorList & errorList, 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); diff --git a/src/Text3.cpp b/src/Text3.cpp index 70453620ac..34f6af1e5b 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -1226,13 +1226,16 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) // 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); - 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")); - else - pasteClipboardText(cur, bv->buffer().errorList("Paste"), true); } else if (isStrUnsignedInt(arg)) { // we have a numerical argument pasteFromStack(cur, bv->buffer().errorList("Paste"),