[Mozile] OT: Range objects
Jeremy Smith
jeremyrsmith at gmail.com
Wed Sep 20 15:09:28 EDT 2006
I apologize for the off-topic message - I'm sure that people on this mailing
list are rather expert in Mozilla DOM-related stuff, so I thought this would
be a good place to ask. Let me know if I'm out of line.
A long time ago, I was working on a syntax-highlighting editor in DHTML. It
worked reasonably well, in firefox only, until version 1.5 which broke it
terribly. Even when it worked, it suffered from myriad problems since it
basically had to implement all keyboard and mouse functionality in
javascript (the semi-repaired original, which is essentially useless, is
here: http://www.duckwizard.com/syntax ).
Yesterday I had an idea - either a brilliant one or an astoundingly stupid
one, depending on your point of view - and started re-implementing this idea
using my new concept. The result so far is here:
http://www.duckwizard.com/syntaxed (it works in firefox, and somewhat in IE;
opera should work but their tabs widths are inconsistent). What it does is
present a textarea which hovers over the highlighted code, so that all the
code in the textarea is aligned with the highlighted code underneath. Then
the textarea is made mostly transparent so that the highlighting shines
through. This way, I get system functionality (keybd, mouse, selections,
copy/paste, undo/redo, etc) essentially for free.
On to my question: I am trying to figure out how I can avoid re-highlighting
the entire document whenever a change is made. It would help tremendously
to be able to determine what element, in the colored document structure, the
cursor (in the textarea) is inside. The most obvious way to do this would
be to make a Range object with the same offset as the cursor's offset in the
textarea, and apply it to the colored document. However, the "offset"
concept seems to change from characters to nodes when inside a non-text
node.
I could walk the entire tree of the colored document and count characters
until I overshoot the cursor position, but this seems as though it would be
dreadfully slow - only marginally faster than going ahead and
re-highlighting the entire document up to that point.
I'm afraid I've done a very poor job of explaining my question, but it's a
tough one to explain. Hopefully someone understands what I'm getting at :-)
Any other suggestions are, of course, welcome (keep in mind I only started
this thing yesterday!)
Thanks,
Jeremy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mozdev.org/pipermail/mozile/attachments/20060920/80ebb34c/attachment.htm
More information about the Mozile
mailing list