Conversation
…hout waiting getSelectedText() is async only because a selection spanning three or more pages may need the text of the pages in between. The text of both ends is always loaded, and the pages in between are usually cached, so a synchronous menu or tooltip builder can show the selection right away. selectedTextIfLoaded returns it from the cache, or null when a page in between is not cached yet. getSelectedTextRanges() now loads the pages in between and then reads the same cache, so both paths share one implementation.
palmoni5
added a commit
to palmoni5/otzaria
that referenced
this pull request
Oct 5, 2026
pdfrx החזיר את הטקסט המסומן רק אחרי המתנה (Future), ולכן התפריט, שנבנה בלי לחכות, לא יכול היה לצטט אותו. בפורק נוסף selectedTextIfLoaded, שמחזיר את הבחירה מיד מתוך מטמון הטקסט, או null אם עמוד באמצע הבחירה טרם נטען (espresso3389/pdfrx#733). - buildSearchAllBooksIconAction מקבל ReaderMenuSelection בשתי התצוגות, והרמז נבנה במקום אחד. - ב-PDF הבחירה נקראת בפתיחת התפריט ומשמשת גם לחיפוש עצמו. רק כשהיא עוד לא טעונה ממתינים ל-getSelectedText. - pdfrx ו-pdfrx_engine מוצמדים ל-ff9785dd בפורק, ו-Otzaria#733 נוסף לרשימת ה-PR שאחריהם חוזרים ל-pub.dev.
Y-PLONI
pushed a commit
to palmoni5/otzaria
that referenced
this pull request
Oct 5, 2026
pdfrx החזיר את הטקסט המסומן רק אחרי המתנה (Future), ולכן התפריט, שנבנה בלי לחכות, לא יכול היה לצטט אותו. בפורק נוסף selectedTextIfLoaded, שמחזיר את הבחירה מיד מתוך מטמון הטקסט, או null אם עמוד באמצע הבחירה טרם נטען (espresso3389/pdfrx#733). - buildSearchAllBooksIconAction מקבל ReaderMenuSelection בשתי התצוגות, והרמז נבנה במקום אחד. - ב-PDF הבחירה נקראת בפתיחת התפריט ומשמשת גם לחיפוש עצמו. רק כשהיא עוד לא טעונה ממתינים ל-getSelectedText. - pdfrx ו-pdfrx_engine מוצמדים ל-ff9785dd בפורק, ו-Otzaria#733 נוסף לרשימת ה-PR שאחריהם חוזרים ל-pub.dev.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
PdfTextSelection.getSelectedText()is async, so code that builds UI synchronously can't show the selected text, for example a context-menu builder that puts the selection into a tooltip such asSearch "…". The only real wait is for a selection that spans three or more pages, where the text of the pages in between may not be loaded yet. The text of both ends is always loaded, and the pages in between are almost always cached already, because the user dragged the selection through them.Change
PdfTextSelection.selectedTextIfLoaded: returns the selected text right away from the viewer's text cache, ornullwhen a page in between has not loaded its text yet. Callers can fall back togetSelectedText().getSelectedTextRanges()andgetSelectedText()are unchanged. They keep the selection ends they started with while the pages in between load, so clearing or replacing the selection meanwhile doesn't change the result of an extraction that is already running.Adding an abstract member to
PdfTextSelectionwould break third-party implementers. The only implementer in the package is_PdfViewerState.Tests
New tests in
pdf_viewer_selection_drag_test.dart:selectedTextIfLoadedon a single-page selection and on a three-page selection, where it equalsawait getSelectedText().selectedTextIfLoadedisnulluntil the pages in between are loaded, and then returns the full selection.getSelectedText()keeps its selection when the selection is cleared or replaced.flutter analyzeandflutter testinpackages/pdfrxpass.