-
Notifications
You must be signed in to change notification settings - Fork 303
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -3,6 +3,8 @@ package com.orgzly.android.usecase | |||||
import android.os.Environment | ||||||
import com.orgzly.android.BookName | ||||||
import com.orgzly.android.data.DataRepository | ||||||
import com.orgzly.android.db.entity.Book | ||||||
import com.orgzly.android.db.entity.NoteView | ||||||
import java.io.File | ||||||
|
||||||
class LinkFindTarget(val path: String) : UseCase() { | ||||||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. This name is confusing, I don't know why I named it |
||||||
val regex = """(.*)\:\:(.*)""".toRegex() | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps
Suggested change
If not, we need to check for it below, having in mind support for other link types in the future, like:
|
||||||
return if (isAbsolute(path)) { | ||||||
File(path) | ||||||
|
||||||
} else if (regex.matches(path)) { | ||||||
val matchResults = regex.matchEntire(path) | ||||||
Comment on lines
+23
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we want to avoid matching twice. |
||||||
val (_, notebook, heading) = matchResults!!.groupValues | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||
isMaybeBook(notebook)?.let { bookName -> | ||||||
dataRepository.getBook(bookName.name)?.let { | ||||||
val allNotes = dataRepository.getNotes(it.name) | ||||||
for (note in allNotes) { | ||||||
Comment on lines
+28
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See I'd create a new |
||||||
if (note.note.title == heading.substring(1)) { // fist char of heading is '*' | ||||||
return Pair<Book, NoteView>(it, note); | ||||||
} | ||||||
} | ||||||
} | ||||||
} | ||||||
File(Environment.getExternalStorageDirectory(), path) | ||||||
} else { | ||||||
isMaybeBook(path)?.let { bookName -> | ||||||
dataRepository.getBook(bookName.name)?.let { | ||||||
|
@@ -29,12 +45,12 @@ class LinkFindTarget(val path: String) : UseCase() { | |||||
} | ||||||
} | ||||||
|
||||||
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 commentThe 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 |
||||||
} | ||||||
|
||||||
private fun isMaybeBook(path: String): BookName? { | ||||||
val file = File(path) | ||||||
private fun isMaybeBook(bookPath: String): BookName? { | ||||||
val file = File(bookPath) | ||||||
|
||||||
return if (!hasParent(file) && BookName.isSupportedFormatFileName(file.name)) { | ||||||
BookName.fromFileName(file.name) | ||||||
|
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
.