Skip to content

ReaderLink: allow a forward location stack#10228

Merged
Frenzie merged 2 commits into
koreader:masterfrom
yparitcher:fls
Mar 29, 2023
Merged

ReaderLink: allow a forward location stack#10228
Frenzie merged 2 commits into
koreader:masterfrom
yparitcher:fls

Conversation

@yparitcher

@yparitcher yparitcher commented Mar 20, 2023

Copy link
Copy Markdown
Member

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 gesture

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


This change is Reviewable

@Frenzie Frenzie added this to the 2023.04 milestone Mar 20, 2023
Comment thread frontend/apps/reader/modules/readerlink.lua Outdated
return true
elseif show_notification_if_empty then
UIManager:show(Notification:new{
text = _("Location history is empty."),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Location forward history is empty." or "No forward location in history." ?

Comment thread frontend/apps/reader/modules/readerlink.lua
Comment thread frontend/apps/reader/modules/readerlink.lua Outdated
Comment thread frontend/apps/reader/modules/readerlink.lua Outdated
Comment on lines +693 to +695
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread frontend/dispatcher.lua Outdated
Comment on lines +125 to +126
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},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(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.)

Comment on lines 29 to 32
"----------------------------",
"go_to_previous_location",
"go_to_next_location",
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More chances to make this menu go above 10 items and become multiple pages :/

@poire-z

poire-z commented Mar 20, 2023

Copy link
Copy Markdown
Contributor

It looks like not much, but it was quite hard to review :/ and I'm a bit unsure about how it works.
Can you confirm that, following links and going back, as soon as you follow a link or do anything that addLocationToStack(), all the previous forward locations is unusable - and you won't be able to "go forward" and be back on a totally unrelated/obsolete "forward location chain" ?

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).
It might be ok to back/forward from a footnote, but bookmarking that footnote page and using "jump to latest bookmark" feels more robust to me (even if less obvious).

What would be your use cases ? And which gestures would you use for it ?

@yparitcher

Copy link
Copy Markdown
Member Author

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.

@Frenzie

Frenzie commented Mar 20, 2023

Copy link
Copy Markdown
Member

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.

@NiLuJe

NiLuJe commented Mar 20, 2023

Copy link
Copy Markdown
Member

I don't recall if there's a matching GH issue, but it came up very recently on MobileRead ;).

@yparitcher

Copy link
Copy Markdown
Member Author

@yparitcher yparitcher marked this pull request as draft March 20, 2023 16:16
@yparitcher yparitcher changed the title ReaderLink: allow a foward location stack ReaderLink: allow a forward location stack Mar 21, 2023
Comment thread frontend/apps/reader/modules/readerlink.lua Outdated
Comment thread frontend/apps/reader/modules/readerlink.lua Outdated
@yparitcher

Copy link
Copy Markdown
Member Author

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

@yparitcher

Copy link
Copy Markdown
Member Author

ready for review. I mostly copied existing strings. Please suggest better english ;)

@yparitcher yparitcher marked this pull request as ready for review March 23, 2023 22:54
Comment on lines +885 to +921
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))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. I am on page 4, I follow a footnote link to page 12
  2. then follow another link to page 17
  3. then "Go back" and end up on page 12
  4. then "Go back" and end up on page 4
  5. then Go forward" and end up on page 12
  6. then "Go back" and end up on page 4

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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".

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are we supposed to remark upon precisely? I've neither looked at nor tried the code yet. ^_^

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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...").

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here?

Comment thread frontend/apps/reader/modules/readerlink.lua Outdated
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
Comment thread frontend/apps/reader/modules/readerlink.lua Outdated

@poire-z poire-z left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@Frenzie Frenzie merged commit bc5d354 into koreader:master Mar 29, 2023
@yparitcher yparitcher deleted the fls branch March 29, 2023 20:50
@mergen3107

Copy link
Copy Markdown
Contributor

I tested this quickly in a PDF with internal links. Doesn’t work after first forward location move.

  1. Open a PDF with internal links (Figures, Tables, Sections, references, etc). Top menu first tab has both back and forth buttons grayed out.
  2. Tap a link to go somewhere.
  3. Top menu, now only has go back to prev location ready.
  4. Tap go back
  5. Top menu now has only forward button ready.
  6. Tap go forward.
  7. It goes there OK, top menu has only back button ready.
  8. Tap back - nothing happens in terms of pages.
  9. Back grays out, forward lights up, but it obviously won’t change locations anymore.

callback = function() self:onGoForwardLink() end,
hold_callback = function(touchmenu_instance)
UIManager:show(ConfirmBox:new{
text = _("Clear Forward location history?"),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed this, but weird capitalization. But the better solution is to just remove this completely imho. What's the purpose?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pardon, overlooked the hold_callback part, so it's hidden.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go Forward to next location has the same problem

@yparitcher

Copy link
Copy Markdown
Member Author

I tested this quickly in a PDF with internal links. Doesn’t work after first forward location move.

1. Open a PDF with internal links (Figures, Tables, Sections, references, etc). Top menu first tab has both back and forth buttons grayed out.

2. Tap a link to go somewhere.

3. Top menu, now only has go back to prev location ready.

4. Tap go back

5. Top menu now has only forward button ready.

6. Tap go forward.

7. It goes there OK, top menu has only back button ready.

8. Tap back - nothing happens in terms of pages.

9. Back grays out, forward lights up, but it obviously won’t change locations anymore.

Works for me, are the link & location on the same page?

@mergen3107

Copy link
Copy Markdown
Contributor

No, the link is a Figure, about 2-3 pages away

TranHHoang added a commit to TranHHoang/koreader that referenced this pull request May 26, 2023
KOReader 2023.04 "Solar Panel"

![koreader-2023-04-fs8](https://user-images.githubusercontent.com/202757/234975122-d7739c71-74aa-4cb0-a086-72a4bba70f52.png)

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)
0xstillb pushed a commit to 0xstillb/koreader-thai that referenced this pull request May 9, 2026
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
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.

6 participants