[Mozile] OT: Range objects
Jeremy Smith
jeremyrsmith at gmail.com
Mon Sep 25 15:36:42 EDT 2006
Thanks to both of you for your comments! James, your code looks to be
particularly helpful. I hope I'll have some time to work on this soon; I
think I have some ideas as to how to improve the performance of the whole
affair.
Josef, the highlighter uses a very agnostic parser (which is pretty simple,
but seems to work OK). It just creates CSS <span> elements with the current
state as the className. To see what I mean, go to the demo page and View
Rendered Source (you must have that extension for this to work).
Then, you simply define your colors in CSS based on the state hierarchy. So
I don't think adapting this to any other language would be significantly
difficult. I should really rewrite the parser to be a real BNF Grammar
parser; we'll see how that goes (would essentially let you use highlight
files from many other text editors with minimal editing)
Jeremy
On 9/22/06, Josef Hahn <j-hahn at gmx.de> wrote:
>
> 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
>
> _______________________________________________
> Mozile mailing list
> Mozile at mozdev.org
> http://mozdev.org/mailman/listinfo/mozile
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mozdev.org/pipermail/mozile/attachments/20060925/5e1263ba/attachment.htm
More information about the Mozile
mailing list