Skip to content

Commit

Permalink
Github Issue #101: Loop in showMKSymbolsFromSavedBlocks is called aga…
Browse files Browse the repository at this point in the history
…in 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
  • Loading branch information
AngryFender committed Oct 7, 2023
1 parent 6819f0e commit 337173f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions mktextdocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -880,8 +880,8 @@ void MkTextDocument::showMKSymbolsFromSavedBlocks(QRect *rect, int cursorBlockNo
FormatData* formatData = dynamic_cast<FormatData*>(data);
if(formatData){
if(formatData->isHidden()){
showAllFormatSymbolsInTextBlock(block, formatData);
formatData->setHidden(false);
showAllFormatSymbolsInTextBlock(block, formatData);
}
}
}
Expand All @@ -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();
Expand Down
14 changes: 7 additions & 7 deletions views_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ void ViewsHandler::setCurrentDocument(const QFileInfo &fileInfo)

viewText->setDocument(currentDocument.data());
viewText->initialialCursorPosition();
return true;
}else{

currentDocument->setFilePath(fileInfo.absoluteFilePath());
Expand All @@ -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();

Expand All @@ -327,6 +323,10 @@ void ViewsHandler::fileDisplay(const QModelIndex& index)
fullPath.replace(vaultPath, "");
}
emit updateRecentFile(fullPath);

if(!newDocument){
viewText->ensureCursorVisible();
}
}

void ViewsHandler::fileSaveHandle()
Expand Down
2 changes: 1 addition & 1 deletion views_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 337173f

Please sign in to comment.