rangy icon indicating copy to clipboard operation
rangy copied to clipboard

Suitability for document objects

Open pickle-weasle opened this issue 5 years ago • 1 comments

Hi there, I was looking for a library that would allow me to identify html ranges based off index in the plaintext, and Rangy looked like a good fit.

Unfortunately I need to use it on html that is not currently rendered, and I'm not sure that's supported. When trying to implement a proof of concept that used a Document object that I created (rather than the current document or a document in an iframe or other window) I ran into issues where Rangy was trying to get info on the window, to determine computedStyles for elements , I think.

This caused an error ERROR TypeError: "getWindow(...) is null" which occurs in this file after running moveStart method.

I can't seem to find others who've encountered the same issue and wonder if I'm missing something or if there may be another tool that will allow me to do something like the following: Give me the range within this Document/document-fragment Object that contains the text that starts X characters in (not including HTML tags etc, just plain text) and ends Y characters in.

It looks to me that Rangy could accomplish this using the textModules moveStart and moveEnd methods.. if they'd only work on DocumentObjects and not require access to the window.

If I've got something wrong, or if this doesn't quite constitute an issue, my apologies! not sure where else to ask the question Would love to hear any suggestions Thanks!

pickle-weasle avatar Jan 23 '20 01:01 pickle-weasle

@pickle-weasle I have a similar issue. I get the error when running .restoreCharacterRanges() also from the Text Range module.

Did you ever find a workaround?

MimmyJau avatar May 24 '23 20:05 MimmyJau