Commit Graph
94 Commits
Author SHA1 Message Date
John O'Keefe cae618ac87 Fix selectionIsBackward for iframe selections
The helper created its probe range in the module's own document
(the host, in the bundled web reader), so boundary points in the
content iframe collapsed the range and every selection read as
backward.
2026-09-13 18:30:09 -04:00
John O'Keefe 2e392e80d3 Retry the touch selection clamp after the gesture ends 2026-09-13 18:26:47 -04:00
John O'Keefe 5102fc70dd Clamp by geometry, not the visible range
The last visible range can extend past the visible column on text
nodes that span multiple columns (its end-offset bisect uses union
rects), so comparing DOM boundary points against it misses off-view
selection endpoints. Test the endpoint caret rect against the
visible column bounds instead.
2026-09-13 18:23:52 -04:00
John O'Keefe 2a54b52fdb Keep touchSelecting armed through collapsed selectionchange events
Chrome emits collapsed selectionchange events while the long-press
word selection is being set up; clearing the flag on them disarmed
the clamp before the selection ever became a Range.
2026-09-13 18:18:03 -04:00
John O'Keefe 8ac36efbda Fix clamp coordinates: caretRangeFromPoint needs content-space bounds 2026-09-13 18:14:25 -04:00
John O'Keefe e1fa4698c6 Clamp touch selection endpoints to the visible page
Chrome word-snapping during a touch selection drag can map the
endpoint past the visible column into the next (off-screen) page,
selecting the entire visible page at once. Re-map the endpoint via
caretRangeFromPoint at the same line height inside the visible
column whenever it lands outside the last visible range.
2026-09-13 18:07:36 -04:00
John O'Keefe de70103651 Fix touch selection paging away mid-drag: gate selection auto-paging to non-touch pointers 2026-09-13 17:18:47 -04:00
Huang Xin 9fd2209b4d Fix blocked animate when running in background (#80) 2025-08-01 23:43:27 +00:00
Protected 55f1a28406 Prevent exception on Firefox due to getSelection returning null (#57) 2025-05-13 12:49:18 +00:00
John Factotum 052123beaf Add an EventTarget for transforming the book
And use it to do paginator-specific CSS replacements.

And use it to catch loading errors in reader.js.

Fixes #14
Closes #18
2025-03-29 15:09:23 +08:00
Ray-D-Song e2014ee753 Fix selection handling in Paginator component (#46) 2025-02-13 07:52:19 +00:00
John Factotum 63a5dbf3e3 Don't scroll to anchor if caret's moved by pointer
In Safari, clicking on links triggers `selectionchange`. Since we do not
move the caret when flipping through pages, when you have flipped to the
next or previous pages and click on any link, it would take you back to
the caret instead of activating the link.

Note that the bug occurs in Safari 17 but not in WebKitGTK 2.46.

Not sure if there's a way to fix this and still retain the "set anchor
to caret on click" behavior. But I guess this behavior isn't really that
essential, anyway. So removing it for now.

Fixes #44
2024-12-12 09:35:33 +08:00
John Factotum bf9adef636 Paginator: react to selection only on input 2024-09-30 19:00:11 +08:00
John Factotum dcd4ff403e Paginator: fix scrolling to collapsed ranges that contain elements 2024-09-25 22:41:20 +08:00
John Factotum 02a24ea25c Grammar 2024-09-25 22:33:02 +08:00
John Factotum 59a5aa22a0 Paginator: respond to selection change
The view follows caret when using caret browsing (F7). Also allows
selecting across pages. And if you click on or select some text and
resize the window, the caret/selection always stays visible.

Some quirks regarding caret browsing:
- In Chromium, in paginated mode, it scrolls when changing selection
  (https://issues.chromium.org/issues/40889650)
- In WebKitGTK, in scrolled mode, the view doesn't follow the caret
  (which would be a WebKit bug)
2024-09-24 11:54:47 +08:00
John Factotum 329e22227a Paginator: fix offset
What's `margin` doing here?! It's like this since the first commit, but
it makes no sense... I think I added it incorrectly, being misled by
the getBoundingClientRect bug in Firefox...
2024-09-24 11:36:43 +08:00
John Factotum 59bb647057 Paginator: fix visible range in Firefox 2024-09-24 11:34:57 +08:00
John Factotum 4ef87c2ca7 Paginator: fix caret position when navigating
The effect of this is more obvious if you enable caret browsing (F7 in
all browsers). Previously, if you go to a fragment, the caret isn't
moved. Now it works as expected.
2024-09-23 20:33:46 +08:00
John Factotum b8a0d11910 Paginator: fix changing background in Chromium 2024-09-23 16:48:11 +08:00
John Factotum e6937eed15 Paginator: fix focus lost when loading new section
Also add method for setting focus on the content window
2024-09-15 13:13:44 +08:00
John Factotum c17b542b5c Paginator: needn't fix tabbing in scrolled mode 2024-09-14 23:18:27 +08:00
John Factotum 3b96ddf3e6 Paginator: fix scroll offset when tabbing 2024-09-14 23:14:04 +08:00
John Factotum 327031aca1 Paginator: add scroll event
Unlike `relocate`, which is debounced, a scroll event is useful when you
want to do stuff as soon as it scrolls.
2024-09-12 05:30:58 +08:00
John Factotum 92964699af Paginator: make grid columns follow text block
This is a purely internal change, but it might make things easier in the
future if one wants to place stuff on the margins (e.g. to fade the edge
of the iframe when animating, or place prev/next buttons on the sides)
2024-06-22 18:34:19 +08:00
John Factotum b7ff640943 Paginator: prevent spread in portrait
Or, for vertical writing, in landscape
2024-04-27 16:14:36 +08:00
John Factotum b45e08b10b Paginator: fix unnecessary wrapping in tables
Fixes https://github.com/johnfactotum/foliate/issues/1278
2024-03-25 05:52:49 +08:00
John Factotum b0d7ed481f Paginator: destroy view before removing it 2024-03-23 12:12:39 +08:00
John Factotum 18159a4d07 Don't check document's existence when expanding
`expand()` is only called after `render()`, which assumes that it exists
2024-03-21 20:22:31 +08:00
John Factotum b0a869b7ed Fix page end cut off when starting with page break
Fixes https://github.com/johnfactotum/foliate/issues/1179
2024-03-20 08:44:47 +08:00
John Factotum cbe9e0009c Make animation setting an attribute instead of a property 2023-11-28 11:07:56 +08:00
John Factotum 2ea63929c7 Fix broken layout when book has !important styles 2023-11-15 04:33:02 +08:00
John Factotum 05329eba6e Fix viewer background not updated when page background changes
Bit of a band-aid fix. Ideally it should have some sort of
"ComputedStyleObserver" but this should fix the most common problem
for now.
2023-10-27 15:13:54 +08:00
John Factotum ecefeb86e1 TTS: split document into ranges of block elements 2023-10-01 01:18:43 +08:00
John Factotum 3833ce5702 Paginator: make scrollToAnchor() public 2023-09-27 02:15:09 +08:00
John Factotum ad25f6b5c3 Paginator: fix anchoring in scrolled mode
Anchoring triggers the `scroll` event, which in scrolled mode causes
`#afterScroll()` to be called again with the reason `scroll`, which
shouldn't happen as it's just anchoring, not scrolling.
2023-08-26 06:32:32 +08:00
John Factotum df95960f82 Expose relocation reason
And fix history not updated when scrolling in scroll mode
2023-08-17 15:18:20 +08:00
John Factotum 44c5eca4e9 Paginator: add scroll amount option 2023-08-11 08:14:30 +08:00
John Factotum 5261c48a90 Paginator: account for margin when getting visible area in scrolled mode
Follows 17fb71943f
2023-06-03 01:26:35 +08:00
John Factotum 4732a23e17 Paginator: allow touchscreen pinch zoom 2023-06-02 22:01:36 +08:00
John Factotum 481d28cced Clamp divisor
Although the max width is min-inline-size * max-column-count, sometimes
the actual width apparently doesn't match that exactly.
2023-06-02 04:45:34 +08:00
John Factotum 2e5dda77e0 Unload section when destroying the renderer 2023-06-01 01:44:00 +08:00
John Factotum 14067fe683 Add workaround for Firefox's broken resize observer 2023-05-31 20:09:31 +08:00
John Factotum d5d1541d3b Paginator: use CSS grid
Massively simplify margin/padding and header/footer layout and eliminate
unnecessary resizes and resize loops.

Also remove layout and style API from View, as these are only applicable
to the paginator.
2023-05-28 22:17:56 +08:00
John Factotum 21744e3c85 Fix touch swiping for vertical writing 2023-05-28 21:22:14 +08:00
John Factotum 0be94135fa Fix positioning of the overlayer 2023-05-27 19:18:31 +08:00
John Factotum abcd87ed9a Fix RTL 2023-05-27 02:20:07 +08:00
John Factotum 90a1706e82 Make scrollBy and snap accept both axes
So that event handlers don't need to know the axis
2023-05-27 01:45:49 +08:00
John Factotum 81c595fcc3 Animate scroll manually instead of using scroll-behavior smooth 2023-05-27 00:26:46 +08:00
John Factotum 4c481214cb Fix page flip throttling 2023-05-27 00:06:27 +08:00