<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Handling Tabs in Textareas</title>
	<atom:link href="http://ajaxian.com/archives/handling-tabs-in-textareas/feed" rel="self" type="application/rss+xml" />
	<link>http://ajaxian.com/archives/handling-tabs-in-textareas</link>
	<description>Cleaning up the web with Ajax</description>
	<lastBuildDate>Thu, 09 Feb 2012 06:55:33 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2</generator>
	<item>
		<title>By: Jaromir</title>
		<link>http://ajaxian.com/archives/handling-tabs-in-textareas/comment-page-1#comment-274990</link>
		<dc:creator>Jaromir</dc:creator>
		<pubDate>Tue, 11 Aug 2009 02:55:43 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/handling-tabs-in-textareas#comment-274990</guid>
		<description>And few changes by me :D

&lt;code&gt;
enableTabs : function ( slectors ) {
	jQuery( selectors ).focus(function () {
		jQuery(this).keypress(function (e) {
			var tab = &quot;\t&quot;;
			var target = e.target;
			var selectionStart = target.selectionStart;
			var selectionEnd = target.selectionEnd;

		    if (e.keyCode == 9) {
		        e.preventDefault();

		        // Multiline selection
		        if (selectionStart != selectionEnd &amp;&amp; target.value.slice(selectionStart,selectionEnd).indexOf(&quot;\n&quot;) != -1) {
		            var pre = target.value.slice(0,selectionStart);
		            var sel = target.value.slice(selectionStart,selectionEnd);
		            var post = target.value.slice(selectionEnd,target.value.length);
		            if(sel.match(/\n(\t){1}/g))
		            	var lines = sel.match(/\n(\t){1}/g).length + 1;
		            else
		            	var lines = sel.split(/\n/).length;

		            if(!e.shiftKey) {
		            	sel = sel.replace(/\n/g,&quot;\n&quot;+tab);
			            target.value = pre.concat(tab).concat(sel).concat(post);
			            target.selectionStart = selectionStart;
			            target.selectionEnd = selectionEnd + lines * tab.length;
		            } else {
		            	if(sel.match(/^(\t){1}/m) &#124;&#124; sel.match(/\n(\t){1}/g)) {
		            		sel = sel.replace(/^(\t){1}/m,&quot;&quot;);
		            		sel = sel.replace(/\n(\t){1}/g,&quot;\n&quot;);
		            		
			            	target.value = pre.concat(sel).concat(post);
				            target.selectionStart = selectionStart;
				            target.selectionEnd = selectionEnd - lines * tab.length;
		            	}
		            }
		        }
		        // No selection or sigle line selection
		        else {
		        	if(!e.shiftKey) {
		        		target.value = target.value.slice(0,selectionStart).concat(tab).concat(target.value.slice(selectionStart,target.value.length));
			            if (selectionStart == selectionEnd) {
			                target.selectionStart = target.selectionEnd = selectionStart + tab.length;
			            }
			            else {
			                target.selectionStart = selectionStart;
			                target.selectionEnd = selectionEnd + tab.length;
			            }
		        	} else {
			            if (selectionStart != selectionEnd) {
				            var pre = target.value.slice(0,selectionStart);
				            var post = target.value.slice(selectionEnd,target.value.length);
			            	var sel = target.value.slice(selectionStart,selectionEnd);
			            	
			            	if(sel.match(/^(\t){1}/)) {
			            		sel = sel.replace(/^(\t){1}/,&quot;&quot;);
				            	target.value = pre.concat(sel).concat(post);
				                target.selectionStart = selectionStart;
				                target.selectionEnd = selectionEnd - tab.length;
			            	}
			            }
		        	}
		        }
		    }
		});
	});
}
&lt;/code&gt;

Useage :

