From 337173f1dc79943255cb2177868cd2538dbd8974 Mon Sep 17 00:00:00 2001 From: AngryFender Date: Sat, 7 Oct 2023 23:35:14 +0100 Subject: [PATCH] Github Issue #101: Loop in showMKSymbolsFromSavedBlocks is called again before finishing its iteration. This is due to combination of QTextCursor::insertText and QScrollBar::valueChanged signal where signal is given more priority when its emitted in the middle of the loop. So inorder not to repeat the same element twice just --- mktextdocument.cpp | 4 ++-- views_handler.cpp | 14 +++++++------- views_handler.h | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/mktextdocument.cpp b/mktextdocument.cpp index 91cd556..4661dee 100644 --- a/mktextdocument.cpp +++ b/mktextdocument.cpp @@ -880,8 +880,8 @@ void MkTextDocument::showMKSymbolsFromSavedBlocks(QRect *rect, int cursorBlockNo FormatData* formatData = dynamic_cast(data); if(formatData){ if(formatData->isHidden()){ - showAllFormatSymbolsInTextBlock(block, formatData); formatData->setHidden(false); + showAllFormatSymbolsInTextBlock(block, formatData); } } } @@ -904,7 +904,7 @@ void MkTextDocument::hideMKSymbolsFromDrawingRect(QRect rect, bool hasSelection, } for(QTextBlock block = this->begin(); block != this->end(); block = block.next()){ - if( layout->blockBoundingRect(block).bottom() < (rect.bottom()+40) && layout->blockBoundingRect(block).top() > (rect.top()-15)){ + if( layout->blockBoundingRect(block).bottom() < (rect.bottom()+50) && layout->blockBoundingRect(block).top() > (rect.top()-40)){ int currentBlockNumber = block.blockNumber(); QTextBlockUserData* data =block.userData(); diff --git a/views_handler.cpp b/views_handler.cpp index 32a4be2..1a79fe1 100644 --- a/views_handler.cpp +++ b/views_handler.cpp @@ -288,6 +288,7 @@ void ViewsHandler::setCurrentDocument(const QFileInfo &fileInfo) viewText->setDocument(currentDocument.data()); viewText->initialialCursorPosition(); + return true; }else{ currentDocument->setFilePath(fileInfo.absoluteFilePath()); @@ -305,20 +306,15 @@ void ViewsHandler::setCurrentDocument(const QFileInfo &fileInfo) cursor.movePosition(QTextCursor::NextCharacter,QTextCursor::MoveAnchor); } connectDocument(); - QObject::disconnect(viewText,&MkEdit::drawTextBlocks, - currentDocument.data(),&MkTextDocument::drawTextBlocksHandler); - viewText->setTextCursor(cursor); - viewText->ensureCursorVisible(); - QObject::connect(viewText,&MkEdit::drawTextBlocks, - currentDocument.data(),&MkTextDocument::drawTextBlocksHandler); + return false; } } void ViewsHandler::fileDisplay(const QModelIndex& index) { QModelIndex sourceIndex = proxyModel.mapToSource(index); - setCurrentDocument(modelTree.fileInfo(sourceIndex)); + bool newDocument = setCurrentDocument(modelTree.fileInfo(sourceIndex)); QString fullPath = this->currentDocument->getFilePath(); @@ -327,6 +323,10 @@ void ViewsHandler::fileDisplay(const QModelIndex& index) fullPath.replace(vaultPath, ""); } emit updateRecentFile(fullPath); + + if(!newDocument){ + viewText->ensureCursorVisible(); + } } void ViewsHandler::fileSaveHandle() diff --git a/views_handler.h b/views_handler.h index 6ea73ba..11d5263 100644 --- a/views_handler.h +++ b/views_handler.h @@ -84,7 +84,7 @@ public slots: void disconnectDocument(); QString getFileContent(QFile& file); - void setCurrentDocument(const QFileInfo &fileInfo); + bool setCurrentDocument(const QFileInfo &fileInfo); MkTextDocument mkGuiDocument; Highlighter highlighter; QString searchedFilename;