Skip to content

Commit

Permalink
fix #3607
Browse files Browse the repository at this point in the history
  • Loading branch information
sunderme committed Apr 16, 2024
1 parent 62bab1d commit d5c2207
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 31 deletions.
76 changes: 46 additions & 30 deletions src/texstudio.cpp
Expand Up @@ -9097,7 +9097,8 @@ void Texstudio::cursorPositionChanged()
if(newSection!=currentSection){
StructureEntry *old=currentSection;
currentSection=newSection;
updateCurrentPosInTOC(nullptr,old);
updateCurrentPosInTOC(old);
updateCurrentPosInStructure(old);
}

syncPDFViewer(currentEditor()->cursor(), false);
Expand Down Expand Up @@ -11624,42 +11625,57 @@ void Texstudio::updateTOC(){
}
root->setExpanded(true);
root->setSelected(false);
updateCurrentPosInTOC(nullptr,nullptr,selectedEntry);
updateCurrentPosInTOC(nullptr,selectedEntry);
}
/*!
* \brief update marking of current position in global TOC and structure view
* Both need to be updated as the docks seem not to provide information whether they are visible or not.
* Works recursively.
* \brief update marking of current position in global TOC
* \param root nullptr at the start, treewidgetitem of which the children need to be checked later.
* \param old previously marked section of which the mark needs to be removed
* \param selected selected section
*/
void Texstudio::updateCurrentPosInTOC(QTreeWidgetItem* root, StructureEntry *old, StructureEntry *selected,bool tocMode)
void Texstudio::updateCurrentPosInTOC(StructureEntry *old, StructureEntry *selected)
{
const QColor activeItemColor(UtilsUi::mediumLightColor(QPalette().color(QPalette::Highlight), 75));
if(!root){
// run update on TOC and structureView
root=topTOCTreeWidget->topLevelItem(0);
if(root){
updateCurrentPosInTOC(root,old,selected,true);
}
root=nullptr;
for(int i=0;i<structureTreeWidget->topLevelItemCount();++i){
QTreeWidgetItem* item=structureTreeWidget->topLevelItem(i);
LatexDocument *doc = static_cast<LatexDocument*>(item->data(0,Qt::UserRole).value<void*>());
if(old && old->document!=documents.getCurrentDocument() && doc==old->document){
// remove cursor mark from structureView of not current document (after document switch)
updateCurrentPosInTOC(item,old);
if(root)
break; // no need to search further
}
if(doc == documents.getCurrentDocument()){
root=item;
}
QTreeWidgetItem* root=topTOCTreeWidget->topLevelItem(0);
if(root){
updateCurrentPosInTOCHelper(root,old,selected,true);
}
}
/*!
* \brief update marking of current position in structure view
* \param root nullptr at the start, treewidgetitem of which the children need to be checked later.
* \param old previously marked section of which the mark needs to be removed
* \param selected selected section
*/
void Texstudio::updateCurrentPosInStructure(StructureEntry *old, StructureEntry *selected)
{
QTreeWidgetItem* root=nullptr;
for(int i=0;i<structureTreeWidget->topLevelItemCount();++i){
QTreeWidgetItem* item=structureTreeWidget->topLevelItem(i);
LatexDocument *doc = static_cast<LatexDocument*>(item->data(0,Qt::UserRole).value<void*>());
if(old && old->document!=documents.getCurrentDocument() && doc==old->document){
// remove cursor mark from structureView of not current document (after document switch)
updateCurrentPosInTOCHelper(item,old);
if(root)
break; // no need to search further
}
if(root){
updateCurrentPosInTOC(root,old,selected,false);
if(doc == documents.getCurrentDocument()){
root=item;
}
}
if(root){
updateCurrentPosInTOCHelper(root,old,selected,false);
}
}
/*!
* \brief update marking of current position in global TOC or structure view
* \param root nullptr at the start, treewidgetitem of which the children need to be checked later.
* \param old previously marked section of which the mark needs to be removed
* \param selected selected section
*/
void Texstudio::updateCurrentPosInTOCHelper(QTreeWidgetItem* root, StructureEntry *old, StructureEntry *selected,bool tocMode)
{
const QColor activeItemColor(UtilsUi::mediumLightColor(QPalette().color(QPalette::Highlight), 75));
if(!root){
return;
}
for(int i=0;i<root->childCount();++i){
Expand Down Expand Up @@ -11688,7 +11704,7 @@ void Texstudio::updateCurrentPosInTOC(QTreeWidgetItem* root, StructureEntry *old
}
}
}
updateCurrentPosInTOC(item,old);
updateCurrentPosInTOCHelper(item,old,nullptr,tocMode);
}
}
/*!
Expand Down Expand Up @@ -12457,7 +12473,7 @@ void Texstudio::updateStructureLocally(bool updateAll){

root->setExpanded(true);
root->setSelected(false);
updateCurrentPosInTOC(nullptr,nullptr,selectedEntry);
updateCurrentPosInStructure(nullptr,selectedEntry);
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/texstudio.h
Expand Up @@ -251,7 +251,9 @@ private slots:
void updateAllTOCs();

void updateTOC();
void updateCurrentPosInTOC(QTreeWidgetItem *root=nullptr, StructureEntry *old=nullptr, StructureEntry *selected=nullptr, bool tocMode=true);
void updateCurrentPosInTOC(StructureEntry *old=nullptr, StructureEntry *selected=nullptr);
void updateCurrentPosInStructure(StructureEntry *old=nullptr, StructureEntry *selected=nullptr);
void updateCurrentPosInTOCHelper(QTreeWidgetItem *root=nullptr, StructureEntry *old=nullptr, StructureEntry *selected=nullptr, bool tocMode=true);
void syncExpanded(QTreeWidgetItem *item);
void syncCollapsed(QTreeWidgetItem *item);
void editSectionCopy();
Expand Down

0 comments on commit d5c2207

Please sign in to comment.