Skip to content
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

Text highlighting from recipes doesn't match anything over a word #641

Closed
4 tasks done
pedro-surf opened this issue Sep 1, 2020 · 1 comment
Closed
4 tasks done
Labels
duplicate This issue or pull request already exists question Further information is requested

Comments

@pedro-surf
Copy link

Before you start - checklist

  • I followed instructions in documentation written for my React-PDF version
  • I have checked if this bug is not already reported
  • I have checked if an issue is not listed in Known issues
  • If I have a problem with PDF rendering, I checked if my PDF renders properly in Mozilla Firefox

Description

I'm using this highlighting recipe
and it doesn't match any text content if I set my searchText string with more than one word.

Steps to reproduce

Steps to reproduce the behavior:

  1. Set search value with more than one word (e.g.: "working well")

Expected behavior

I'd like to select multiple words.
Thanks a lot for this great package.

Additional information

Code:

function highlightPattern(text, pattern) {
 const splitText = text.split(pattern)
 if (splitText.length <= 1) {
   return text;
 }

 const matches = text.match(pattern);

 return splitText.reduce(
   (arr, element, index) =>
     matches[index]
       ? [
           ...arr,
           element,
           <mark
             ref={(r) =>
               r &&
               r.scrollIntoView({
                 behavior: "smooth",
                 block: "center",
                 inline: "center",
               })
             }
             style={{ backgroundColor: "orange" }}
             key={index}
           >
             {matches[index]}
           </mark>,
         ]
       : [...arr, element],
   []
 );
}
  function makeTextRenderer(searchText) {
    return function textRenderer(textItem) {
      return highlightPattern(textItem.str, searchText);
    };
  }

Environment

  • React-PDF: latest
  • React:latest
  • Electron: latest
@pedro-surf
Copy link
Author

I think it's a duplicate? Sorry

@wojtekmaj wojtekmaj added duplicate This issue or pull request already exists question Further information is requested labels Oct 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants