OfficeDev / office-js

A repository for issues related to the Office JavaScript APIs and Office Add-ins platform. Find the Office.js library in Office.js CDN: https://appsforoffice.microsoft.com/lib/1/hosted/office.js.
https://learn.microsoft.com/javascript/api/overview
Other
725 stars 106 forks source link

Word.Range Search returns Range or RangeCollection online, but only RangeCollection on Desktop (PC and Mac) #5510

Closed dweill closed 2 weeks ago

dweill commented 1 month ago

Provide required information needed to triage your issue

When getting a document selection and performing a search

range.search('hello')

If there is only one instance of the search text in the document, Range.search returns a Range for the online version, but a RangeCollection for desktop. If there are multiple matches it correctly returns a RangeCollection, per the api documentation

Your Environment

Expected behavior

I would expect that calling the Range.search method returns a RangeCollection both online and on desktop versions of the office js api.

Current behavior

Currently, in the online version of the office js api, Range.search returns a RangeCollection OR a Range (if there is only one match)

An improvement would be for it to always return a RangeCollection or note the different behavior on the web in the documentation

Steps to reproduce

  1. Using office on the web (Word) perform a search on a range (Range.search) for text that appears only once in the document
  2. await context.sync();
  3. log the result.
  4. see that it logs a Range, and not the expected RangeCollection

Link to live example(s)




Provide additional details




Context

Useful logs

Thank you for taking the time to report an issue. Our triage team will respond to you in less than 72 hours. Normally, response time is <10 hours Monday through Friday. We do not triage on weekends.

penglongzhaochina commented 1 month ago

hi @dweill ,

Thank you for reporting the issue. I can't reproduce your case on word online. It all return rangeCollection no matter how many string hit. Like below picture. Could you please share more details about reproducing step or screen shot? Thanks.

Image

dweill commented 1 month ago

Hmm strange, I can no longer reproduce it either. I originally noticed it because my code would error when invoking the getFirst method on the range search result, but that seems to be working now. Thank you for your prompt response and feedback.

penglongzhaochina commented 1 month ago

@dweill , no problem, I will close this issue since you can't reproduce it any more.