&lt;code&gt;
enableTabs(&quot;textarea&quot;);
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>And few changes by me :D</p>
<p><code><br />
enableTabs : function ( slectors ) {<br />
	jQuery( selectors ).focus(function () {<br />
		jQuery(this).keypress(function (e) {<br />
			var tab = "\t";<br />
			var target = e.target;<br />
			var selectionStart = target.selectionStart;<br />
			var selectionEnd = target.selectionEnd;</p>
<p>		    if (e.keyCode == 9) {<br />
		        e.preventDefault();</p>
<p>		        // Multiline selection<br />
		        if (selectionStart != selectionEnd &amp;&amp; target.value.slice(selectionStart,selectionEnd).indexOf("\n") != -1) {<br />
		            var pre = target.value.slice(0,selectionStart);<br />
		            var sel = target.value.slice(selectionStart,selectionEnd);<br />
		            var post = target.value.slice(selectionEnd,target.value.length);<br />
		            if(sel.match(/\n(\t){1}/g))<br />
		            	var lines = sel.match(/\n(\t){1}/g).length + 1;<br />
		            else<br />
		            	var lines = sel.split(/\n/).length;</p>
<p>		            if(!e.shiftKey) {<br />
		            	sel = sel.replace(/\n/g,"\n"+tab);<br />
			            target.value = pre.concat(tab).concat(sel).concat(post);<br />
			            target.selectionStart = selectionStart;<br />
			            target.selectionEnd = selectionEnd + lines * tab.length;<br />
		            } else {<br />
		            	if(sel.match(/^(\t){1}/m) || sel.match(/\n(\t){1}/g)) {<br />
		            		sel = sel.replace(/^(\t){1}/m,"");<br />
		            		sel = sel.replace(/\n(\t){1}/g,"\n");</p>
<p>			            	target.value = pre.concat(sel).concat(post);<br />
				            target.selectionStart = selectionStart;<br />
				            target.selectionEnd = selectionEnd - lines * tab.length;<br />
		            	}<br />
		            }<br />
		        }<br />
		        // No selection or sigle line selection<br />
		        else {<br />
		        	if(!e.shiftKey) {<br />
		        		target.value = target.value.slice(0,selectionStart).concat(tab).concat(target.value.slice(selectionStart,target.value.length));<br />
			            if (selectionStart == selectionEnd) {<br />
			                target.selectionStart = target.selectionEnd = selectionStart + tab.length;<br />
			            }<br />
			            else {<br />
			                target.selectionStart = selectionStart;<br />
			                target.selectionEnd = selectionEnd + tab.length;<br />
			            }<br />
		        	} else {<br />
			            if (selectionStart != selectionEnd) {<br />
				            var pre = target.value.slice(0,selectionStart);<br />
				            var post = target.value.slice(selectionEnd,target.value.length);<br />
			            	var sel = target.value.slice(selectionStart,selectionEnd);</p>
<p>			            	if(sel.match(/^(\t){1}/)) {<br />
			            		sel = sel.replace(/^(\t){1}/,"");<br />
				            	target.value = pre.concat(sel).concat(post);<br />
				                target.selectionStart = selectionStart;<br />
				                target.selectionEnd = selectionEnd - tab.length;<br />
			            	}<br />
			            }<br />
		        	}<br />
		        }<br />
		    }<br />
		});<br />
	});<br />
}<br />
</code></p>
<p>Useage :</p>
<p><code><br />
enableTabs("textarea");<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: devel</title>
		<link>http://ajaxian.com/archives/handling-tabs-in-textareas/comment-page-1#comment-274943</link>
		<dc:creator>devel</dc:creator>
		<pubDate>Fri, 07 Aug 2009 15:24:49 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/handling-tabs-in-textareas#comment-274943</guid>
		<description>This is a more cleaned up version of version of Greg&#039;s from June 4th, 2007... Uses the onkeydown event to handle any textarea.




document.onkeydown = tabTextarea;

/**
 * ORIGINAL SOURCE:
 * 		http://www.answermysearches.com/here-is-how-to-make-the-tab-work-in-a-textarea-javascript/265/
 * MODIFIED:
 * 		20090807 - Beall
 * @param evt Native onkeydown event
 */
function tabTextarea(evt) {
	// Get Event
	var keyEvent = (evt &#124;&#124; event);
	// Get Key Code
	var keyCode = keyEvent.keyCode;
	// Get Event Target
	var keyTarget = keyEvent.target ? keyEvent.target
			: keyEvent.srcElement ? keyEvent.srcElement : null;
	
       //TAB
	if(keyCode==9 &amp;&amp; keyTarget.tagName.toLowerCase() == &quot;textarea&quot;){
    //Ctrl+Q - Used to not effect normal tab functionality
    //if(keyEvent.ctrlKey &amp;&amp; keyCode==81 &amp;&amp; keyTarget.tagName.toLowerCase() == &quot;textarea&quot;){	
		//So the scroll won&#039;t move after a tabbing
    	var oldscroll = keyTarget.scrollTop;
        
    	//Firefox
      	if (keyTarget.setSelectionRange) {
      	    //Insert tab character
      	    keyTarget.value = keyTarget.value.substring(0, keyTarget.selectionStart) 
     	    		+ &#039;\t&#039; + keyTarget.value.substring(keyTarget.selectionEnd,keyTarget.value.length);
      	}
      	//Handle IE
      	else {
      		//This much effort was almost unnecessary, but sometimes while
      		//	tabbing, it would reset the cursor position to before the created tab
      		var textRange= document.selection.createRange();
      		textRange.text=&#039;\t&#039;;
      		var selectionLength = textRange.text.length;
      		textRange.moveStart (&#039;character&#039;,-keyTarget.value.length);
      		var selectionStartPos = textRange.text.length-selectionLength;
      		var selectionEndPos = selectionStartPos+selectionLength;

		   if(selectionLength&gt;1){
		        selectionLength=1;
		        selectionEndPos=selectionStartPos+1;
		    }

	   		textRange = keyTarget.createTextRange();
	        textRange .collapse(true);
	        textRange .moveEnd(&#039;character&#039;, selectionEndPos);
	        textRange .moveStart(&#039;character&#039;, selectionEndPos);
	        textRange .select();
      	}

      	//put back the scroll
      	keyTarget.scrollTop = oldscroll; 
      	
      	keyEvent.cancelBubble = true;
      	return false;
    }
}



</description>
		<content:encoded><![CDATA[<p>This is a more cleaned up version of version of Greg&#8217;s from June 4th, 2007&#8230; Uses the onkeydown event to handle any textarea.</p>
<p>document.onkeydown = tabTextarea;</p>
<p>/**<br />
 * ORIGINAL SOURCE:<br />
 * 		<a href="http://www.answermysearches.com/here-is-how-to-make-the-tab-work-in-a-textarea-javascript/265/" rel="nofollow">http://www.answermysearches.com/here-is-how-to-make-the-tab-work-in-a-textarea-javascript/265/</a><br />
 * MODIFIED:<br />
 * 		20090807 &#8211; Beall<br />
 * @param evt Native onkeydown event<br />
 */<br />
function tabTextarea(evt) {<br />
	// Get Event<br />
	var keyEvent = (evt || event);<br />
	// Get Key Code<br />
	var keyCode = keyEvent.keyCode;<br />
	// Get Event Target<br />
	var keyTarget = keyEvent.target ? keyEvent.target<br />
			: keyEvent.srcElement ? keyEvent.srcElement : null;</p>
<p>       //TAB<br />
	if(keyCode==9 &amp;&amp; keyTarget.tagName.toLowerCase() == &#8220;textarea&#8221;){<br />
    //Ctrl+Q &#8211; Used to not effect normal tab functionality<br />
    //if(keyEvent.ctrlKey &amp;&amp; keyCode==81 &amp;&amp; keyTarget.tagName.toLowerCase() == &#8220;textarea&#8221;){<br />
		//So the scroll won&#8217;t move after a tabbing<br />
    	var oldscroll = keyTarget.scrollTop;</p>
<p>    	//Firefox<br />
      	if (keyTarget.setSelectionRange) {<br />
      	    //Insert tab character<br />
      	    keyTarget.value = keyTarget.value.substring(0, keyTarget.selectionStart)<br />
     	    		+ &#8216;\t&#8217; + keyTarget.value.substring(keyTarget.selectionEnd,keyTarget.value.length);<br />
      	}<br />
      	//Handle IE<br />
      	else {<br />
      		//This much effort was almost unnecessary, but sometimes while<br />
      		//	tabbing, it would reset the cursor position to before the created tab<br />
      		var textRange= document.selection.createRange();<br />
      		textRange.text=&#8217;\t&#8217;;<br />
      		var selectionLength = textRange.text.length;<br />
      		textRange.moveStart (&#8216;character&#8217;,-keyTarget.value.length);<br />
      		var selectionStartPos = textRange.text.length-selectionLength;<br />
      		var selectionEndPos = selectionStartPos+selectionLength;</p>
<p>		   if(selectionLength&gt;1){<br />
		        selectionLength=1;<br />
		        selectionEndPos=selectionStartPos+1;<br />
		    }</p>
<p>	   		textRange = keyTarget.createTextRange();<br />
	        textRange .collapse(true);<br />
	        textRange .moveEnd(&#8216;character&#8217;, selectionEndPos);<br />
	        textRange .moveStart(&#8216;character&#8217;, selectionEndPos);<br />
	        textRange .select();<br />
      	}</p>
<p>      	//put back the scroll<br />
      	keyTarget.scrollTop = oldscroll; </p>
<p>      	keyEvent.cancelBubble = true;<br />
      	return false;<br />
    }<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Fordi</title>
		<link>http://ajaxian.com/archives/handling-tabs-in-textareas/comment-page-1#comment-266998</link>
		<dc:creator>Fordi</dc:creator>
		<pubDate>Thu, 28 Aug 2008 14:40:50 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/handling-tabs-in-textareas#comment-266998</guid>
		<description>Also, a lot of those &#039;-4&#039;s should be replaced with tab.length</description>
		<content:encoded><![CDATA[<p>Also, a lot of those &#8216;-4&#8242;s should be replaced with tab.length</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Fordi</title>
		<link>http://ajaxian.com/archives/handling-tabs-in-textareas/comment-page-1#comment-266997</link>
		<dc:creator>Fordi</dc:creator>
		<pubDate>Thu, 28 Aug 2008 14:27:14 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/handling-tabs-in-textareas#comment-266997</guid>
		<description>Hey, I noticed that firefox, at least, was resetting the scroll position of the textarea whenever you interfere with its value.  As such, it seems it&#039;s best to cache the textarea&#039;s scrollon line 9, and restore it on line 54.

I know that&#039;s what I&#039;m going.</description>
		<content:encoded><![CDATA[<p>Hey, I noticed that firefox, at least, was resetting the scroll position of the textarea whenever you interfere with its value.  As such, it seems it&#8217;s best to cache the textarea&#8217;s scrollon line 9, and restore it on line 54.</p>
<p>I know that&#8217;s what I&#8217;m going.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris Beauchamp</title>
		<link>http://ajaxian.com/archives/handling-tabs-in-textareas/comment-page-1#comment-253383</link>
		<dc:creator>Chris Beauchamp</dc:creator>
		<pubDate>Wed, 01 Aug 2007 03:12:07 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/handling-tabs-in-textareas#comment-253383</guid>
		<description>This is perfect! Just what I was looking for!</description>
		<content:encoded><![CDATA[<p>This is perfect! Just what I was looking for!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Danny Mendel</title>
		<link>http://ajaxian.com/archives/handling-tabs-in-textareas/comment-page-1#comment-250292</link>
		<dc:creator>Danny Mendel</dc:creator>
		<pubDate>Tue, 08 May 2007 20:29:54 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/handling-tabs-in-textareas#comment-250292</guid>
		<description>I find that it makes life much easier if you add the following line:
	var oldscroll = t.scrollTop;
at the beginning of the function; and add this line:
	t.scrollTop = oldscroll;
at the end. Otherwise the textarea jumps with every tab.</description>
		<content:encoded><![CDATA[<p>I find that it makes life much easier if you add the following line:<br />
	var oldscroll = t.scrollTop;<br />
at the beginning of the function; and add this line:<br />
	t.scrollTop = oldscroll;<br />
at the end. Otherwise the textarea jumps with every tab.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt White</title>
		<link>http://ajaxian.com/archives/handling-tabs-in-textareas/comment-page-1#comment-106647</link>
		<dc:creator>Matt White</dc:creator>
		<pubDate>Wed, 27 Sep 2006 01:25:46 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/handling-tabs-in-textareas#comment-106647</guid>
		<description>I found this code very useful.  Thanks!  I modified the code to be cross-browser (firefox, safari, ie) and to handle only tab and shift-tab (for indent/outdent).  I also made some modifications to make it work more like programs I&#039;m used to.  Anyway, don&#039;t know if anyone is reading these messages anymore, but here&#039;s my code if anyone finds it useful:

&lt;code&gt;
// place in the onkeypress event (onkeydown for ie!!) of a textarea
// t: textarea object, evt: event object
function enableTextareaTabInsertion(t, evt)
{
  var kc = evt.which ? evt.which : evt.keyCode, isSafari = navigator.userAgent.toLowerCase().indexOf(&quot;safari&quot;) != -1;

  if (kc == 9 &#124;&#124; (isSafari &amp;&amp; kc == 25))
  { 
    t.focus();
  
    // hack for ie
    if (!t.selectionStart)
    {
      var range = document.selection.createRange();
      var stored_range = range.duplicate();
      stored_range.moveToElementText(t);
      stored_range.setEndPoint(&#039;EndToEnd&#039;, range);
      t.selectionStart = stored_range.text.length - range.text.length;
      t.selectionEnd = t.selectionStart + range.text.length;
      t.setSelectionRange = function(start, end) 
      { 
      	var range = this.createTextRange();
      	range.collapse(true);
      	range.moveStart(&quot;character&quot;, start);
      	range.moveEnd(&quot;character&quot;, end - start);
      	range.select();
      }
    }

    var tablen = 4, tab = &#039;    &#039;, tab_regexp = /\n\s\s\s\s/g;
    var ss = t.selectionStart, se = t.selectionEnd, ta_val = t.value, sel = ta_val.slice(ss, se); shft = (isSafari &amp;&amp; kc == 25) &#124;&#124; evt.shiftKey;
    var was_tab = ta_val.slice(ss - tablen, ss) == tab, starts_with_tab = ta_val.slice(ss, ss + tablen) == tab, offset = shft ? 0-tablen : tablen, full_indented_line = false, num_lines = sel.split(&quot;\n&quot;).length;
    
    if (ss != se &amp;&amp; sel[sel.length-1] == &#039;\n&#039;) { se--; sel = ta_val.slice(ss, se); num_lines--; }
    if (num_lines == 1 &amp;&amp; starts_with_tab) full_indented_line = true;

    if (!shft &#124;&#124; was_tab &#124;&#124; num_lines &gt; 1 &#124;&#124; full_indented_line)
    {
      // multi-line selection
      if (num_lines &gt; 1) 
      {
        // tab each line
        if (shft &amp;&amp; (was_tab &#124;&#124; starts_with_tab) &amp;&amp; sel.split(tab_regexp).length == num_lines)
        {
          if (!was_tab) sel = sel.substring(tablen);
          t.value = ta_val.slice(0, ss - (was_tab ? tablen : 0)).concat(sel.replace(tab_regexp, &quot;\n&quot;)).concat(ta_val.slice(se, ta_val.length));
          ss += was_tab ? offset : 0; se += offset * num_lines;
        }
        else if (!shft)
        {
          t.value = ta_val.slice(0, ss).concat(tab).concat(sel.replace(/\n/g, &quot;\n&quot; + tab)).concat(ta_val.slice(se, ta_val.length));
          se += offset * num_lines;
        }
      }

      // single-line selection
      else 
      {
        if (shft)
          t.value = ta_val.slice(0, ss - (full_indented_line ? 0 : tablen)).concat(ta_val.slice(ss + (full_indented_line ? tablen : 0), ta_val.length));
        else
          t.value = ta_val.slice(0, ss).concat(tab).concat(ta_val.slice(ss, ta_val.length));
        
        if (ss == se)
          ss = se = ss + offset;
        else 
          se += offset;
      }
    }

    setTimeout(&quot;var t=$(&#039;&quot; + t.id + &quot;&#039;); t.focus(); t.setSelectionRange(&quot; + ss + &quot;, &quot; + se + &quot;);&quot;, 0);
    return false; 
  }
}
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>I found this code very useful.  Thanks!  I modified the code to be cross-browser (firefox, safari, ie) and to handle only tab and shift-tab (for indent/outdent).  I also made some modifications to make it work more like programs I&#8217;m used to.  Anyway, don&#8217;t know if anyone is reading these messages anymore, but here&#8217;s my code if anyone finds it useful:</p>
<p><code><br />
// place in the onkeypress event (onkeydown for ie!!) of a textarea<br />
// t: textarea object, evt: event object<br />
function enableTextareaTabInsertion(t, evt)<br />
{<br />
  var kc = evt.which ? evt.which : evt.keyCode, isSafari = navigator.userAgent.toLowerCase().indexOf("safari") != -1;</p>
<p>  if (kc == 9 || (isSafari &amp;&amp; kc == 25))<br />
  {<br />
    t.focus();</p>
<p>    // hack for ie<br />
    if (!t.selectionStart)<br />
    {<br />
      var range = document.selection.createRange();<br />
      var stored_range = range.duplicate();<br />
      stored_range.moveToElementText(t);<br />
      stored_range.setEndPoint('EndToEnd', range);<br />
      t.selectionStart = stored_range.text.length - range.text.length;<br />
      t.selectionEnd = t.selectionStart + range.text.length;<br />
      t.setSelectionRange = function(start, end)<br />
      {<br />
      	var range = this.createTextRange();<br />
      	range.collapse(true);<br />
      	range.moveStart("character", start);<br />
      	range.moveEnd("character", end - start);<br />
      	range.select();<br />
      }<br />
    }</p>
<p>    var tablen = 4, tab = '    ', tab_regexp = /\n\s\s\s\s/g;<br />
    var ss = t.selectionStart, se = t.selectionEnd, ta_val = t.value, sel = ta_val.slice(ss, se); shft = (isSafari &amp;&amp; kc == 25) || evt.shiftKey;<br />
    var was_tab = ta_val.slice(ss - tablen, ss) == tab, starts_with_tab = ta_val.slice(ss, ss + tablen) == tab, offset = shft ? 0-tablen : tablen, full_indented_line = false, num_lines = sel.split("\n").length;</p>
<p>    if (ss != se &amp;&amp; sel[sel.length-1] == '\n') { se--; sel = ta_val.slice(ss, se); num_lines--; }<br />
    if (num_lines == 1 &amp;&amp; starts_with_tab) full_indented_line = true;</p>
<p>    if (!shft || was_tab || num_lines &gt; 1 || full_indented_line)<br />
    {<br />
      // multi-line selection<br />
      if (num_lines &gt; 1)<br />
      {<br />
        // tab each line<br />
        if (shft &amp;&amp; (was_tab || starts_with_tab) &amp;&amp; sel.split(tab_regexp).length == num_lines)<br />
        {<br />
          if (!was_tab) sel = sel.substring(tablen);<br />
          t.value = ta_val.slice(0, ss - (was_tab ? tablen : 0)).concat(sel.replace(tab_regexp, "\n")).concat(ta_val.slice(se, ta_val.length));<br />
          ss += was_tab ? offset : 0; se += offset * num_lines;<br />
        }<br />
        else if (!shft)<br />
        {<br />
          t.value = ta_val.slice(0, ss).concat(tab).concat(sel.replace(/\n/g, "\n" + tab)).concat(ta_val.slice(se, ta_val.length));<br />
          se += offset * num_lines;<br />
        }<br />
      }</p>
<p>      // single-line selection<br />
      else<br />
      {<br />
        if (shft)<br />
          t.value = ta_val.slice(0, ss - (full_indented_line ? 0 : tablen)).concat(ta_val.slice(ss + (full_indented_line ? tablen : 0), ta_val.length));<br />
        else<br />
          t.value = ta_val.slice(0, ss).concat(tab).concat(ta_val.slice(ss, ta_val.length));</p>
<p>        if (ss == se)<br />
          ss = se = ss + offset;<br />
        else<br />
          se += offset;<br />
      }<br />
    }</p>
<p>    setTimeout("var t=$('" + t.id + "'); t.focus(); t.setSelectionRange(" + ss + ", " + se + ");", 0);<br />
    return false;<br />
  }<br />
}<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: 50 Cent</title>
		<link>http://ajaxian.com/archives/handling-tabs-in-textareas/comment-page-1#comment-38444</link>
		<dc:creator>50 Cent</dc:creator>
		<pubDate>Thu, 29 Jun 2006 13:43:18 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/handling-tabs-in-textareas#comment-38444</guid>
		<description>did you guy try this on IE?  if you press any key a javascript error occurs</description>
		<content:encoded><![CDATA[<p>did you guy try this on IE?  if you press any key a javascript error occurs</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sunny</title>
		<link>http://ajaxian.com/archives/handling-tabs-in-textareas/comment-page-1#comment-9326</link>
		<dc:creator>Sunny</dc:creator>
		<pubDate>Thu, 11 May 2006 08:40:48 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/handling-tabs-in-textareas#comment-9326</guid>
		<description>Perhaps make a \t when pressing a lonnnnnng tab ?</description>
		<content:encoded><![CDATA[<p>Perhaps make a \t when pressing a lonnnnnng tab ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tucows Farm: The Tucows Developers' Hangout</title>
		<link>http://ajaxian.com/archives/handling-tabs-in-textareas/comment-page-1#comment-9101</link>
		<dc:creator>Tucows Farm: The Tucows Developers' Hangout</dc:creator>
		<pubDate>Mon, 08 May 2006 12:45:03 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/handling-tabs-in-textareas#comment-9101</guid>
		<description>&lt;strong&gt;[JavaScript] Handling Tabs in Textareas&lt;/strong&gt;

</description>
		<content:encoded><![CDATA[<p><strong>[JavaScript] Handling Tabs in Textareas</strong></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Phill Kenoyer</title>
		<link>http://ajaxian.com/archives/handling-tabs-in-textareas/comment-page-1#comment-8865</link>
		<dc:creator>Phill Kenoyer</dc:creator>
		<pubDate>Fri, 05 May 2006 20:03:49 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/handling-tabs-in-textareas#comment-8865</guid>
		<description>&lt;code&gt;
In my browser CTRL-Tab already makes a tab.  So, why do I need to use JavaScript to make the Tab key work?

	Tabbed with CTRL-Tab (HTML doesn&#039;t show tabs.)
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p><code><br />
In my browser CTRL-Tab already makes a tab.  So, why do I need to use JavaScript to make the Tab key work?</p>
<p>	Tabbed with CTRL-Tab (HTML doesn't show tabs.)<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dean Edwards</title>
		<link>http://ajaxian.com/archives/handling-tabs-in-textareas/comment-page-1#comment-8862</link>
		<dc:creator>Dean Edwards</dc:creator>
		<pubDate>Fri, 05 May 2006 18:51:26 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/handling-tabs-in-textareas#comment-8862</guid>
		<description>&gt; Does anyone know if itâ€™s possible to make this work in IE?

I&#039;ve got a working example somewhere. I&#039;ll post it to my blog over the weekend.</description>
		<content:encoded><![CDATA[<p>&gt; Does anyone know if itâ€™s possible to make this work in IE?</p>
<p>I&#8217;ve got a working example somewhere. I&#8217;ll post it to my blog over the weekend.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris Iufer</title>
		<link>http://ajaxian.com/archives/handling-tabs-in-textareas/comment-page-1#comment-8861</link>
		<dc:creator>Chris Iufer</dc:creator>
		<pubDate>Fri, 05 May 2006 18:31:00 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/handling-tabs-in-textareas#comment-8861</guid>
		<description>I think this is very useful. I know that this is one of those things I will need someday and yet not want to have to spend time developing it. I have always been frusturated by the lack of tab support in the &quot;online editors&quot; that some blog apps (textpattern) provide. Im all about tabbing my code so it gets annoying to have to un-train my brain every time I have to bother with it. Now if we could only get someone to make this into a nice little textpattern or wordpress plugin...</description>
		<content:encoded><![CDATA[<p>I think this is very useful. I know that this is one of those things I will need someday and yet not want to have to spend time developing it. I have always been frusturated by the lack of tab support in the &#8220;online editors&#8221; that some blog apps (textpattern) provide. Im all about tabbing my code so it gets annoying to have to un-train my brain every time I have to bother with it. Now if we could only get someone to make this into a nice little textpattern or wordpress plugin&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: The Miles Rausch DootDoot Weblog Page Website By Awayken &#187; Blog Archive &#187; links for 2006-05-05</title>
		<link>http://ajaxian.com/archives/handling-tabs-in-textareas/comment-page-1#comment-8860</link>
		<dc:creator>The Miles Rausch DootDoot Weblog Page Website By Awayken &#187; Blog Archive &#187; links for 2006-05-05</dc:creator>
		<pubDate>Fri, 05 May 2006 18:20:21 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/handling-tabs-in-textareas#comment-8860</guid>
		<description>[...] Ajaxian Â» Handling Tabs in Textareas (tags: javascript ajax tabs) [...]</description>
		<content:encoded><![CDATA[<p>[...] Ajaxian Â» Handling Tabs in Textareas (tags: javascript ajax tabs) [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Allen</title>
		<link>http://ajaxian.com/archives/handling-tabs-in-textareas/comment-page-1#comment-8859</link>
		<dc:creator>Allen</dc:creator>
		<pubDate>Fri, 05 May 2006 18:05:30 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/handling-tabs-in-textareas#comment-8859</guid>
		<description>theres a much better solution to all of this, onkeyup replace &quot;\t&quot; in that text field with an actual \t or &quot;	&quot; (thats a real tab), you cant use modifiers like control shift or alt, they are already used, anyway this solution is way too bulky for something so simple (KISS)</description>
		<content:encoded><![CDATA[<p>theres a much better solution to all of this, onkeyup replace &#8220;\t&#8221; in that text field with an actual \t or &#8221;	&#8221; (thats a real tab), you cant use modifiers like control shift or alt, they are already used, anyway this solution is way too bulky for something so simple (KISS)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeremy Dunck</title>
		<link>http://ajaxian.com/archives/handling-tabs-in-textareas/comment-page-1#comment-8840</link>
		<dc:creator>Jeremy Dunck</dc:creator>
		<pubDate>Fri, 05 May 2006 13:16:47 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/handling-tabs-in-textareas#comment-8840</guid>
		<description>&quot;
If you do not wish to lose the TAB functionality, you can use SHIFT+TAB to insert a TAB just like you use SHIFT+ENTER to insert a new line on instant messengers like MSN Messenger.
&quot;

Except that Shift-Tab is already used to tab to the previous control.  Control-Tab switches to next tab in FF, Ctrl-Shift-Tab switches to previous tab in FF, Alt-Tab and Alt-Shift-Tab similarly switch windows in Windows.

Ctrl-Alt-Tab and/or Ctrl-Alt-Shift-Tab might be available, but, uh, bleh.</description>
		<content:encoded><![CDATA[<p>&#8221;<br />
If you do not wish to lose the TAB functionality, you can use SHIFT+TAB to insert a TAB just like you use SHIFT+ENTER to insert a new line on instant messengers like MSN Messenger.<br />
&#8221;</p>
<p>Except that Shift-Tab is already used to tab to the previous control.  Control-Tab switches to next tab in FF, Ctrl-Shift-Tab switches to previous tab in FF, Alt-Tab and Alt-Shift-Tab similarly switch windows in Windows.</p>
<p>Ctrl-Alt-Tab and/or Ctrl-Alt-Shift-Tab might be available, but, uh, bleh.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Darren</title>
		<link>http://ajaxian.com/archives/handling-tabs-in-textareas/comment-page-1#comment-8795</link>
		<dc:creator>Darren</dc:creator>
		<pubDate>Thu, 04 May 2006 23:39:07 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/handling-tabs-in-textareas#comment-8795</guid>
		<description>Does anyone know if it&#039;s possible to make this work in IE?</description>
		<content:encoded><![CDATA[<p>Does anyone know if it&#8217;s possible to make this work in IE?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Roy</title>
		<link>http://ajaxian.com/archives/handling-tabs-in-textareas/comment-page-1#comment-8789</link>
		<dc:creator>Roy</dc:creator>
		<pubDate>Thu, 04 May 2006 22:38:52 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/handling-tabs-in-textareas#comment-8789</guid>
		<description>If you do not wish to lose the TAB functionality, you can use SHIFT+TAB to insert a TAB just like you use SHIFT+ENTER to insert a new line on instant  messengers like MSN Messenger.
Below is my small modification to make that happen.

NOTE: For IE, you can use the evt.shiftKey instead. 


Change from 
&lt;b&gt;
            // Tab key - insert tab expansion
            if (evt.keyCode == 9) {
&lt;/b&gt;
to:
&lt;code&gt;
&lt;b&gt;
            // Tab key - insert tab expansion
            if ((evt.keyCode == 9)&amp;&amp;(evt.shiftKey))  {
&lt;/b&gt;&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>If you do not wish to lose the TAB functionality, you can use SHIFT+TAB to insert a TAB just like you use SHIFT+ENTER to insert a new line on instant  messengers like MSN Messenger.<br />
Below is my small modification to make that happen.</p>
<p>NOTE: For IE, you can use the evt.shiftKey instead. </p>
<p>Change from<br />
<b><br />
            // Tab key &#8211; insert tab expansion<br />
            if (evt.keyCode == 9) {<br />
</b><br />
to:<br />
<code><br />
<b><br />
            // Tab key - insert tab expansion<br />
            if ((evt.keyCode == 9)&amp;&amp;(evt.shiftKey))  {<br />
</b></code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Handling Tabs in Textareas at The Hero Dies in This One</title>
		<link>http://ajaxian.com/archives/handling-tabs-in-textareas/comment-page-1#comment-8786</link>
		<dc:creator>Handling Tabs in Textareas at The Hero Dies in This One</dc:creator>
		<pubDate>Thu, 04 May 2006 22:08:20 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/handling-tabs-in-textareas#comment-8786</guid>
		<description>[...] Handle Tabs in Textareas with support for indenting selections etc. Very nice. (via) [...]</description>
		<content:encoded><![CDATA[<p>[...] Handle Tabs in Textareas with support for indenting selections etc. Very nice. (via) [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sean FousheÃ©</title>
		<link>http://ajaxian.com/archives/handling-tabs-in-textareas/comment-page-1#comment-8779</link>
		<dc:creator>Sean FousheÃ©</dc:creator>
		<pubDate>Thu, 04 May 2006 19:34:55 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/handling-tabs-in-textareas#comment-8779</guid>
		<description>@ Mike: Actually if you use ctl-tab it moves you out of the text area and onto the next form element.  It would be better to switch this behaviour and make ctl-tab the magic key to add a tab-space in your text and leave tab working as it is expected.  All this method requires is a simple note telling users how to add a tab-space to their text.</description>
		<content:encoded><![CDATA[<p>@ Mike: Actually if you use ctl-tab it moves you out of the text area and onto the next form element.  It would be better to switch this behaviour and make ctl-tab the magic key to add a tab-space in your text and leave tab working as it is expected.  All this method requires is a simple note telling users how to add a tab-space to their text.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

