Hi! Thank you :-)
Unfortunately I can't really help you here� There probably should be
some way to get cursor position from a contenteditable block and then
set it back but I don't have any knowledge on this.
In fact I even doubt that using highlight.js for live highlighting is a
good idea because it would effectively replace the whole DOM sub-tree
inside the area on every change so it may be slow and suffer from visual
artifacts like flickering.
On 04/13/2011 11:28 AM, André Vasko wrote:Hi! Thank you :-)
Hi there,
First, I would like to thanks for this very usefull library.
Second, I need to ask how can I type an text inside a code element and
the text be automatically highlighten on the fly? I already started
some code:
<pre width="500px">
<code width="500px" id="sqlInput" contenteditable="true">SELECT *
FROM table;</code>
</pre>
But the problem is when I alter the origin text, the new text is not
highlighten. So I have to call this Javascript function and I lose the
object's focus:
$('pre').each(function(i, e) {hljs.highlightBlock(e)});
This is a real problem because I cannot continue to type my SQL
sentence. Does anyone can help me?
Maybe there is a way of calling some other function that does not
steal the focus, or to save the focus and recover it later...
Unfortunately I can't really help you here… There probably should be some way to get cursor position from a contenteditable block and then set it back but I don't have any knowledge on this.
jQuery(document).on('keyup', 'pre code.editor', function(event) {
jQuery('pre code.result').html(this.innerText);
hljs.highlightBlock(jQuery('pre code.result')[0],' ', false);
});