Skip to content

feat: PdfTextSearcher.stopTextSearch and PdfViewerController.releaseCachedImages - #730

Open
palmoni5 wants to merge 2 commits into
espresso3389:masterfrom
palmoni5:feat/stop-search-and-release-images
Open

palmoni5 wants to merge 2 commits into
espresso3389:masterfrom
palmoni5:feat/stop-search-and-release-images

Conversation

@palmoni5

Copy link
Copy Markdown
Contributor

Summary

Two small additive APIs. Each is its own commit.

1. PdfTextSearcher.stopTextSearch()

resetTextSearch() is the only way to end a search today, and it also clears the matches. A search pane that offers a "stop" button during a long scan has to throw away what was found.

stopTextSearch():

  • cancels the running or pending search;
  • keeps matches and the current match;
  • sets isSearching to false and notifies listeners.

It also clears the stored condition, so starting the same pattern again searches the whole document.

2. PdfViewerController.releaseCachedImages({bool keepVisible = true})

An app that keeps several viewers alive (tabs in a keep-alive PageView, split panes) holds every viewer's page images until each viewer is disposed. limitRenderingCache/maxImageBytesCachedOnMemory bound one viewer, but not the sum over hidden ones.

releaseCachedImages():

  • disposes the preview and partial images and cancels their pending renders;
  • also clears the magnifier cache.

Released pages are rendered again the next time they are painted. With keepVisible (the default), the images of the pages overlapping the visible rect are kept, so showing the viewer again does not flash blank pages.

Testing

  • test/pdf_text_searcher_test.dart (new): stopping mid-scan keeps the matches of the pages already searched, notifies once, and a re-issued pattern searches all pages again.
  • releaseCachedImages has no dedicated test. The image cache is private, and the effect is native memory. It is exercised in Otzaria, which calls it when a PDF tab leaves the screen.
  • packages/pdfrx: PDFIUM_PATH=... flutter test: all tests passed.
  • flutter analyze lib test: clean apart from the pre-existing info in test/lazy_loading_test.dart.

Independent of #729; the two touch nearby lines in pdf_viewer.dart and pdf_text_searcher.dart, so whichever lands second may need a trivial rebase.

resetTextSearch was the only way to end a search, and it also cleared the matches. stopTextSearch cancels the running (or pending) search, keeps matches and the current match, and notifies listeners. Re-issuing the same pattern then searches the whole document again.
… off screen

An app that keeps several viewers alive (e.g. tabs in a keep-alive PageView) holds every viewer's page images until the viewer is disposed. releaseCachedImages disposes them and cancels their pending renders; released pages are rendered again the next time they are painted. By default the images of the pages on screen are kept, so showing the viewer again does not flash blank pages.
palmoni5 added a commit to palmoni5/otzaria that referenced this pull request Sep 27, 2026
הענף perf/viewer-render-order מכיל עכשיו גם את stopTextSearch ואת releaseCachedImages. חוזרים ל-pub.dev רק אחרי ש-Otzaria#724, Otzaria#729 ו-Otzaria#730 ימוזגו וישוחררו.
Y-PLONI pushed a commit to palmoni5/otzaria that referenced this pull request Sep 28, 2026
הענף perf/viewer-render-order מכיל עכשיו גם את stopTextSearch ואת releaseCachedImages. חוזרים ל-pub.dev רק אחרי ש-Otzaria#724, Otzaria#729 ו-Otzaria#730 ימוזגו וישוחררו.

This branch has not been deployed

No deployments
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.

1 participant