Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Asalle
Copy link

@Asalle Asalle commented May 3, 2020

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 :)

Asalle added 2 commits May 3, 2020 09:54
path was shadowed by LinkFindTarget::path, let's call the function arguments
something different so we can actually operate on them.
Copy link
Member

@nevenz nevenz left a 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);
Copy link
Member

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 {
Copy link
Member

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.

Comment on lines +23 to +24
} else if (regex.matches(path)) {
val matchResults = regex.matchEntire(path)
Copy link
Member

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()
Copy link
Member

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:

Suggested change
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
Copy link
Member

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.

Comment on lines +28 to +29
val allNotes = dataRepository.getNotes(it.name)
for (note in allNotes) {
Copy link
Member

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('/')
Copy link
Member

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?

@lytex lytex mentioned this pull request Oct 21, 2020
@hahuang65
Copy link

Is there any further progress on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support links to headers inside notebooks
3 participants