Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions lib/src/engine/epub/epub_viewport.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1325,23 +1325,31 @@ final class _EpubViewportState extends State<EpubViewport> {
(direction < 0 && !neighbor.complete)) {
return const ReaderLoading();
}
return _spread(
neighbor.pages,
direction > 0
? 0
: (neighbor.pages.length / columns).ceil() -
1,
columns,
displayPreferences,
spine: spine,
return SelectionContainer.disabled(
child: _spread(
neighbor.pages,
direction > 0
? 0
: (neighbor.pages.length / columns)
.ceil() -
1,
columns,
displayPreferences,
spine: spine,
),
);
}
return _spread(
final spread = _spread(
pages,
local,
columns,
displayPreferences,
);
// Offscreen spreads can be kept alive with a zero paint transform.
// Only the visible text can participate in a touch selection.
return local == _pageIndex
? spread
: SelectionContainer.disabled(child: spread);
},
),
),
Expand Down
63 changes: 63 additions & 0 deletions test/presentation/epub_selection_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,69 @@ import '../support/in_process_epub_worker.dart';
import '../support/synthetic_epub.dart';

void main() {
testWidgets('touch selects a word after a page turn within a long chapter', (
tester,
) async {
tester.view.devicePixelRatio = 1;
tester.view.physicalSize = const Size(390, 844);
addTearDown(tester.view.reset);
final engine = testEpubEngine();
ReaderSelection? saved;
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(platform: TargetPlatform.android),
home: PapyrusReader(
initialPreferences: const ReaderPreferences(
fontSize: 16,
columnMode: ReaderColumnMode.single,
),
document: ReaderDocument(
id: 'long-chapter',
format: ReaderFormat.epub,
loadBytes: () async =>
syntheticEpub(longChapter: true, singleSpine: true),
),
registry: ReaderEngineRegistry([
ReaderEngineRegistration(
formats: const {ReaderFormat.epub},
factory: () => engine,
),
]),
onAnnotate: (selection) => saved = selection,
),
),
);
await tester.pumpAndSettle();
final text = find.byWidgetPredicate(
(widget) =>
widget is RichText &&
widget.text.toPlainText().startsWith('Paragraph '),
);
// Reproduce a page kept alive by the platform after it leaves the viewport.
final keepAlive = KeepAliveHandle();
addTearDown(keepAlive.dispose);
KeepAliveNotification(
keepAlive,
).dispatch(tester.element(text.hitTestable().first));
await tester.pump();
await pumpReaderCommand(tester, engine.goNext());
expect(engine.locator.textOffset, greaterThan(0));
final paragraph = tester.renderObject<RenderParagraph>(
text.hitTestable().at(1),
);
final target = paragraph
.getBoxesForSelection(
const TextSelection(baseOffset: 1, extentOffset: 2),
)
.first;
await tester.longPressAt(paragraph.localToGlobal(target.toRect().center));
await tester.pumpAndSettle();
expect(tester.takeException(), isNull);
await tester.tap(find.text('Annotate'));
await tester.pumpAndSettle();
expect(saved?.text, 'Paragraph');
});

for (final (kind, animation) in [
(PointerDeviceKind.mouse, true),
(PointerDeviceKind.touch, true),
Expand Down
Loading