mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
fix paste image issue
- Will detect whether there is only <img> in html; - Detect local file when handling text;
This commit is contained in:
parent
2ff9c607dd
commit
d3a5642d06
@ -1580,3 +1580,9 @@ QString VUtils::promptForFileName(const QString &p_title,
|
|||||||
|
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool VUtils::onlyHasImgInHtml(const QString &p_html)
|
||||||
|
{
|
||||||
|
// Tricky.
|
||||||
|
return !p_html.contains("<p ");
|
||||||
|
}
|
||||||
|
@ -339,6 +339,9 @@ public:
|
|||||||
const QString &p_dir,
|
const QString &p_dir,
|
||||||
QWidget *p_parent = nullptr);
|
QWidget *p_parent = nullptr);
|
||||||
|
|
||||||
|
// Whether @p_html has only <img> content.
|
||||||
|
static bool onlyHasImgInHtml(const QString &p_html);
|
||||||
|
|
||||||
// Regular expression for image link.
|
// Regular expression for image link.
|
||||||
// 
|
// 
|
||||||
// Captured texts (need to be trimmed):
|
// Captured texts (need to be trimmed):
|
||||||
|
@ -766,7 +766,8 @@ void VMdEditor::insertFromMimeData(const QMimeData *p_source)
|
|||||||
if (p_source->hasHtml()) {
|
if (p_source->hasHtml()) {
|
||||||
// Handle <img>.
|
// Handle <img>.
|
||||||
QRegExp reg("<img ([^>]*)src=\"([^\"]+)\"([^>]*)>");
|
QRegExp reg("<img ([^>]*)src=\"([^\"]+)\"([^>]*)>");
|
||||||
if (reg.indexIn(p_source->html()) != -1) {
|
QString html(p_source->html());
|
||||||
|
if (reg.indexIn(html) != -1 && VUtils::onlyHasImgInHtml(html)) {
|
||||||
if (p_source->hasImage()) {
|
if (p_source->hasImage()) {
|
||||||
// Both image data and URL are embedded.
|
// Both image data and URL are embedded.
|
||||||
VSelectDialog dialog(tr("Insert From Clipboard"), this);
|
VSelectDialog dialog(tr("Insert From Clipboard"), this);
|
||||||
@ -858,9 +859,15 @@ void VMdEditor::insertFromMimeData(const QMimeData *p_source)
|
|||||||
int selection = dialog.getSelection();
|
int selection = dialog.getSelection();
|
||||||
if (selection == 0) {
|
if (selection == 0) {
|
||||||
// Insert as image.
|
// Insert as image.
|
||||||
QUrl url(text);
|
QUrl url;
|
||||||
|
if (QFileInfo::exists(text)) {
|
||||||
|
url = QUrl::fromLocalFile(text);
|
||||||
|
} else {
|
||||||
|
url = QUrl(text);
|
||||||
|
}
|
||||||
|
|
||||||
if (url.isValid()) {
|
if (url.isValid()) {
|
||||||
m_editOps->insertImageFromURL(QUrl(text));
|
m_editOps->insertImageFromURL(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user