Home Forums General XMetaL Discussion Inserting Element Reply To: Inserting Element

Derek Read

Reply to: Inserting Element

I would suggest that your need is very different then.
Taking a guess, but maybe your logic could be something like this:

1. Create a range after selecting the entire contents of the current element.
2. Duplicate that range. So you now have rng1 and rng2.
3. Collapse rng1 to the start and rng2 to the end.
4. In a loop…
    – try to insert your element at rng1
    – if that fails then move rng1 to the next element
    – exit the loop if an insertion occurs or if rng1 is equal to or greater than rng2

You could also probably try creating a node walker to do this but that code would probably be harder to understand and write. It might end up with less predictable results for the user, or they might not care. For inspiration see the Programmers Guide topic “Node example: A simple tree-walker”. If it were me I think I'd stick with something like what I've outlined above.

Reply

Products
Downloads
Support