Index: trunk/phase3/skins/common/wikibits.js |
— | — | @@ -318,8 +318,10 @@ |
319 | 319 | |
320 | 320 | // Mozilla |
321 | 321 | } else if(txtarea.selectionStart || txtarea.selectionStart == '0') { |
| 322 | + var replaced = false; |
322 | 323 | var startPos = txtarea.selectionStart; |
323 | 324 | var endPos = txtarea.selectionEnd; |
| 325 | + if(endPos-startPos) replaced=true; |
324 | 326 | var scrollTop=txtarea.scrollTop; |
325 | 327 | var myText = (txtarea.value).substring(startPos, endPos); |
326 | 328 | if(!myText) { myText=sampleText;} |
— | — | @@ -331,10 +333,15 @@ |
332 | 334 | txtarea.value = txtarea.value.substring(0, startPos) + subst + |
333 | 335 | txtarea.value.substring(endPos, txtarea.value.length); |
334 | 336 | txtarea.focus(); |
335 | | - |
336 | | - var cPos=startPos+(tagOpen.length+myText.length+tagClose.length); |
337 | | - txtarea.selectionStart=cPos; |
338 | | - txtarea.selectionEnd=cPos; |
| 337 | + //set new selection |
| 338 | + if(replaced){ |
| 339 | + var cPos=startPos+(tagOpen.length+myText.length+tagClose.length); |
| 340 | + txtarea.selectionStart=cPos; |
| 341 | + txtarea.selectionEnd=cPos; |
| 342 | + }else{ |
| 343 | + txtarea.selectionStart=startPos+tagOpen.length; |
| 344 | + txtarea.selectionEnd=startPos+tagOpen.length+myText.length; |
| 345 | + } |
339 | 346 | txtarea.scrollTop=scrollTop; |
340 | 347 | |
341 | 348 | // All other browsers get no toolbar. |