textarea のselectionStart属性とselectionEnd属性をcontenteditable div 要素で機能させるのに苦労しています。私はグーグルとSOで多くの関連記事をチェックしましたが、役に立ちませんでした。テキストエリアで完全に機能する次のようなものがあります。しかし、これを contenteditable div で動作させたいと思っています。
function replaceVal(node, val, step){
//...
var cursorLoc = node.selectionStart;
node.value = node.value.substring(0, node.selectionStart - step) + value +
node.value.substring(node.selectionEnd, node.value.length);
node.scrollTop = scrollTop;
node.selectionStart = cursorLoc + value.length - step;
node.selectionEnd = cursorLoc + value.length - step;
//...
}
textarea の代わりに contenteditable div 要素で動作するように、これをどのように変更できますか?