Document.body.search filters out relevant hit
Our Word add-in needs to select a piece of text between startOffset A and endOffset B. Since the Office JS API doesn't provide a way to set a selection between start/end positions the body text, we use the search function. This works fine in most cases, however not when the same text is repeated multiple times.
Suppose i want to select "test test" in the document body "test test test". There are two occurrences of "test test" in this document body but the search API only finds one: "[test test] test". I need to select the second occurrence, "test [test test]", but can't seem to get the search API to find it.
Has anyone else found a solution for this issue?
@Nils Lockean I'm checking with the team to see if they have any suggestions.
Hi @Nils Lockean , which platform are you using?
Hi @Phoebe Yuan ! I am using the Office JS API on the following platforms:
- Word on iPad
- Word on Mac (Microsoft 365)
- Word 2016 or later on Mac
- Word 2019 or later on Mac
- Word on the web
- Word 2013 or later on Windows
- Word 2016 or later on Windows
- Word 2019 or later on Windows
- Word on Windows (Microsoft 365)
Hey currently the search API can only recognize "[test test] test" inside "test test test" and it is aligned with search feature's design. For selecting a piece of text between startOffset A and endOffset B, you may consider posting a feature ask in m365dev-suggestions
Sign in to comment