ReaderLink: allow a forward location stack#10228
Conversation
| return true | ||
| elseif show_notification_if_empty then | ||
| UIManager:show(Notification:new{ | ||
| text = _("Location history is empty."), |
There was a problem hiding this comment.
"Location forward history is empty." or "No forward location in history." ?
| self.location_stack_index = self.location_stack_index + 1 | ||
| self.location_stack[self.location_stack_index] = location | ||
| self.location_stack[self.location_stack_index+1] = nil |
There was a problem hiding this comment.
Are we supposed somehow somewhere to navigate again to older forward locations, when you got back and follow a new path ?
It's a bit unclear this gymnastic with +1 = nil or ~= nil.
| previous_location = {category="none", event="GoBackLink", arg=true, title=_("Back to previous location"), reader=true}, | ||
| next_location = {category="none", event="GoForwardLink", arg=true, title=_("Forward to net location"), reader=true}, |
There was a problem hiding this comment.
(I guess the naming is for consistency with the existing one, but ok, we go back usually from a link - we're not really going forward from/to a link - or there is another event, follow nearest link.)
| "----------------------------", | ||
| "go_to_previous_location", | ||
| "go_to_next_location", | ||
| }, |
There was a problem hiding this comment.
More chances to make this menu go above 10 items and become multiple pages :/
|
It looks like not much, but it was quite hard to review :/ and I'm a bit unsure about how it works. I remember there's been requests for that, but it feels totally unpractical to me: as soon as you tap a link/bookmark/ToC/page thumbnail/skim..., you addCurrentLocationToStack and your dear forward history is lost (as it should be). What would be your use cases ? And which gestures would you use for it ? |
|
Sorry i thought i wrote the explanation comment. Github must have swallowed it. We are using the table as an array so as long as the next item is nil the array is finished and we dont care about further values. If it is too coplicated for us, i can switch to using ipairs to clear all further values. When i am at my computer i will fix/answer all the individual points I don't use links so much, but sometimes i trigger the previous location gesture by mistake and can't get back to my current location. |
|
Forward location stack was actually on my mental list from the moment I implemented the thing, so I may have mentioned it somewhere without opening an issue. I pretty much forgot about it though and it actually hasn't really bothered me in practice over the past five years. |
|
I don't recall if there's a matching GH issue, but it came up very recently on MobileRead ;). |
|
I looked up undo/redo queues, and found a much simpler idea with 2 stacks, we leave the existing stack alone and add a forward stack, when we pop from one (by going back) we insert it onto the other. Will redo this when i have time. Thanks @poire-z for reminding me i was overengineering this :) |
|
ready for review. I mostly copied existing strings. Please suggest better english ;) |
| local saved_location = table.remove(self.forward_location_stack) | ||
| if saved_location then | ||
| table.insert(self.location_stack, saved_location) | ||
| logger.dbg("GoForward: restoring:", saved_location) | ||
| self.ui:handleEvent(Event:new('RestoreBookLocation', saved_location)) |
There was a problem hiding this comment.
saved_location is the future forward location we are going to.
So, table.insert(self.location_stack, saved_location) seems wrong ? You should insert the current location we are leaving.
There was a problem hiding this comment.
I will start with going back (your other comment)
For example we have 3 previous locations on the stack, no forward locations, we pop one. If the current and popped are not the same we add current to forward stack. The popped location is added to the forward stack and we go to it. So now it is forward of us.
When we go forward we pop the last forward location off the stack, push it to previous location stack, and go to it.
There was a problem hiding this comment.
we add current to forward stack. The popped location is added to the forward stack and we go to it. So now it is forward of us.
Still confused, sorry :/
When going back, we'll add 2 items to the foward_stack: the footnote page we were in, + the reading page we are going back to ? So the forward stack top elment is the current page ?
When we go forward we pop the last forward location off the stack, push it to previous location stack, and go to it.
You're saying what I said: the previous location stack will be where we are going?
So, we don't add anywhere the current location ?!
Can you give some example with PDF pages (to keep it simpler than xpointer), the state of both stacks, when say:
- I am on page 4, I follow a footnote link to page 12
- then follow another link to page 17
- then "Go back" and end up on page 12
- then "Go back" and end up on page 4
- then Go forward" and end up on page 12
- then "Go back" and end up on page 4
There was a problem hiding this comment.
location_stack = {}, forward_location_stack = {}
I am on page 4, I follow a footnote link to page 12
location_stack = { 4 }, forward_location_stack = {}
then follow another link to page 17
location_stack = { 4, 12 }, forward_location_stack = {}
then "Go back" and end up on page 12
location_stack = { 4 }, forward_location_stack = { 17, 12 }
then "Go back" and end up on page 4
location_stack = {}, forward_location_stack = { 17, 12, 4 }
then Go forward" and end up on page 12 4
location_stack = { 4 }, forward_location_stack = { 17, 12 }
then Go forward" and end up on page 12
location_stack = { 4, 12 }, forward_location_stack = { 17 }
then "Go back" and end up on page 4 12
location_stack = { 4 }, forward_location_stack = { 17, 12 }
then "Go back" and end up on page 4
location_stack = {}, forward_location_stack = { 17, 12, 4 }
Since we are always between locations (we store results, not actions) when you switch from forward<-->back, you repeat the first one going the other way. however if you move pages in the middle it make more sense:
location_stack = {}, forward_location_stack = {}
I am on page 4, I follow a footnote link to page 12
location_stack = { 4 }, forward_location_stack = {}
then follow another link to page 17
location_stack = { 4, 12 }, forward_location_stack = {}
then "Go back" and end up on page 12
location_stack = { 4 }, forward_location_stack = { 17, 12 }
then "Go back" and end up on page 4
location_stack = {}, forward_location_stack = { 17, 12, 4 }
then Go forward" and end up on page 12 4
location_stack = { 4 }, forward_location_stack = { 17, 12 }
then Go forward" and end up on page 12
location_stack = { 4, 12 }, forward_location_stack = { 17 }
read to the next page (13) to finish the footnote.
then "Go back" and end up on page 4 12
location_stack = { 4 }, forward_location_stack = { 17, 12 }
then "Go back" and end up on page 4
location_stack = {}, forward_location_stack = { 17, 12, 4 }
If you want we can check if the end of the stack == current_page and #location_stack >= 2 to jump 2 locations, solving the issue in the first case.
There was a problem hiding this comment.
I think I understand now your idea behind the obscure "If we are not on the same page as the current item, then add our current location to the forward stack", it's for when we turn pages after following links.
So, I guess that if I am on page 4, then jump to page 12, then turn page to page 13, when "go back to previous location", I'll then be first on page 12, and then on page 4 - and "go forward" will lead me to (x) page 12 then 13, right ?
(with (x) being an intermediate "to page 4" with no visible effect, but this is another issue which is not the one I'm focusing here :)
In my mind, page 12 shouldn't be tracked:
if I am on page 4, then jump to page 12, then turn page to page 13, only 13 should be the forward location. So, going back and getting on page 4, only page 13 should be in the forward location - and when I "go forward", I reach page 13 directly.
So, that's my naive expectation of the behaviour :) and your more complex, may be handling other use cases with more granularity about the locations remembered, feels a bit confusing - with either "no page change" or unwished intermediate page when I hit "go forward" (and even "go back"?)
Did I understand you correctly, and do you get me?
There was a problem hiding this comment.
If nobody else has remarks about your behaviour and we go with it, it would be good to have more comments in the code about this behaviour, or at least its tricky parts, with the kind of samples "if I go..." and the stacks states we used above, and "this allows... such use case".
There was a problem hiding this comment.
What are we supposed to remark upon precisely? I've neither looked at nor tried the code yet. ^_^
There was a problem hiding this comment.
So, ask again after you've done that :)
(I won't put noise/directions into your genuine/naive appreciation of it all - but later, you can read the scenarios described above ("I am on page 4...").
There was a problem hiding this comment.
(I won't put noise/directions into your genuine/naive appreciation of it all - but later, you can read the scenarios described above ("I am on page 4...").
Haven't read them yet, but forward and backward don't seem to work I'd expect them to. They're… double?
There was a problem hiding this comment.
I am going to add a commit to address the go to same page when switching between back<-->forward.
| end | ||
| end | ||
|
|
||
| table.insert(self.forward_location_stack, saved_location) |
this allows going back and forth from links (think of undo / redo) when going back and no forward locations and when we are not on the same page as the last saved location, add the current location to the forward stack, helping if one goes back by mistake they can jump back to thier current location
poire-z
left a comment
There was a problem hiding this comment.
OK with the code and the unchanged "go back" behaviour.
(Not interested enough with the "go forward" behaviour to get back into focusing on it :)
|
I tested this quickly in a PDF with internal links. Doesn’t work after first forward location move.
|
| callback = function() self:onGoForwardLink() end, | ||
| hold_callback = function(touchmenu_instance) | ||
| UIManager:show(ConfirmBox:new{ | ||
| text = _("Clear Forward location history?"), |
There was a problem hiding this comment.
Missed this, but weird capitalization. But the better solution is to just remove this completely imho. What's the purpose?
There was a problem hiding this comment.
Pardon, overlooked the hold_callback part, so it's hidden.
There was a problem hiding this comment.
Go Forward to next location has the same problem
Works for me, are the link & location on the same page? |
|
No, the link is a Figure, about 2-3 pages away |
KOReader 2023.04 "Solar Panel"  It's been another busy month squashing many bugs. Our Mac users will be happy to hear that I told macOS we've supported HiDPI since long before anyone came up with such terminology (koreader#10341), and that the program can now natively build on M1 devices (koreader#10291). Solar panel credit: <https://openclipart.org/detail/294030/solar-energy> by gnokii We'd like to thank all contributors for their efforts. Some highlights since the previous release include: * Readerzooming: fix use of default settings (koreader#10205) @hius07 * ButtonDialog/ButtonDialogTitle: consistent 'width' handling (koreader#10230) @poire-z * MovableContainer: add support for anchoring initial position (koreader#10230) @poire-z * Book map, Page browser: add top left menu (koreader#10230) @poire-z * Book style tweak: add button with CSS suggestions (koreader#10230) @poire-z * crengine: fix parsing of multibytes encodings (koreader#10230) @poire-z * readerstyletweak: update profiles on unregistering in dispatcher (koreader#10247) @hius07 * Filesearcher: add search in book metadata (koreader#10198) @hius07 * Fix: Updated legacy directory, which crashed the program (koreader#10260) @Mochitto * ReaderLink: allow a forward location stack (koreader#10228) @yparitcher * BookInfo: add page information (koreader#10255) @hius07 * Center pdf manual zoom mode (koreader#10246) @nairyosangha * File browser: add Folder Menu (koreader#10275) @hius07 * Calendar view: add options to change start time of days (koreader#10254) @weijiuqiao * filechooser: fix crash on "unreadable content" (koreader#10283) @hius07 * Sync book statistics: add to dispatcher (koreader#10285) @ptrm * [plugin] Exporter: use util.getSafeFilename() to remove illegal characters from output filename (koreader#10282) @Mochitto * readerbookmark: fix writing pdf annotation (koreader#10287) @hius07 * Folder Menu: sign for Home folder (koreader#10288) @hius07 * ListMenu: show mark for books with highlights (koreader#10276) @hius07 * Calendar view's day view: thicker separator at 00:00 (koreader#10289) @poire-z * PageBrowser: tweak scrolling behaviour at book start/end (koreader#10289) @poire-z * Make `kodev check` feature complete (koreader#8682) @yparitcher * macOS: support for M1 building (koreader#10291) @ptrm * Reader: do not apply font size and spacing out of range (koreader#10295, koreader#10307) @hius07 * File browser: show Folder Menu on long-press on Home icon (koreader#10298) @hius07 * SSH.koplugin: fix cant stop SSH server bug when pid file's stale (koreader#10300) @weijiuqiao * PM: Optimize task queue handling around standby (koreader#10203) @zwim * statistic.koplugin: fix today's timeline showing next day when within custom offset (koreader#10299) @weijiuqiao * ReaderThumbnails: update cached page thumbnail on bookmark note change (koreader#10303) @hius07 * SDL: add multitouch support (koreader#10334) @Frenzie * SDL: add HiDPI support (koreader#10341) @Frenzie * BookInfo: fix crash on show cover (koreader#10315) @hius07 * Deal with table.pack corner-cases properly (koreader#10350) @NiLuJe * Android: add Tagus Gea support (<koreader/android-luajit-launcher#412>) @Alfedi [Full changelog](koreader/koreader@v2023.03...v2023.04) — [closed milestone issues](https://github.com/koreader/koreader/milestone/63?closed=1) --- Installation instructions: [Android](https://github.com/koreader/koreader/wiki/Installation-on-Android-devices) • [Cervantes](https://github.com/koreader/koreader/wiki/Installation-on-BQ-devices) • [ChromeOS](https://github.com/koreader/koreader/wiki/Installation-on-Chromebook-devices) • [Kindle](https://github.com/koreader/koreader/wiki/Installation-on-Kindle-devices) • [Kobo](https://github.com/koreader/koreader/wiki/Installation-on-Kobo-devices) • [PocketBook](https://github.com/koreader/koreader/wiki/Installation-on-PocketBook-devices) • [ReMarkable](https://github.com/koreader/koreader/wiki/Installation-on-ReMarkable) • [Desktop Linux](https://github.com/koreader/koreader/wiki/Installation-on-desktop-linux) • [MacOS](https://github.com/koreader/koreader/wiki/Installation-on-MacOS)
this allows going back and forth from links (think of undo / redo) when going back and no forward locations and when we are not on the same page as the last saved location, add the current location to the forward stack, helping if one goes back by mistake they can jump back to their current location when going back and no forward locations and when we are not on the same page as the last saved location, add the current location to the forward stack, helping if one goes back by mistake they can jump back to thier current location
this allows users to jump back and forth to a link
When we go back (and are at the end of the stack) if the current page is not the same as the last location add it to the stack. this allows going (back)foward if one by mistake did the back gesturethis allows going back and forth from links (think of undo / redo)
when going back and no forward locations and when we are not on the same page as the last saved location, add the current location to the forward stack, helping if one goes back by mistake they can jump back to thier current location
This change is