DOM text
Richard Lewis
richardlewis at fastmail.co.uk
Tue Aug 30 08:00:27 EDT 2005
On Tue, 30 Aug 2005 12:05:38 +0100, "Richard Lewis"
<richardlewis at fastmail.co.uk> said:
>
> On Tue, 30 Aug 2005 11:17:25 +0100, "Richard Lewis"
> <richardlewis at fastmail.co.uk> said:
> >
> > Here is the *complete* code for my SectionCursor class:
>
> In case anyone's interested, I've just noticed a logical error in the
> next_node() method:
OK, I'm beginning to wish I hadn't mentioned this now; I've changed the
insert_node() method as well:
================================
def insert_node(self, ref_doc, new_node):
if self.current_node.nodeType == Node.TEXT_NODE:
parent_node = self.current_node.parentNode
text_node = self.current_node
next_node = text_node.nextSibling
preceeding_portion =
ref_doc.createTextNode(text_node.data[:self.char_pos])
proceeding_portion =
ref_doc.createTextNode(text_node.data[self.char_pos:])
parent_node.replaceChild(preceeding_portion, text_node)
if next_node is None:
parent_node.appendChild(new_node)
parent_node.appendChild(proceeding_portion)
else:
parent_node.insertBefore(new_node, next_node)
parent_node.insertBefore(proceeding_portion, next_node)
# where is the cursor?
else:
parent_node = self.current_node.parentNode
next_node = self.current_node.nextSibling
if next_node is None:
parent_node.appendChild(new_node)
else:
parent_node.insertBefore(new_node, self.current_node)
# where is the cursor?
================================
I've done some more testing and it seems that, after a call to
insert_node() when the current_node is a Text node, current_node's
parentNode, nextSibling and firstChild properties become None (assuming
they weren't None before, which firstChild was).
Hmm. Um...er, yeah. I don't think anyones following me anyway....
I'll keep fiddling with it.
More information about the Python-list
mailing list