Revised selection code

SVN revision: 2160
This commit is contained in:
Stefan Ritt 2009-01-16 13:42:07 +00:00
parent 6a4e2fd222
commit 761b5a0e0e

View File

@ -7,14 +7,13 @@ function getSelection(text)
rng = sel.createRange(); rng = sel.createRange();
rng.colapse; rng.colapse;
return rng.text; return rng.text;
} else if (browser == 'Mozilla' || browser == 'Safari') } else {
if (text.selectionEnd > 0 && text.selectionEnd != text.selectionStart && if (text.selectionEnd > 0 && text.selectionEnd != text.selectionStart &&
text.value.charAt(text.selectionEnd-1) == ' ') text.value.charAt(text.selectionEnd-1) == ' ')
return text.value.substring(text.selectionStart, text.selectionEnd-1); return text.value.substring(text.selectionStart, text.selectionEnd-1);
else else
return text.value.substring(text.selectionStart, text.selectionEnd); return text.value.substring(text.selectionStart, text.selectionEnd);
else }
return "";
} }
function replaceSelection(doc, text, newSelection, cursorPos) function replaceSelection(doc, text, newSelection, cursorPos)
@ -31,7 +30,7 @@ function replaceSelection(doc, text, newSelection, cursorPos)
rng.moveEnd('character', -(newSelection.length-cursorPos)); rng.moveEnd('character', -(newSelection.length-cursorPos));
rng.select(); rng.select();
} }
} else if (browser == 'Mozilla' || browser == 'Safari') { } else {
start = text.selectionStart; start = text.selectionStart;
stop = text.selectionEnd; stop = text.selectionEnd;
if (text.selectionEnd > 0 && text.selectionStart != text.selectionEnd && if (text.selectionEnd > 0 && text.selectionStart != text.selectionEnd &&
@ -48,8 +47,7 @@ function replaceSelection(doc, text, newSelection, cursorPos)
text.selectionStart = start + cursorPos; text.selectionStart = start + cursorPos;
text.selectionEnd = text.selectionStart; text.selectionEnd = text.selectionStart;
} }
} else }
text.value += newSelection;
} }
function elcode(text, tag, value) function elcode(text, tag, value)