Closed Bug 135922 Opened 23 years ago Closed 21 years ago

[FIXr]Range.insertNode doesn't split textnodes

Categories

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

defect

Tracking

()

RESOLVED FIXED
mozilla1.4beta

People

(Reporter: peterv, Assigned: bzbarsky)

References

()

Details

(Keywords: dom2)

Attachments

(3 files, 1 obsolete file)

The spec says "If the start boundary point of the Range is in a Text node, the insertNode operation splits the Text node at the boundary point." Mozilla doesn't handle this correctly, we don't split the text node but instead try to append the new node to the text node, which of course always fails.
Attached file Testcase (obsolete) (deleted) —
Blocks: 30838
Priority: -- → P3
Target Milestone: --- → mozilla1.0.1
Status: NEW → ASSIGNED
Target Milestone: mozilla1.0.1 → Future
Keywords: dom2
Unfortunately, the problem is not just that the text node is not split, but that nsRange::insertNode() is broken in just about every conceivable way. http://lxr.mozilla.org/seamonkey/source/content/base/src/nsRange.cpp#2059 2073 if( (nsIDOMNode::CDATA_SECTION_NODE == tNodeType) || 2074 (nsIDOMNode::TEXT_NODE == tNodeType) ) Should be checking type of tStartContainer, not type of node to be inserted. 2081 return tSCParentNode->InsertBefore(aN, tSCParentNode, getter_AddRefs(tResultNode)); 1) Need to splitText if necessary (see SurroundContents for details) 2) Second arg should be tStartContainer, so we don't try to insert before self. 2092 if(tStartOffset == (PRInt32)tChildListLength) Comparison shouldn't be necessary. tChildList->Item() should return null if offset greater than tChildListLength, and tStartContainer->InsertBefore reverts to append if tChildNode is null.
Attached file Another test case (deleted) —
Here's another test case for range.insertNode()
Attachment #78023 - Attachment is obsolete: true
taking
Assignee: kin → bzbarsky
Blocks: 104383
Status: ASSIGNED → NEW
Priority: P3 → P1
Summary: Range.insertNode doesn't split textnodes → [FIX]Range.insertNode doesn't split textnodes
Target Milestone: Future → mozilla1.4beta
Attachment #121596 - Flags: superreview?(peterv)
Comment on attachment 121596 [details] [diff] [review] Patch based on Nathan's suggestion Yay, nsRange!
Attachment #121596 - Flags: review?(caillon) → review+
Attachment #121596 - Flags: superreview?(peterv) → superreview+
Summary: [FIX]Range.insertNode doesn't split textnodes → [FIXr]Range.insertNode doesn't split textnodes
Comment on attachment 121596 [details] [diff] [review] Patch based on Nathan's suggestion Requesting 1.4b approval; this is a simple change to bring us in line with the spec and prevent content disappearing completely when insertNode is used on ranges.
Attachment #121596 - Flags: approval1.4b?
Comment on attachment 121596 [details] [diff] [review] Patch based on Nathan's suggestion a=asa (on behalf of drivers) for checkin to 1.4b
Attachment #121596 - Flags: approval1.4b? → approval1.4b+
Fixed.
Status: NEW → RESOLVED
Closed: 21 years ago
Resolution: --- → FIXED
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

Created:
Updated:
Size: