[Mozile] OT: Range objects

Josef Hahn j-hahn at gmx.de
Fri Sep 22 10:24:05 EDT 2006


Hi Jeremy,

just an answer to one of your questions: IMO your idea is brilliant. 
Your code highlighting textarea could be used perfectly e.g. as a 
template editor in content management systems where cms specific makros 
have to be inserted between normal (x)html-tags. An other way to use it, 
is in a forum where BBcode can be inserted in textfields .

For this usage my suggestions to improve the editor is that one should
have a possibility to define own tags/makros that are highlighted in
also definable colors.

Keep on coding :-), Josef


Jeremy Smith schrieb:
> 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
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Mozile mailing list
> Mozile at mozdev.org
> http://mozdev.org/mailman/listinfo/mozile



More information about the Mozile mailing list