@@ -3414,14 +3414,27 @@ QString Note::relativeFilePath(const QString &path) const {
3414
3414
* @param oldNote
3415
3415
* @return true if we had to change the current note
3416
3416
*/
3417
- bool Note::handleNoteMoving (const Note & oldNote) {
3417
+ bool Note::handleNoteMoving (Note oldNote) {
3418
3418
const QVector<int > noteIdList = oldNote.findLinkedNoteIds ();
3419
3419
const int noteCount = noteIdList.count ();
3420
3420
3421
- if (noteCount == 0 ) {
3422
- return false ;
3421
+ const auto reverseLinkNotes = oldNote.findReverseLinkNotes ();
3422
+ const int reverseLinkNotesCount = reverseLinkNotes.count ();
3423
+ bool result = false ;
3424
+
3425
+ if (noteCount >= 0 ) {
3426
+ result = handleLinkedNotesAfterMoving (oldNote, noteIdList);
3427
+ }
3428
+
3429
+ if (reverseLinkNotesCount > 0 ) {
3430
+ result |= handleReverseLinkedNotesAfterMoving (oldNote, reverseLinkNotes);
3423
3431
}
3424
3432
3433
+ return result;
3434
+ }
3435
+
3436
+ bool Note::handleLinkedNotesAfterMoving (const Note &oldNote, const QVector<int > ¬eIdList) {
3437
+ const int noteCount = noteIdList.count ();
3425
3438
const QString oldUrl = getNoteURL (oldNote.getName ());
3426
3439
const QString newUrl = getNoteURL (_name);
3427
3440
@@ -3438,7 +3451,7 @@ bool Note::handleNoteMoving(const Note &oldNote) {
3438
3451
QStringLiteral (" note-replace-links" )) == QMessageBox::Yes) {
3439
3452
// replace the urls in all found notes
3440
3453
for (const int noteId : noteIdList) {
3441
- Note note = Note:: fetch (noteId);
3454
+ Note note = fetch (noteId);
3442
3455
3443
3456
if (!note.isFetched ()) {
3444
3457
continue ;
@@ -3501,6 +3514,23 @@ bool Note::handleNoteMoving(const Note &oldNote) {
3501
3514
return noteIdList.contains (_id);
3502
3515
}
3503
3516
3517
+ bool Note::handleReverseLinkedNotesAfterMoving (
3518
+ const Note &oldNote, const QHash<Note, QSet<BacklinkHit>> &reverseLinkNotes) {
3519
+ // Iterate over reverseLinkNotes
3520
+ for (auto it = reverseLinkNotes.begin (); it != reverseLinkNotes.end (); ++it) {
3521
+ const Note &backlinkNote = it.key ();
3522
+ const QSet<BacklinkHit> &linkTextList = it.value ();
3523
+
3524
+ qDebug () << __func__ << " - 'oldNote': " << oldNote;
3525
+
3526
+ qDebug () << __func__ << " - 'backlinkNote': " << backlinkNote;
3527
+ qDebug () << __func__ << " - 'linkTextList': " << linkTextList;
3528
+ }
3529
+
3530
+ // TODO: Change to true if we had to change the current note
3531
+ return false ;
3532
+ }
3533
+
3504
3534
QSet<Note> Note::findBacklinks () const {
3505
3535
const QVector<int > noteIdList = this ->findLinkedNoteIds ();
3506
3536
const int noteCount = noteIdList.count ();
@@ -4170,3 +4200,8 @@ bool Note::operator==(const Note ¬e) const {
4170
4200
return _id == note.getId () && _fileName == note.getFileName () &&
4171
4201
_noteSubFolderId == note.getNoteSubFolderId ();
4172
4202
}
4203
+
4204
+ QDebug operator <<(QDebug dbg, const BacklinkHit &hit) {
4205
+ dbg.nospace () << " BacklinkHit(markdown: " << hit.markdown << " , text: " << hit.text << ' )' ;
4206
+ return dbg.space ();
4207
+ }
0 commit comments