This commit is contained in:
Erin Call 2016-08-26 11:26:19 +00:00 committed by GitHub
commit 381102da1e
2 changed files with 32 additions and 30 deletions

View file

@ -275,7 +275,7 @@ haste.prototype.configureButtons = function() {
$where: $('#box2 .new'), $where: $('#box2 .new'),
label: 'New', label: 'New',
shortcut: function(evt) { shortcut: function(evt) {
return evt.ctrlKey && evt.keyCode === 78 return evt.ctrlKey && evt.keyCode === 78;
}, },
shortcutDescription: 'control + n', shortcutDescription: 'control + n',
action: function() { action: function() {
@ -361,35 +361,37 @@ 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) { var sel, startPos, endPos, scrollTop,
evt.preventDefault(); myValue = ' ';
var myValue = ' '; if (evt.ctrlKey || evt.keyCode !== 9) {
// http://stackoverflow.com/questions/946534/insert-text-into-textarea-with-jquery return true;
// For browsers like Internet Explorer }
if (document.selection) {
this.focus(); evt.preventDefault();
sel = document.selection.createRange(); // http://stackoverflow.com/questions/946534/insert-text-into-textarea-with-jquery
sel.text = myValue; // For browsers like Internet Explorer
this.focus(); if (document.selection) {
} this.focus();
// Mozilla and Webkit sel = document.selection.createRange();
else if (this.selectionStart || this.selectionStart == '0') { sel.text = myValue;
var startPos = this.selectionStart; this.focus();
var endPos = this.selectionEnd; }
var scrollTop = this.scrollTop; // Mozilla and Webkit
this.value = this.value.substring(0, startPos) + myValue + else if (this.selectionStart || this.selectionStart == '0') {
this.value.substring(endPos,this.value.length); startPos = this.selectionStart;
this.focus(); endPos = this.selectionEnd;
this.selectionStart = startPos + myValue.length; scrollTop = this.scrollTop;
this.selectionEnd = startPos + myValue.length; this.value = this.value.substring(0, startPos) + myValue +
this.scrollTop = scrollTop; this.value.substring(endPos,this.value.length);
} this.focus();
else { this.selectionStart = startPos + myValue.length;
this.value += myValue; this.selectionEnd = startPos + myValue.length;
this.focus(); this.scrollTop = scrollTop;
} }
else {
this.value += myValue;
this.focus();
} }
}); });

File diff suppressed because one or more lines are too long