-
Notifications
You must be signed in to change notification settings - Fork 10.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added multiple term search functionality (with default phrase search) #5579
Conversation
What exactly are the differences with #5496? Good to know so we can compare them. |
Disadvantages of #5496:
|
Advantages of my solution:
|
@@ -6,3 +6,4 @@ tags | |||
Makefile | |||
node_modules/ | |||
examples/node/svgdump/ | |||
.idea |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this change.
That is really good to know. Your solution looks pretty clean. I have added some comments to be addressed for this PR. Thanks! |
All defects fixed. |
Really nice. Could you also squash the commits into one commit so it can be reviewed more easily? See https://github.com/mozilla/pdf.js/wiki/Squashing-Commits on how to do this. |
Done |
PDFViewerApplication.findBar.findField.value = hashParams['search']; | ||
PDFViewerApplication.findBar.dispatchEvent('again', false); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this code be moved to the PDFViewerApplication.setHash?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Besides moving this into setHash
, I also think that the if
's needs to be enclosed in !PDFViewerApplication.supportsIntegratedFind
check. Otherwise this will result in strange behaviour in the Firefox versions of PDF.js.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yurydelendik, @Snuffleupagus, yes, you are right. But in some cases requires to use PDF.js search toolbar despite the fact that the built-in search is also available.
For example, PDF.js is used in iframe as part of the third-party applications. It is very important for our application.
What the best way to do it? Maybe we can use the new hash tag #disableIntegratedFind and set supportsIntegratedFind in false, if #disableIntegratedFind = true?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if I completely understand your questions/concerns here!?
Regarding moving the code into setHash
: that shouldn't be an issue as far as I can tell, so please try moving this code there instead.
But in some cases requires to use PDF.js search toolbar despite the fact that the built-in search is also available.
Please note that there are some search related features that, for security reasons, are currently disabled in the Firefox versions of PDF.js. So for now, I personally don't see why the feature in this PR would be any different. See e.g. viewer.js#L711-L713.
For example, PDF.js is used in iframe as part of the third-party applications.
Please note that supportsIntegratedFind
is only ever true
in the Firefox versions of PDF.js, and only when the viewer is used standalone.
In all other versions of the viewer, and certainly when it's in an iframe, supportsIntegratedFind === false
, so that shouldn't be an issue. See viewer.js#L326-L337.
It is very important for our application.
I understand that, but showing the PDFFindBar
in the Firefox versions of PDF.js could be confusing for users given that it's normally not used there.
(The main use case for the viewer is, after all, to be the user interface of PDF.js for Firefox.)
What the best way to do it? Maybe we can use the new hash tag #disableIntegratedFind and set supportsIntegratedFind in false, if #disableIntegratedFind = true?
Letting hash parameters enable/disable functions in PDF.js is a bad practice, which we are actively moving away from.
Given my answers above, I don't think that you actually need a way to toggle this feature, so I (currently) see no reason to add a parameter to the API either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you are right. This feature is not needed.
All suggestions have been implemented |
if (!this.supportsIntegratedFind) { | ||
if ('phrase' in params) { | ||
this.findBar.phraseSearch.checked = | ||
(params['phrase'] === 'true'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: this should fit on the previous line, please move it there instead.
I've added a couple of small comments about the coding style. Once you've addressed them, please squash the commits. |
@D4FR3NCH We reduced scope of this PR by removing UI changes for speeding UP the landing of this PR. Multi term search works, but it's hard to see it :) UI changes will be implemented in next PR. |
Based on e.g. the #5579 (comment) by @yurydelendik, I'd expect that this patch does not change the default find behaviour in the PDF.js find bar/Firefox integrated find, but rather only adds support for the However, as is, this patch is changing the default find behaviour in PDF.js:
AR: ER: Even if the behaviour of the Wouldn't it make more sense to keep the current behaviour for the PDF.js find bar/Firefox find integration? E.g. by instead setting |
@Snuffleupagus @yurydelendik What should be the behavior in this case (described by @Snuffleupagus)? |
The current find behavior shall not change (with or without #search= parameter), so it shall use phaseSearch=true. For
The #search= has weird syntax |
Few more changes, I think these will be the last. Thanks for addressing the comments fast!
|
Review status: all files reviewed at latest revision, 4 unresolved discussions. web/app.js, line 1920 [r3] (raw file):
|
/botio-windows preview |
From: Bot.io (Windows)ReceivedCommand cmd_preview from @yurydelendik received. Current queue size: 0 Live output at: http://107.22.172.223:8877/d18363a9b2ee6f8/output.txt |
From: Bot.io (Windows)SuccessFull output at http://107.22.172.223:8877/d18363a9b2ee6f8/output.txt Total script time: 1.93 mins Published |
@@ -1251,6 +1251,7 @@ var PDFViewerApplication = { | |||
eventBus.on('rotateccw', webViewerRotateCcw); | |||
eventBus.on('documentproperties', webViewerDocumentProperties); | |||
eventBus.on('find', webViewerFind); | |||
eventBus.on('findFromUrlHash', webViewerFindFromUrlHash); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Please change the event name to lower-case, so that it's consistent with all the existing ones.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Reviewed 4 of 4 files at r4, 2 of 2 files at r5. Comments from Reviewable |
Thank you for the patch. |
Nice work! |
Cool, thanks! |
Wow, I thought that would never happen 👍 |
Weird, I'm trying http://mozilla.github.io/pdf.js/web/viewer.html#search=Java and it rarely loads up the query + scroll to first match. It's like it only works the first time, and then if I reload it doesn't work anymore. Maybe these changes are not already available in that URL? |
If URL hash doesn't change (if your press F5 or reload page it doesn't change), in IE and Chrome PDFLinkService_setHash method doesn't run. In Firefox it works fine. |
Yep, works only first time, doesn't on reload. It scrolls back to where I was. |
I believe you may have to fire the first event with inline script or a setTimeout on refresh. We run into this problem with other code and apps quite frequently. The next pages will highlight fine. |
Looks like this problem is not related to this PR, so discussion is somewhat off-topic. @dasilvacontin, could you create a separate issue, and provide all details such as your configuration and steps to reproduce? (Personally I'm confused about "first time" and "if I reload it" terms)
The same here "inline script" or "setTimeout on refresh" -- not sure what does it mean in PDF.js context but it sounds like "magic". BTW, inline scripts are not used for security reason and setTimeout is bad practice in async apps. |
I am trying to search tracemonkey for "Dynamic languages", "Google Docs", and JavaScript at the same time. How would I construct my URL? This used to work in #5496. Could someone post an example? Thanks. |
This PR has been merged a month ago and is quite big now in terms of comments, so please use IRC/the mailing list for questions and the issue tracker for actual problems regarding this PR. |
This pull-request is very similar to #5496
Change allows:
Examples:
find phrase 'Locking tames tamed tame':
search=Locking%20tames%20tamed%20tame&phrase=true
or
search=Locking%20tames%20tamed%20tame
find multiple term search 'Locking tames tamed tame':
search=Locking%20tames%20tamed%20tame&phrase=false
Screenshots:
This change is