Skip to content

Commit

Permalink
#3184 fix: crash when accessing mimeData
Browse files Browse the repository at this point in the history
Signed-off-by: Patrizio Bekerle <[email protected]>
  • Loading branch information
pbek committed Dec 23, 2024
1 parent 5484624 commit a6bbccc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# QOwnNotes Changelog

## 24.12.6
- A possible crash when pasting HTML as Markdown or pasting as text file was fixed
(for [#3184](https://github.com/pbek/QOwnNotes/issues/3184))

## 24.12.5
- Both note links and the link dialog are now supporting also heading 1, not only
heading 2 and up, as long `#` headings are used (for [#3181](https://github.com/pbek/QOwnNotes/issues/3181))
Expand Down
9 changes: 7 additions & 2 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7156,15 +7156,20 @@ void MainWindow::handleInsertingFromMimeData(const QMimeData *mimeData) {
const QPoint globalPos = textEdit->mapToGlobal(rect.bottomRight());
QMenu menu;

// We need to fetch the text and html from the mime data here, because the mimeData object
// may not be available anymore after the menu was closed and accessing it may cause a crash
const auto text = mimeData->text();
const auto html = mimeData->html();

QAction *htmlAction = menu.addAction(tr("Paste &HTML as Markdown"));
QAction *textAttachmentAction = menu.addAction(tr("Paste as &text file attachment"));
QAction *selectedItem = menu.exec(globalPos);

if (selectedItem == htmlAction) {
insertHtmlAsMarkdownIntoCurrentNote(mimeData->html());
insertHtmlAsMarkdownIntoCurrentNote(html);
} else if (selectedItem == textAttachmentAction) {
// Insert text as attachment file
insertTextAsAttachment(mimeData->text());
insertTextAsAttachment(text);
}
}
}
Expand Down

0 comments on commit a6bbccc

Please sign in to comment.