mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
bugfix: clear image preview blocks having unmatched image path
The syntax highlighter could not recognize image links with spaces in the URL. When clearing orphan image preview block, we need to clear thoes blocks which having unmatched image path. Fix issue: after inserting spaces in the URL of an image link, the preview block still exists. Signed-off-by: Le Tan <tamlokveer@gmail.com>
This commit is contained in:
parent
180ab46367
commit
010f4245f6
@ -268,14 +268,28 @@ bool VMdEdit::isOrphanImagePreviewBlock(QTextBlock p_block)
|
||||
{
|
||||
if (isImagePreviewBlock(p_block)) {
|
||||
// It is an orphan image preview block if previous block is not
|
||||
// a block need to preview (containing exactly one image).
|
||||
// a block need to preview (containing exactly one image) or the image
|
||||
// paths are not equal to each other.
|
||||
QTextBlock prevBlock = p_block.previous();
|
||||
if (prevBlock.isValid()) {
|
||||
if (fetchImageToPreview(prevBlock.text()).isEmpty()) {
|
||||
QString imageLink = fetchImageToPreview(prevBlock.text());
|
||||
if (imageLink.isEmpty()) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
QString imagePath = QDir(m_file->retriveBasePath()).filePath(imageLink);
|
||||
|
||||
// Get image preview block's image path.
|
||||
QTextCursor cursor(p_block);
|
||||
int shift = p_block.text().indexOf(QChar::ObjectReplacementCharacter);
|
||||
if (shift > 0) {
|
||||
cursor.movePosition(QTextCursor::Right, QTextCursor::MoveAnchor,
|
||||
shift + 1);
|
||||
}
|
||||
QTextImageFormat format = cursor.charFormat().toImageFormat();
|
||||
Q_ASSERT(format.isValid());
|
||||
QString curPath = format.property(ImagePath).toString();
|
||||
|
||||
return curPath != imagePath;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user