mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 05:16:21 +00:00
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.
This commit is contained in:
parent
6e69a61d00
commit
c0ea37f337
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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"),
|
||||
|
Loading…
Reference in New Issue
Block a user