Skip to content

Commit

Permalink
#1717 backlinks: improve link detection and UI
Browse files Browse the repository at this point in the history
Signed-off-by: Patrizio Bekerle <[email protected]>
  • Loading branch information
pbek committed Sep 5, 2024
1 parent 4c4c6ee commit 024b198
Show file tree
Hide file tree
Showing 5 changed files with 234 additions and 222 deletions.
13 changes: 8 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# QOwnNotes Changelog

## 24.9.2
- The **backlink widget** link detection was improved
- The **backlink widget** link detection and UI was improved
(for [#1717](https://github.com/pbek/QOwnNotes/issues/1717))
- In checkbox lists the checkboxes will now not be detected as part of the links
- In the note search line edit, the `Right` arrow key will not make the focus
jump to the note list anymore, the `Tab` key is enough to do that
(for [#3097](https://github.com/pbek/QOwnNotes/issues/3097))
- In checkbox lists the checkboxes will now not be detected as part of the link
- Multiple occurrences of similar links can now be detected in notes
- A problem with the found link not showing up in the tooltips of items was fixed
- More information for the found notes will now be shown in the tooltip
- In the note search line edit, the `Right` arrow key will not make the focus
jump to the note list anymore, the `Tab` key is enough to do that
(for [#3097](https://github.com/pbek/QOwnNotes/issues/3097))

## 24.9.1
- The **backlink widget** in the navigation panel now also shows the links in the notes
Expand Down
27 changes: 17 additions & 10 deletions src/entities/note.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3126,18 +3126,25 @@ QVector<int> Note::findLinkedNoteIds() const {
return noteIdList;
}

// TODO: Use two parameters instead of patterns
BacklinkHit Note::findAndReturnBacklinkHit(const QString &text, const QString &pattern) {
return text.contains(pattern) ? BacklinkHit(pattern, pattern) : BacklinkHit("", "");
}

BacklinkHit Note::findAndReturnBacklinkHit(const QString &text, const QRegularExpression &pattern) {
const QRegularExpressionMatch match = pattern.match(text);
if (match.hasMatch()) {
return {match.captured(0), match.captured(1)};
QList<BacklinkHit> Note::findAndReturnBacklinkHit(const QString &text,
const QRegularExpression &regex) {
QList<BacklinkHit> backlinkHits;
QRegularExpressionMatchIterator iterator = regex.globalMatch(text);

while (iterator.hasNext()) {
QRegularExpressionMatch match = iterator.next();
QString linkText = match.captured(1);
QString linkUrl = match.captured(2);
// Do something with the link text and URL

backlinkHits.append(BacklinkHit(match.captured(0), match.captured(1)));
}

return {"", ""};
return backlinkHits;
}

void Note::addTextToBacklinkNoteHashIfFound(const Note &note, const QString &pattern) {
Expand All @@ -3153,13 +3160,13 @@ void Note::addTextToBacklinkNoteHashIfFound(const Note &note, const QString &pat
}

void Note::addTextToBacklinkNoteHashIfFound(const Note &note, const QRegularExpression &pattern) {
const BacklinkHit backlinkHit = findAndReturnBacklinkHit(note.getNoteText(), pattern);
const auto backlinkHits = findAndReturnBacklinkHit(note.getNoteText(), pattern);

if (!backlinkHit.isEmpty()) {
if (!backlinkHits.isEmpty()) {
if (!_backlinkNoteHash.contains(note)) {
_backlinkNoteHash.insert(note, {backlinkHit});
_backlinkNoteHash.insert(note, backlinkHits);
} else {
_backlinkNoteHash[note] << backlinkHit;
_backlinkNoteHash[note] << backlinkHits;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/entities/note.h
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,8 @@ class Note {
void restoreCreatedDate();

static BacklinkHit findAndReturnBacklinkHit(const QString &text, const QString &pattern);
static BacklinkHit findAndReturnBacklinkHit(const QString &text,
const QRegularExpression &pattern);
static QList<BacklinkHit> findAndReturnBacklinkHit(const QString &text,
const QRegularExpression &regex);

void addTextToBacklinkNoteHashIfFound(const Note &note, const QString &pattern);
void addTextToBacklinkNoteHashIfFound(const Note &note, const QRegularExpression &pattern);
Expand Down
Loading

0 comments on commit 024b198

Please sign in to comment.