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

Can't find and highlight words hyphenated across lines #125

Closed
nataliia-obraztsova opened this issue Jul 9, 2024 · 0 comments · Fixed by #129
Closed

Can't find and highlight words hyphenated across lines #125

nataliia-obraztsova opened this issue Jul 9, 2024 · 0 comments · Fixed by #129
Labels
bug Something isn't working

Comments

@nataliia-obraztsova
Copy link

Problem description

Words, that are hyphenated across lines are not matched by searchQuery.
searchQuery function doesn't remove hyphens in case textItem.hasEOL. Following replacement of "\n" with a white space also adds a white space in the middle of a word.

Example 1: phrase until a hyphen is matched

const highlightText = ref('Dynamic languages such as JavaScript are more difficult to com')
image

Example 2: phrase containing a word without a hyphen is no longer matched

const highlightText = ref('Dynamic languages such as JavaScript are more difficult to compile')
image

Example 3: phrase containing a word with a hyphen and a white space is matched again

const highlightText = ref('Dynamic languages such as JavaScript are more difficult to com- pile')
image

Expected behavior

String 'Dynamic languages such as JavaScript are more difficult to compile' is highlighted.

Possible solution

A possible solution would be to remove line break hyphens in the middle of words when joining lines together. And to refrain from adding a white space between this line and the next line.

Code to reproduce

<template>
    <VuePDF :pdf="pdf" text-layer :highlight-text="highlightText" :highlight-options="highlightOptions"/>

</template>

<script setup lang="ts">
import { VuePDF, usePDF } from '@tato30/vue-pdf'
import { ref } from 'vue'
import '@tato30/vue-pdf/style.css';

const pdfLink = 'https://raw.githubusercontent.com/mozilla/pdf.js/ba2edeae/web/compressed.tracemonkey-pldi-09.pdf'
const { pdf } = usePDF(pdfLink)

const highlightText = ref('Dynamic languages such as JavaScript are more difficult to com- pile')
const highlightOptions = ref({
  completeWords: false,
  ignoreCase: true,
})
</script>

<style scoped>
</style>

Configuration:

  • vue-pdf: 4.3.0
  • vue: 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants