[14] | 1 | /** Umožní zadávat tabulátor */ |
---|
| 2 | |
---|
| 3 | var tab = "\t"; |
---|
| 4 | |
---|
| 5 | function checkTab(evt) { |
---|
| 6 | |
---|
| 7 | var t = evt.target; |
---|
| 8 | var ss = t.selectionStart; |
---|
| 9 | var se = t.selectionEnd; |
---|
| 10 | |
---|
| 11 | |
---|
| 12 | // Tabulátor |
---|
| 13 | if (evt.keyCode == 9) { |
---|
| 14 | evt.preventDefault(); |
---|
| 15 | |
---|
| 16 | // Víceřádkový výběr |
---|
| 17 | if (ss != se && t.value.slice(ss,se).indexOf("\n") != -1) { |
---|
| 18 | var pre = t.value.slice(0,ss); |
---|
| 19 | var sel = t.value.slice(ss,se).replace(/\n/g,"\n"+tab); |
---|
| 20 | var post = t.value.slice(se,t.value.length); |
---|
| 21 | t.value = pre.concat(tab).concat(sel).concat(post); |
---|
| 22 | t.selectionStart = ss + tab.length; |
---|
| 23 | t.selectionEnd = se + tab.length; |
---|
| 24 | } |
---|
| 25 | |
---|
| 26 | // Jednořádkový nebo žádný výběr |
---|
| 27 | else { |
---|
| 28 | t.value = t.value.slice(0,ss).concat(tab).concat(t.value.slice(ss,t.value.length)); |
---|
| 29 | if (ss == se) { |
---|
| 30 | t.selectionStart = t.selectionEnd = ss + tab.length; |
---|
| 31 | } |
---|
| 32 | else { |
---|
| 33 | t.selectionStart = ss + tab.length; |
---|
| 34 | t.selectionEnd = se + tab.length; |
---|
| 35 | } |
---|
| 36 | } |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | // Backspace |
---|
| 40 | else if (evt.keyCode==8 && t.value.slice(ss - 4,ss) == tab) { |
---|
| 41 | evt.preventDefault(); |
---|
| 42 | t.value = t.value.slice(0,ss - 4).concat(t.value.slice(ss,t.value.length)); |
---|
| 43 | t.selectionStart = t.selectionEnd = ss - tab.length; |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | // Delete |
---|
| 47 | else if (evt.keyCode==46 && t.value.slice(se,se + 4) == tab) { |
---|
| 48 | evt.preventDefault(); |
---|
| 49 | t.value = t.value.slice(0,ss).concat(t.value.slice(ss + 4,t.value.length)); |
---|
| 50 | t.selectionStart = t.selectionEnd = ss; |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | // Doleva |
---|
| 54 | else if (evt.keyCode == 37 && t.value.slice(ss - 4,ss) == tab) { |
---|
| 55 | alert("levá"); |
---|
| 56 | evt.preventDefault(); |
---|
| 57 | t.selectionStart = t.selectionEnd = ss - 4; |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | |
---|
| 61 | // Doprava |
---|
| 62 | else if (evt.keyCode == 39 && t.value.slice(ss,ss + 4) == tab) { |
---|
| 63 | alert("pravá"); |
---|
| 64 | evt.preventDefault(); |
---|
| 65 | t.selectionStart = t.selectionEnd = ss + 4; |
---|
| 66 | } |
---|
| 67 | } |
---|