Closed Bug 43535 Opened 24 years ago Closed 23 years ago

Range.deleteContents() sometimes removing too many nodes

Categories

(Core :: DOM: Core & HTML, defect, P3)

defect

Tracking

()

RESOLVED FIXED
mozilla1.0

People

(Reporter: dannyg, Assigned: kinmoz)

References

Details

(Keywords: dom2)

Attachments

(4 files)

If a range is set to select an element node nested inside a P element and the range contents are deleted, the text node after the selected node is also deleted. The method does the right thing when the range selects a nodes contents. The following test case demonstrates the good (when the range is set via Range.selectNodeContents()) and the bad (when set via Range.selectNode()). The Delete Range Contents button invokes deleteContents() on the current range. Child node count reporting is correct, but the lastChild.nodeValue is not when the nested node has been selected as a range. ---------- <HTML> <HEAD> <TITLE>Range.deleteContents() Method</TITLE> <STYLE TYPE="text/css"> #mySPAN {color:red; font-weight:bold} #nodeCount {font-weight:bold} #lastValue {color:blue} </STYLE> <SCRIPT LANGUAGE="JavaScript"> var rng function selContents() { rng = document.createRange() rng.selectNodeContents(document.getElementById("mySPAN")) } function selNode() { rng = document.createRange() rng.selectNode(document.getElementById("mySPAN")) } function del() { if (rng) { rng.deleteContents() showReadout() rng = null } } function showReadout() { document.getElementById("nodeCount").innerHTML = document.getElementById("myP").childNodes.length document.getElementById("lastValue").innerHTML = document.getElementById("myP").lastChild.nodeValue } </SCRIPT> </HEAD> <BODY onLoad="showReadout()"> <H1>Range.deleteContents() Method</H1> <HR> <BUTTON onClick="selContents()">Set Range to Span Contents</BUTTON> <BUTTON onClick="selNode()">Set Range to Span Node</BUTTON> <BUTTON onClick="del()">Delete Range Contents</BUTTON> <P>P element has <SPAN ID="nodeCount"></SPAN> child node(s).</P> <P>lastChild.nodeValue is: <SPAN ID="lastValue"></SPAN></P> <HR> <P ID="myP"> Lorem ipsum dolor sit, <SPAN ID="mySPAN">consectetaur adipisicing elit, </SPAN> sed do eiusmod tempor incididunt ut labore et dolore aliqua.</P> </BODY> </HTML>
jfrancis, here's one for you, akkana offerd to look at this if you're currently overloaded...
Assignee: jst → jfrancis
accepting bug / m17
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
Target Milestone: --- → M17
future
Target Milestone: M17 → Future
This may be related to http://bugzilla.mozilla.org/show_bug.cgi?id=58213 where selectNode() is not selecting a node as would be expected.
I've seen this bug too. It is still present in the 2000120521 nightly build
Keywords: correctness
OS: Windows 98 → All
Hardware: PC → All
Keywords: dom2
Component: DOM Level 2 → DOM Traversal-Range
I am attaching a JavaScript "Patch" that can be used as a work around for the range object. This patch adds support for the following: Range.innerHTML - read only Range.extractContents - as per W3C specs Range.cloneContents - as per W3C specs Range.insertNode - as per W3C specs Range.surroundContents - as per W3C specs Range.deleteContents - as per W3C specs - fixes buggy support from Mozilla Range.jmyCompareNode - extends Mozilla's compareNode to include the following 2 constants Range.NODE_BEFORE_AND_INSIDE = -1; Range.NODE_INSIDE_AND_AFTER = -2; I would like a C++ programmer to implement these in C if possible. Jeff Yates
Attached file Patch for Range functionality (deleted) —
Attached file JS Patch File (deleted) —
Attached file Test Case (deleted) —
getting all the range bugs grouped with kin...
Assignee: jfrancis → kin
Status: ASSIGNED → NEW
I just checked in a rewrite of CloneContents() and DeleteContents(), into the TRUNK, to fix bug #120366 (Crash in nsRange::CopyContents()). mozilla/content/base/src/nsRange.cpp revision 1.146 mozilla/content/base/src/nsRange.h revision 1.37 That should fix this bug.
Blocks: 30838
Status: NEW → RESOLVED
Closed: 23 years ago
Resolution: --- → FIXED
Target Milestone: Future → mozilla1.0
Component: DOM: Traversal-Range → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: