This work.
var selection;
if(window.getSelection){
selection = window.getSelection();
}
var input = document.getElementById("textarea");
const input_width = input.width();
const hidden = $("hidden");
const hidden_width = hidden.width();
var select;
var text = input.val();
for(n = 0; text.length; n++){
input.prop('selectionEnd', n);
select = selection.toString();
hidden.html(select);
if( hidde.width > input_width ){
insertAtCaret("\r\n");
}
}
insertAtCaret = function(input, text){
input.setRangeText(
text,
input.selectionEnd,
input.selectionEnd,
'end')
}
But this is slow.
Are there any better improvements?
Thanks!