From 386ae6e1dc07a0c9472a60658763147b5a35b3f4 Mon Sep 17 00:00:00 2001 From: Erik Moeller Date: Mon, 29 Aug 2005 19:43:36 +0000 Subject: [PATCH] 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 ;-) --- skins/common/wikibits.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/skins/common/wikibits.js b/skins/common/wikibits.js index b19bfc3727..7ee99f7831 100644 --- a/skins/common/wikibits.js +++ b/skins/common/wikibits.js @@ -318,8 +318,10 @@ function insertTags(tagOpen, tagClose, sampleText) { // Mozilla } else if(txtarea.selectionStart || txtarea.selectionStart == '0') { + var replaced = false; var startPos = txtarea.selectionStart; var endPos = txtarea.selectionEnd; + if(endPos-startPos) replaced=true; var scrollTop=txtarea.scrollTop; var myText = (txtarea.value).substring(startPos, endPos); if(!myText) { myText=sampleText;} @@ -331,10 +333,15 @@ function insertTags(tagOpen, tagClose, sampleText) { txtarea.value = txtarea.value.substring(0, startPos) + subst + txtarea.value.substring(endPos, txtarea.value.length); txtarea.focus(); - - var cPos=startPos+(tagOpen.length+myText.length+tagClose.length); - txtarea.selectionStart=cPos; - txtarea.selectionEnd=cPos; + //set new selection + if(replaced){ + var cPos=startPos+(tagOpen.length+myText.length+tagClose.length); + txtarea.selectionStart=cPos; + txtarea.selectionEnd=cPos; + }else{ + txtarea.selectionStart=startPos+tagOpen.length; + txtarea.selectionEnd=startPos+tagOpen.length+myText.length; + } txtarea.scrollTop=scrollTop; // All other browsers get no toolbar. -- 2.20.1