-
Notifications
You must be signed in to change notification settings - Fork 306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support relative links to headers inside notebooks #702
base: master
Are you sure you want to change the base?
Conversation
path was shadowed by LinkFindTarget::path, let's call the function arguments something different so we can actually operate on them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you and sorry for the delay.
I think we'll want a few tests in InternalLinksTest
for this too.
else if (userData instanceof Pair) { | ||
if (((Pair) userData).getFirst() instanceof Book && ((Pair) userData).getSecond() instanceof NoteView) { | ||
NoteView noteView = (NoteView) ((Pair) userData).getSecond(); | ||
Intent intent = new Intent(AppIntent.ACTION_OPEN_NOTE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This always opens note details. I think we want to honor user preference Settings / Notes & Notebooks / Note / Link target
and perhaps open a book instead, scrolling to the note.
See how that's done for ID/CUSTOM_ID links in followLinkToNoteWithProperty
.
@@ -15,9 +17,23 @@ class LinkFindTarget(val path: String) : UseCase() { | |||
} | |||
|
|||
private fun openLink(dataRepository: DataRepository, path: String): Any { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This name is confusing, I don't know why I named it openLink
. I'd rename it to findTarget
to match the use case.
} else if (regex.matches(path)) { | ||
val matchResults = regex.matchEntire(path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we want to avoid matching twice.
@@ -15,9 +17,23 @@ class LinkFindTarget(val path: String) : UseCase() { | |||
} | |||
|
|||
private fun openLink(dataRepository: DataRepository, path: String): Any { | |||
val regex = """(.*)\:\:(.*)""".toRegex() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps *
can be included in the regex. Something like:
val regex = """(.*)\:\:(.*)""".toRegex() | |
val regex = """(.*)::\*(.*)""".toRegex() |
If not, we need to check for it below, having in mind support for other link types in the future, like:
file:sometextfile::NNN (jump to line number)
file:projects.org::some words (text search)
file:projects.org::#custom-id (headline search)
|
||
} else if (regex.matches(path)) { | ||
val matchResults = regex.matchEntire(path) | ||
val (_, notebook, heading) = matchResults!!.groupValues |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!!
is generally avoided in Kotlin. A single match and checking for its result should do it.
val allNotes = dataRepository.getNotes(it.name) | ||
for (note in allNotes) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See getNotesByTitle
in DataRepository
. We have to avoid going through all book's notes.
I'd create a new getNotesByTitle
that accepts book ID in addition to the title.
private fun isAbsolute(path: String): Boolean { | ||
return path.startsWith('/') | ||
private fun isAbsolute(bookPath: String): Boolean { | ||
return bookPath.startsWith('/') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not consistent with the name above. I don't care much about the name itself. Perhaps just link
would make the most sense?
Is there any further progress on this? |
Fixes #694
Related to #565
Now, if you click on the link "[[file:"notes.org::Heading1"][link]]" it opens the selected note (in "editing" mode).
Please help me patch up this frankenstein, I just learned about kotlin a week ago :)