C
Ciaran
Hi I have a working WYSIWYG (copied mostly from
http://themaninblue.com/writing/perspective/2005/01/27/). I'm trying
to auto save the content but the save resets the caret position to the
beginning of the input which disrupts the flow of the user typing.
It's a complicated on I know but can anyone suggest a way to get the
cursor position before the save and set it back to that same position
after the save? I'd even be happy to just set the caret to the very
end of the input rather than the very beginning.
I patched together this function which sets the caret position in a
textarea. It might be a good starting point:
function setCursor(el,st,end) {
if(st=='end'){ //jump to end:
end=el.value.length
st=end;
}else if (st=='start'){ //jump to start:
el.focus();
return(1);
}
if(el.setSelectionRange) {//jump to position:
el.focus();
el.setSelectionRange(st,end);
}else {
if(el.createTextRange) {
range=el.createTextRange();
range.collapse(true);
range.moveend('character',end);
range.moveStart('character',st);
range.select();
}
}
}
Thanks for any help!
Ciarán
http://themaninblue.com/writing/perspective/2005/01/27/). I'm trying
to auto save the content but the save resets the caret position to the
beginning of the input which disrupts the flow of the user typing.
It's a complicated on I know but can anyone suggest a way to get the
cursor position before the save and set it back to that same position
after the save? I'd even be happy to just set the caret to the very
end of the input rather than the very beginning.
I patched together this function which sets the caret position in a
textarea. It might be a good starting point:
function setCursor(el,st,end) {
if(st=='end'){ //jump to end:
end=el.value.length
st=end;
}else if (st=='start'){ //jump to start:
el.focus();
return(1);
}
if(el.setSelectionRange) {//jump to position:
el.focus();
el.setSelectionRange(st,end);
}else {
if(el.createTextRange) {
range=el.createTextRange();
range.collapse(true);
range.moveend('character',end);
range.moveStart('character',st);
range.select();
}
}
}
Thanks for any help!
Ciarán