- commit
- 798763c75841f82cc846203e5733dfd60c5cf9de
- parent
- 586e47897dff05cfab53cb786cd8c4e839fde1f3
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2020-05-07 09:03
inline setText
Diffstat
M | static/pad.js | 30 | ++++++++++++++---------------- |
1 files changed, 14 insertions, 16 deletions
diff --git a/static/pad.js b/static/pad.js
@@ -16,19 +16,6 @@ var localChanges = []; 16 16 17 17 document.title += ' - ' + location.hash.slice(1); 18 1819 -1 var setText = function(text, start, end) {20 -1 if (text !== el.value) {21 -1 var scrollTop = el.scrollTop;22 -1 el.value = text;23 -1 el.selectionStart = start;24 -1 el.selectionEnd = end;25 -1 requestAnimationFrame(function() {26 -1 el.scrollTop = scrollTop;27 -1 });28 -1 old = text;29 -1 }30 -1 };31 -132 19 var backup = utils.throttled(function() { 33 20 if (!el.readonly) { 34 21 via.store(room, el.value, true); @@ -46,7 +33,16 @@ var applyChanges = function(changes) { 46 33 while (changes.length) { 47 34 text = context.apply(text, changes.shift(), selection); 48 35 }49 -1 setText(text, selection[0], selection[1]);-1 36 if (text !== el.value) { -1 37 var scrollTop = el.scrollTop; -1 38 el.value = text; -1 39 el.selectionStart = selection[0]; -1 40 el.selectionEnd = selection[1]; -1 41 requestAnimationFrame(function() { -1 42 el.scrollTop = scrollTop; -1 43 }); -1 44 old = text; -1 45 } 50 46 }; 51 47 52 48 el.addEventListener('input', function() { @@ -69,7 +65,8 @@ via.listen(room, function(msg) { 69 65 if (!el.value) { 70 66 via.restore(room).then(text => { 71 67 if (!el.value) {72 -1 setText(text, 0, 0);-1 68 el.value = text; -1 69 old = text; 73 70 } 74 71 }).finally(() => { 75 72 el.readOnly = false; @@ -81,7 +78,8 @@ via.listen(room, function(msg) { 81 78 } else if (msg[1] === 'request') { 82 79 via.send(room, [id, 'text', el.value]); 83 80 } else if (msg[1] === 'text' && !el.value) {84 -1 setText(msg[2], 0, 0);-1 81 el.value = msg[2]; -1 82 old = msg[2]; 85 83 el.readOnly = false; 86 84 } 87 85 });