Skip to content
Open
Changes from 1 commit
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
18 changes: 11 additions & 7 deletions web/pdf_find_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,11 @@ class PDFFindController {
#convertToRegExpString(query, hasDiacritics) {
const { matchDiacritics } = this.#state;
let isUnicode = false;
const rawQuery = this._rawQuery ?? this.#state?.query;
const queryHasWhitespace =
typeof rawQuery === "string"
? /\s/.test(rawQuery)
: Array.isArray(rawQuery) && rawQuery.some(q => /\s/.test(q));
query = query.replaceAll(
SPECIAL_CHARS_REG_EXP,
(
Expand All @@ -718,16 +723,16 @@ class PDFFindController {
p4 /* diacritics */,
p5 /* letters */
) => {
// We don't need to use a \s for whitespaces since all the different
// kind of whitespaces are replaced by a single " ".
// We don't need \s because all whitespace is normalized to a single " ".

if (p1) {
// Escape characters like *+?... to not interfere with regexp syntax.
return `[ ]*\\${p1}[ ]*`;
// Escaped metacharacters like . * + ? ...
// Allow spaces around them ONLY if the user typed spaces.
return queryHasWhitespace ? `[ ]*\\${p1}[ ]*` : `\\${p1}`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you want to do that ?

}
if (p2) {
// Allow whitespaces around punctuation signs.
return `[ ]*${p2}[ ]*`;
// Punctuation: allow optional spaces ONLY if the user typed spaces.
return queryHasWhitespace ? `[ ]*${p2}[ ]*` : `${p2}`;
}
if (p3) {
// Replace spaces by \s+ to be sure to match any spaces.
Expand Down Expand Up @@ -906,7 +911,6 @@ class PDFFindController {
.then(
textContent => {
const strBuf = [];

for (const textItem of textContent.items) {
strBuf.push(textItem.str);
if (textItem.hasEOL) {
Expand Down