contentEditable
html要素に基づく構文ハイライトを使用してjavascriptエディターを作成しています。エディターを管理し、次のように機能するクラスを作成しました。
function Editor() {
this.setContent = function(content) {
var pos = //Computes cursor position in current dom scope (number of characters from begining)
editor.innerHTML = content;
/* Here I set the cursor back, again, it is complicated and slow process*/
}
this.highlight = function() {
this.setContent(someHighlighter.highlight(this.getTextContent())); //Slow - highlights whole innerText of editor DOM and sets it as innerHTML
}
}
上記のコードは単なる概念です。しかし、それでも、それは効果的ではないことがわかり、私がより良い代替品を探していることを理解できるかもしれません。
反対に、私は残りの人生をこのエディターに費やしたくありません。
- 純粋なテキストの代わりにDOMで機能するjavascript構文ハイライトはありますか?
- カーソル位置を失うことなく要素の内容を変更するためのより良い方法はありますか?