|
| 1 | +addEventListener('keydown', (event) => { |
| 2 | + let target = event.originalTarget; |
| 3 | + if (!target.hasAttribute("placeholder")) return; |
| 4 | + if (!target.placeholder.toLowerCase().includes("prompt")) return; |
| 5 | + |
| 6 | + let plus = "ArrowUp" |
| 7 | + let minus = "ArrowDown" |
| 8 | + if (event.key != plus && event.key != minus) return; |
| 9 | + |
| 10 | + selectionStart = target.selectionStart; |
| 11 | + selectionEnd = target.selectionEnd; |
| 12 | + if(selectionStart == selectionEnd) return; |
| 13 | + |
| 14 | + event.preventDefault(); |
| 15 | + |
| 16 | + if (selectionStart == 0 || target.value[selectionStart - 1] != "(") { |
| 17 | + target.value = target.value.slice(0, selectionStart) + |
| 18 | + "(" + target.value.slice(selectionStart, selectionEnd) + ":1.0)" + |
| 19 | + target.value.slice(selectionEnd); |
| 20 | + |
| 21 | + target.focus(); |
| 22 | + target.selectionStart = selectionStart + 1; |
| 23 | + target.selectionEnd = selectionEnd + 1; |
| 24 | + |
| 25 | + } else { |
| 26 | + end = target.value.slice(selectionEnd + 1).indexOf(")") + 1; |
| 27 | + weight = parseFloat(target.value.slice(selectionEnd + 1, selectionEnd + 1 + end)); |
| 28 | + if (event.key == minus) weight -= 0.1; |
| 29 | + if (event.key == plus) weight += 0.1; |
| 30 | + |
| 31 | + weight = parseFloat(weight.toPrecision(12)); |
| 32 | + |
| 33 | + target.value = target.value.slice(0, selectionEnd + 1) + |
| 34 | + weight + |
| 35 | + target.value.slice(selectionEnd + 1 + end - 1); |
| 36 | + |
| 37 | + target.focus(); |
| 38 | + target.selectionStart = selectionStart; |
| 39 | + target.selectionEnd = selectionEnd; |
| 40 | + } |
| 41 | +}); |
0 commit comments