@@ -9682,15 +9682,13 @@ void MainWindow::onNavigationWidgetHeadingRenamed(int position, const QString &o
96829682 */
96839683void MainWindow::updateBacklinksAfterHeadingRename (const QString &oldHeading,
96849684 const QString &newHeading) {
9685- Note currentNote = this ->currentNote ;
9686-
96879685 // Generate the old and new heading fragments (URL encoded)
96889686 // Heading fragments in links are URL-encoded (spaces become %20, etc.)
96899687 QString oldFragment = QString (QUrl::toPercentEncoding (oldHeading));
96909688 QString newFragment = QString (QUrl::toPercentEncoding (newHeading));
96919689
96929690 // Find all notes that have backlinks to the current note
9693- QVector<int > backlinkNoteIds = currentNote.findBacklinkedNoteIds ();
9691+ QVector<int > backlinkNoteIds = this -> currentNote .findBacklinkedNoteIds ();
96949692
96959693 if (backlinkNoteIds.isEmpty ()) {
96969694 return ;
@@ -9720,44 +9718,36 @@ void MainWindow::updateBacklinksAfterHeadingRename(const QString &oldHeading,
97209718 }
97219719
97229720 // Ask the user if they want to update the backlinks
9723- QString message;
9724- if (notesWithHeadingLinks.size () == 1 ) {
9725- message = tr (" The heading \" %1\" is referenced in 1 note. "
9726- " Do you want to update the link to use the new heading \" %2\" ?" )
9727- .arg (oldHeading, newHeading);
9728- } else {
9729- message = tr (" The heading \" %1\" is referenced in %2 notes. "
9730- " Do you want to update all links to use the new heading \" %3\" ?" )
9731- .arg (oldHeading)
9732- .arg (notesWithHeadingLinks.size ())
9733- .arg (newHeading);
9734- }
9735-
9736- if (Utils::Gui::question (this , tr (" Update backlinks" ), message,
9737- QStringLiteral (" update-heading-backlinks" )) == QMessageBox::Yes) {
9738- // User clicked "Yes"
9739- int updatedCount = 0 ;
9740-
9741- for (Note &backlinkNote : notesWithHeadingLinks) {
9742- QString noteText = backlinkNote.getNoteText ();
9743-
9744- // Replace all occurrences of the old heading fragment with the new one
9745- QString oldFragmentPattern = QStringLiteral (" #" ) + oldFragment;
9746- QString newFragmentPattern = QStringLiteral (" #" ) + newFragment;
9747-
9748- if (noteText.contains (oldFragmentPattern)) {
9749- noteText.replace (oldFragmentPattern, newFragmentPattern);
9750- backlinkNote.storeNewText (std::move (noteText));
9751- backlinkNote.storeNoteTextFileToDisk ();
9752- updatedCount++;
9753- }
9754- }
9721+ if (Utils::Gui::question (this , tr (" Update backlinks" ),
9722+ tr (" The heading \" %1\" is referenced in %n note(s). "
9723+ " Do you want to update the link to use the new heading \" %2\" ?" ,
9724+ " " , notesWithHeadingLinks.size ())
9725+ .arg (oldHeading, newHeading),
9726+ QStringLiteral (" update-heading-backlinks" )) != QMessageBox::Yes) {
9727+ return ;
9728+ }
97559729
9756- // Show a confirmation message
9757- if (updatedCount > 0 ) {
9758- showStatusBarMessage (tr (" Updated heading links in %n note(s)" , " " , updatedCount), 5000 );
9730+ // User clicked "Yes"
9731+ int updatedCount = 0 ;
9732+
9733+ for (Note &backlinkNote : notesWithHeadingLinks) {
9734+ QString noteText = backlinkNote.getNoteText ();
9735+
9736+ // Replace all occurrences of the old heading fragment with the new one
9737+ QString oldFragmentPattern = QStringLiteral (" #" ) + oldFragment;
9738+ QString newFragmentPattern = QStringLiteral (" #" ) + newFragment;
9739+
9740+ if (noteText.contains (oldFragmentPattern)) {
9741+ noteText.replace (oldFragmentPattern, newFragmentPattern);
9742+ backlinkNote.storeNewText (std::move (noteText));
9743+ updatedCount++;
97599744 }
97609745 }
9746+
9747+ // Show a confirmation message
9748+ if (updatedCount > 0 ) {
9749+ showStatusBarMessage (tr (" Updated heading links in %n note(s)" , " " , updatedCount), 5000 );
9750+ }
97619751}
97629752
97639753/* *
0 commit comments