We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 20394
    • 134 Posts
    Vous avez sans doute constaté que lors de l’édition d’un chunk (par exemple),
    on ne peut utiliser la touche tab pour faire de belles indentations car cette touche est récupérée par le navigateur.

    Voici une solution, honteusement repompée du site de Greg Taff.
    La mise en place du textarea dans mutate_htmlsnippet devient :
    <textarea id="htmlta" name="post" style="width:100%; height: 370px;" onChange='documentDirty=true;'><?php echo htmlspecialchars($content['snippet']); ?></textarea>
    	</div>
    	<!-- HTML text editor end -->
    <input type="submit" name="save" style="display:none">
    </div>
    <script>
    function insert(input, theText) {
    	  if(typeof input.selectionStart != 'undefined')
    	  {
    	    var start = input.selectionStart;
    	    var end = input.selectionEnd;
    	    input.value = input.value.substr(0, start) + theText + input.value.substr(end);
    	   	input.selectionStart = start + theText.length;
    	   	input.selectionEnd = start + theText.length;
    		input.focus();
    	  }
    	}
    function keyDownHandler(e){
    		
    		/*  enable the tab key for the text areas */
    		
    		if(e.keyCode == 9){
    			var cacheScrollTop = e.target.scrollTop;
    			setTimeout("insert($('"+e.target.id+"'), unescape('%09'));", 0);
    			setTimeout("$('"+e.target.id+"').scrollTop = " + cacheScrollTop, 10);
    			return false;
    			}
    	}
    $("htmlta").onkeydown=keyDownHandler;
    
    </script>

    Notez que l’on donne un id au textarea et que ce code nécessite prototype.js.