r10831 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r10830‎ | r10831 | r10832 >
Date:19:43, 29 August 2005
Author:eloquence
Status:old
Tags:
Comment:
Edit toolbar - steal a little trick from DokuWiki: When you click a button
with no selection, the example text within the formatting, e.g. the "Link
title" in [[Link title]], is highlighted so that you can immediately type
over it.

Gecko only for now due to lack of testability under IE, if anyone wants to
hack it for IE, the code is at
http://wiki.splitbrain.org/lib/scripts/script.js

Note that they copied it from us first, so it's fair game ;-)
Modified paths:
  • /trunk/phase3/skins/common/wikibits.js (modified) (history)

Diff [purge]

Index: trunk/phase3/skins/common/wikibits.js
@@ -318,8 +318,10 @@
319319
320320 // Mozilla
321321 } else if(txtarea.selectionStart || txtarea.selectionStart == '0') {
 322+ var replaced = false;
322323 var startPos = txtarea.selectionStart;
323324 var endPos = txtarea.selectionEnd;
 325+ if(endPos-startPos) replaced=true;
324326 var scrollTop=txtarea.scrollTop;
325327 var myText = (txtarea.value).substring(startPos, endPos);
326328 if(!myText) { myText=sampleText;}
@@ -331,10 +333,15 @@
332334 txtarea.value = txtarea.value.substring(0, startPos) + subst +
333335 txtarea.value.substring(endPos, txtarea.value.length);
334336 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+ }
339346 txtarea.scrollTop=scrollTop;
340347
341348 // All other browsers get no toolbar.

Status & tagging log