Hey Will, I was doing a lot of work with contentEditable about a year and a 
half ago and wrote a little library for managing selections and determining if 
they are roughly equivalent to DOM nodes, etc. Some of it might be helpful to 
you:

http://code.google.com/p/simpleselection/

I also wrote a higher level library to replace execCommand (mostly because it 
operated so differently across browsers), but never got it to a spot where I 
felt it was worth open-sourcing. I'll try and dig it up; it might be a helpful 
starting point for you since it did just about exactly what you are describing 
:)

-Rob


On Mar 19, 2011, at 05:12 PM, Will Rock <[email protected]> wrote:

Hey all,

I'm playing around with contentEditable and I'm current working with
styling (bold, italic, etc..) of the current selection
(window.getSelection()). Now, I know I can do this via
document.execCommand (in certain browsers), but I'd like to implement
my own method. I can easily apply a style node (b, i, u, etc..) to
the selected text, but I also know that I need to be aware that the
style may already be applied to parts of the (or the entire)
selection. For instance, selecting part of a bold sentence, then
applying bold to that part will result in that part being plain, and
the original bold element will be broken up into 2 bold elements with
textnodes, and just a textnode in between them.

So, I'm wondering if there exists a pattern for tree traversal to
check for this type of thing. For those of you not familar with the
Selection object, you get a startContainer and endContainer for the
start and end node of the current selection, respectively. You also
get a commonAncestor. All of the elements are there, I just don't want
to re-invent the wheel.

Thanks!

--
To view archived discussions from the original JSMentors Mailman list: 
[email protected]/'>http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
[email protected]/'>http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

--
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to