]> git.lyx.org Git - features.git/commitdiff
Fix image pasting regression
authorGeorg Baum <baum@lyx.org>
Sat, 13 Jul 2013 08:29:54 +0000 (10:29 +0200)
committerVincent van Ravesteijn <vfr@lyx.org>
Sat, 13 Jul 2013 20:44:20 +0000 (22:44 +0200)
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.

src/CutAndPaste.cpp
src/CutAndPaste.h
src/Text3.cpp

index ce6164d4ad09b2dbb251100e40eda5419d9e5aef..874b3411a51c4e9fb1d048a7d1b2a04c60ba86fa 100644 (file)
@@ -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;
 }
 
 
index 802319d0d37297f452a36adb392d94f36f8e3c4c..4149f1983b135a0465d72e6e6a7041513f0baaa7 100644 (file)
@@ -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);
 
index 70453620ac9251541b382b1614aa453fb365ed3e..34f6af1e5b48448ee1b1b454043c5daacb63bcc8 100644 (file)
@@ -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"),