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

Word.API body.search() does not match paragraphs with footnote or endnote #4401

Closed
mscc-sascha opened this issue Apr 25, 2024 · 4 comments
Closed
Assignees
Labels
Area: Word Issue related to Word add-ins Needs: attention 👋 Waiting on Microsoft to provide feedback

Comments

@mscc-sascha
Copy link

mscc-sascha commented Apr 25, 2024

Provide required information needed to triage your issue

If a paragraph in MS Word contains a footnote or endnote and I try to search for the entire paragraph with context.document.body.search(), the result is empty.

Your Environment

  • Platform [PC desktop, Mac, iOS, Office on the web]: Office on the web, PC dekstop, Mac
  • Host [Excel, Word, PowerPoint, etc.]: Word
  • Office version number: Office Online

Expected behavior

The entire paragraph should be matched when I search for the text.

Current behavior

No results available if I search for a part of the paragraph when there is a footnote or endnote in between.

Steps to reproduce

  1. Create a word document and insert a sample paragraph (e.g. Video provides a powerful way to help you prove your point. )
  2. Insert a footnote to any word in the sentence
  3. Search for the entire paragraph using OfficeJS
    context.document.body.search("Video provides a powerful 1way to help you prove your point.")
  4. Search result will be empty

Link to live example(s)

Snippets for Script Lab

Script

$("#basic-search").on("click", () => tryCatch(basicSearch));

async function basicSearch() {
  // Does a basic text search and highlights matches in the document.
  await Word.run(async (context) => {
    const match = context.document.body.search("Video provides a powerful 1way to help you prove your point.");

    match.load("items");

    await context.sync();

    const startRange = match.items[0];
    startRange.select();

    await context.sync();
  });
}

async function tryCatch(callback) {
  try {
    await callback();
  } catch (error) {
    // Note: In a production add-in, you'd want to notify the user through your add-in's UI.
    console.error(error);
  }
}

HTML

<section class="ms-font-m">
	Sample
</section>

<section class="samples ms-font-m">
	<button id="basic-search" class="ms-Button">
    <span class="ms-Button-label">Search entire paragraph</span>
  </button>
</section>

CSS

section.samples {
    margin-top: 20px;
}

section.samples .ms-Button, section.setup .ms-Button {
    display: block;
    margin-bottom: 5px;
    margin-left: 20px;
    min-width: 80px;
}

Libraries

https://appsforoffice.microsoft.com/lib/1/hosted/office.js
@types/office-js

office-ui-fabric-js@1.4.0/dist/css/fabric.min.css
office-ui-fabric-js@1.4.0/dist/css/fabric.components.min.css

core-js@2.4.1/client/core.min.js
@types/core-js

jquery@3.1.1
@types/jquery@3.3.1
Copy link
Contributor

Thank you for letting us know about this issue. We will take a look shortly. Thanks.

@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs: attention 👋 Waiting on Microsoft to provide feedback label Apr 25, 2024
@xiruatms
Copy link

@mscc-sascha , thanks for reporting this.

I assuming you're trying to search some words with marker for footnote/endnote as following:
image

Is that correct?

As the screenshot shows, this is not supported with Word on Win32 or Online.

@mscc-sascha
Copy link
Author

@xiruatms Thanks for verifying! You are right, the default search in MS Word does not match the parts neither. We will implement a work around then.

@xiruatms
Copy link

Thanks for your confirmation. Close this ticket as agreed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Word Issue related to Word add-ins Needs: attention 👋 Waiting on Microsoft to provide feedback
Projects
None yet
Development

No branches or pull requests

3 participants