@@ -2059,8 +2059,14 @@ bool MainWindow::changeNoteFolder(const int noteFolderId, const bool forceChange
20592059 QString folderName = noteFolder.getLocalPath ();
20602060 const QString oldPath = this ->notesPath ;
20612061
2062+ // Switch the active note folder first so all subsequent refresh steps
2063+ // (including combo/menu rebuilding) use the correct current folder.
2064+ noteFolder.setAsCurrent ();
2065+
2066+ const bool notesPathChanged = (oldPath != folderName);
2067+
20622068 // reload notes if notes folder was changed
2063- if (oldPath != folderName ) {
2069+ if (notesPathChanged ) {
20642070 const QSignalBlocker blocker2 (this ->ui ->searchLineEdit );
20652071 {
20662072 Q_UNUSED (blocker2)
@@ -2073,8 +2079,6 @@ bool MainWindow::changeNoteFolder(const int noteFolderId, const bool forceChange
20732079 // commit the changes in the current note folder to git
20742080 gitCommitCurrentNoteFolder ();
20752081
2076- noteFolder.setAsCurrent ();
2077-
20782082 // update the recent note folder list
20792083 storeRecentNoteFolder (this ->notesPath , folderName);
20802084
@@ -2092,34 +2096,40 @@ bool MainWindow::changeNoteFolder(const int noteFolderId, const bool forceChange
20922096 // we have to unset the current note otherwise it might show up after
20932097 // switching to another note folder
20942098 unsetCurrentNote ();
2099+ } else {
2100+ // Keep selector and Note -> Note folders menu in sync when switching
2101+ // between folders that share the same path.
2102+ loadNoteFolderListMenu ();
2103+ }
20952104
2096- buildNotesIndexAndLoadNoteDirectoryList (false , false , false );
2105+ buildNotesIndexAndLoadNoteDirectoryList (false , !notesPathChanged , false );
20972106
2098- // update the current folder tooltip
2099- updateCurrentFolderTooltip ();
2107+ // update the current folder tooltip
2108+ updateCurrentFolderTooltip ();
21002109
2101- // restore the note tabs
2102- Utils::Gui::restoreNoteTabs (ui->noteEditTabWidget , ui->noteEditTabWidgetLayout );
2110+ // restore the note tabs
2111+ Utils::Gui::restoreNoteTabs (ui->noteEditTabWidget , ui->noteEditTabWidgetLayout );
21032112
2104- // restore the note history of the new note folder
2105- noteHistory.restoreForCurrentNoteFolder ();
2113+ // restore the note history of the new note folder
2114+ noteHistory.restoreForCurrentNoteFolder ();
21062115
2107- // check if there is a note name set and jump to it
2108- QString noteName = _activeNoteFolderNotePositions[noteFolderId].getNoteName ();
2116+ // check if there is a note name set and jump to it
2117+ QString noteName = _activeNoteFolderNotePositions[noteFolderId].getNoteName ();
21092118
2110- // if there was no NoteHistory found try the note history
2111- if (noteName.isEmpty ()) {
2112- _activeNoteFolderNotePositions[noteFolderId] = noteHistory.getCurrentHistoryItem ();
2113- noteName = _activeNoteFolderNotePositions[noteFolderId].getNoteName ();
2114- }
2119+ // if there was no NoteHistory found try the note history
2120+ if (noteName.isEmpty ()) {
2121+ _activeNoteFolderNotePositions[noteFolderId] = noteHistory.getCurrentHistoryItem ();
2122+ noteName = _activeNoteFolderNotePositions[noteFolderId].getNoteName ();
2123+ }
21152124
2116- if (!noteName.isEmpty ()) {
2117- jumpToNoteName (noteName);
2125+ if (!noteName.isEmpty ()) {
2126+ jumpToNoteName (noteName);
21182127
2119- // restore the current position in the note
2120- _activeNoteFolderNotePositions[noteFolderId].restoreTextEditPosition (ui->noteTextEdit );
2121- }
2128+ // restore the current position in the note
2129+ _activeNoteFolderNotePositions[noteFolderId].restoreTextEditPosition (ui->noteTextEdit );
2130+ }
21222131
2132+ if (notesPathChanged) {
21232133 // commit the changes in the selected note folder to git
21242134 gitCommitCurrentNoteFolder ();
21252135 }
0 commit comments