From 96594fbe1becbe79f57e5763d24c013ad5990559 Mon Sep 17 00:00:00 2001 From: Akiba So Date: Tue, 23 Jun 2026 10:04:38 +0800 Subject: [PATCH] feat(route): search opens PDFs in pen editor too The search-result document jump still opened the OLD PdfAnnotatorScreen, the last live entry to it. Route it to PenEditorScreen instead, and add an initialPage param to the editor so the jump lands on the hit's page (clamped to the document range once it loads). With this, PenEditorScreen is the ONLY reachable PDF surface; the old annotator is now dead code (no remaining references). flutter analyze: 0 issues. Full suite: 258/258. --- lib/editor/canvas/pen_editor_screen.dart | 18 ++++++++++++++++-- lib/screens/search_screen.dart | 4 ++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/editor/canvas/pen_editor_screen.dart b/lib/editor/canvas/pen_editor_screen.dart index 631efe1..146dfca 100644 --- a/lib/editor/canvas/pen_editor_screen.dart +++ b/lib/editor/canvas/pen_editor_screen.dart @@ -41,10 +41,18 @@ String _documentIdFromPath(String path) { } class PenEditorScreen extends StatefulWidget { - const PenEditorScreen({super.key, required this.pdfPath}); + const PenEditorScreen({ + super.key, + required this.pdfPath, + this.initialPage = 0, + }); final String pdfPath; + /// 0-based page to open on (e.g. a search-result jump). Clamped to the + /// document's page range once it loads. + final int initialPage; + @override State createState() => _PenEditorScreenState(); } @@ -212,7 +220,13 @@ class _PenEditorScreenState extends State { doc.dispose(); return; } - setState(() => _document = doc); + setState(() { + _document = doc; + // Honor a requested initial page (search-result jump), clamped. + if (doc.pages.isNotEmpty) { + _pageIndex = widget.initialPage.clamp(0, doc.pages.length - 1); + } + }); } catch (e) { if (mounted) setState(() => _openError = e); } diff --git a/lib/screens/search_screen.dart b/lib/screens/search_screen.dart index 3a56e6e..99e8730 100644 --- a/lib/screens/search_screen.dart +++ b/lib/screens/search_screen.dart @@ -3,11 +3,11 @@ import 'dart:async'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; +import '../editor/canvas/pen_editor_screen.dart'; import '../l10n/app_localizations.dart'; import '../models/note.dart'; import '../providers/search_provider.dart'; import 'note_editor_screen.dart'; -import 'pdf_annotator_screen.dart'; class SearchScreen extends ConsumerStatefulWidget { const SearchScreen({super.key}); @@ -222,7 +222,7 @@ class _DocumentSearchResultTile extends StatelessWidget { Navigator.of(context).push( MaterialPageRoute( builder: (_) => - PdfAnnotatorScreen(filePath: filePath, initialPage: pageNumber), + PenEditorScreen(pdfPath: filePath, initialPage: pageNumber), ), ); },