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

rangy.getSelection().getRangeAt(0).getNodes([1]) returns empty #440

Closed
dportabella opened this issue Mar 7, 2018 · 1 comment
Closed

Comments

@dportabella
Copy link

rangy.getSelection().getRangeAt(0).getNodes([1]) returns empty for a selected text, when this text is a one unique word surrounded by tag.

Test: double click on "oneword" to select the text, and then press the button. it shows that getNodes returns an empty array (this looks like a bug of rangy). note: you can see that rangy created the span tag and it is not yellow. select the "two words" or a part of it, and click test, and you will see that getNodes returns a non-empty array (as expected). remember to reload the page when testing, as rangy is adding spans.

rangy.init();

function test() {
  rangyOptions = { useExistingElements: false };
  applier = rangy.createClassApplier("myclass", rangyOptions);
  applier.applyToSelection();

  var nodes = rangy.getSelection().getRangeAt(0).getNodes([1]);
  console.log(nodes);
  console.log(nodes.length);
  alert(nodes.length);
}
.myclass {
    background-color: rgba(255, 255, 0, 1);
}
<div>two words</div>
<div>oneword</div>
<button onclick="test()">test</button>
<script src="https://cdnjs.cloudflare.com/ajax/libs/rangy/1.3.0/rangy-core.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/rangy/1.3.0/rangy-classapplier.js"></script>

Issue from:
https://stackoverflow.com/questions/49156179/rangy-getselection-getrangeat0-getnodes1-returns-empty

@dportabella
Copy link
Author

I've opened a new issue better explained:
#441

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant