Refactor to reduce nesting

This commit is contained in:
Andrew Lorente 2014-07-23 13:27:03 -07:00
parent f9558a34fa
commit cfff6616e6
2 changed files with 30 additions and 29 deletions

View File

@ -361,35 +361,36 @@ haste.prototype.configureShortcuts = function() {
///// Tab behavior in the textarea - 2 spaces per tab ///// Tab behavior in the textarea - 2 spaces per tab
$(function() { $(function() {
$('textarea').keydown(function(evt) { $('textarea').keydown(function(evt) {
if (evt.keyCode === 9 && ! evt.ctrlKey) { if (evt.ctrlKey || evt.keyCode !== 9) {
evt.preventDefault(); return true;
var myValue = ' '; }
// http://stackoverflow.com/questions/946534/insert-text-into-textarea-with-jquery
// For browsers like Internet Explorer evt.preventDefault();
if (document.selection) { var myValue = ' ';
this.focus(); // http://stackoverflow.com/questions/946534/insert-text-into-textarea-with-jquery
sel = document.selection.createRange(); // For browsers like Internet Explorer
sel.text = myValue; if (document.selection) {
this.focus(); this.focus();
} sel = document.selection.createRange();
// Mozilla and Webkit sel.text = myValue;
else if (this.selectionStart || this.selectionStart == '0') { this.focus();
var startPos = this.selectionStart; }
var endPos = this.selectionEnd; // Mozilla and Webkit
var scrollTop = this.scrollTop; else if (this.selectionStart || this.selectionStart == '0') {
this.value = this.value.substring(0, startPos) + myValue + var startPos = this.selectionStart;
this.value.substring(endPos,this.value.length); var endPos = this.selectionEnd;
this.focus(); var scrollTop = this.scrollTop;
this.selectionStart = startPos + myValue.length; this.value = this.value.substring(0, startPos) + myValue +
this.selectionEnd = startPos + myValue.length; this.value.substring(endPos,this.value.length);
this.scrollTop = scrollTop; this.focus();
} this.selectionStart = startPos + myValue.length;
else { this.selectionEnd = startPos + myValue.length;
this.value += myValue; this.scrollTop = scrollTop;
this.focus(); }
} else {
this.value += myValue;
this.focus();
} }
}); });

File diff suppressed because one or more lines are too long