weixin_39981360 2020-11-30 05:06
浏览 0

range.deleteContents() doesn't delete all contents in some cases

From vladimir....de on January 04, 2013 14:05:55

What steps will reproduce the problem? 1. Check this fiddle http://jsfiddle.net/Szy8Z/2/ 2. Just select everything inside the div#text by CTRL + A 3. Click on "Delete selected contents" What is the expected output? What do you see instead? Everything should be deleted inside the first div but insted of this an empty a tag is still there. What version of the product are you using? On what operating system? rangy 1.2.3 / Windows 7 / Chrome 23 Please provide any additional information below. The same error can be seen on your Rangy Core Demo page. Just add a hyperlink into the contenteditable p (under "Competitions"), click inside the p, select all (CTRL + A) and try to delete selection or delete range. In both cases the a tag stays undeleted.

Original issue: http://code.google.com/p/rangy/issues/detail?id=144

该提问来源于开源项目:timdown/rangy

  • 写回答

10条回答 默认 最新

  • weixin_39981360 2020-11-30 05:06
    关注

    From timd....com on January 04, 2013 07:09:27

    This is a unfortunate consequence of WebKit's idea of where selections start and end. When you select the whole of the div's contents, the range that WebKit's selection provides ends at the end of the text node in the final link rather than after the link. See http://jsfiddle.net/tAYVx/ That being the case, the link isn't wholly contained within the selection range and hence is not removed.

    I made the decision right at the start not to have Rangy try to "correct" selections like that as it would not reflect the reality of the browser's internal representation of the selection. However, this kind of problem has come up a few times, so I'm considering adding a method to range to extend the range to completely encompass elements whose text is completely contained within the range. Another alternative would be to add a method to the selection, similar to the existing deleteFromDocument() method.

    评论

报告相同问题?