- commit
- 8c2dc7ee8dce47134d7ba3b827d658298309eb65
- parent
- efe07380d1d4de07b6ed2710e3ade91ae4e28db9
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2020-05-03 18:49
refactor: setText()
Diffstat
M | static/index.js | 21 | +++++++++++---------- |
1 files changed, 11 insertions, 10 deletions
diff --git a/static/index.js b/static/index.js
@@ -11,18 +11,22 @@ var localChanges = []; 11 11 12 12 document.title += ' - ' + room; 13 13 -1 14 var setText = function(text, start, end) { -1 15 if (text !== el.value) { -1 16 el.value = text; -1 17 el.selectionStart = start; -1 18 el.selectionEnd = end; -1 19 old = text; -1 20 } -1 21 }; -1 22 14 23 var applyChanges = function(changes) { 15 24 var text = el.value; 16 25 var selection = [el.selectionStart, el.selectionEnd]; 17 26 while (changes.length) { 18 27 text = context.apply(text, changes.shift(), selection); 19 28 }20 -1 if (text !== el.value) {21 -1 el.value = text;22 -1 el.selectionStart = selection[0];23 -1 el.selectionEnd = selection[1];24 -1 old = text;25 -1 }-1 29 setText(text, selection[0], selection[1]); 26 30 }; 27 31 28 32 el.addEventListener('input', function() { @@ -39,10 +43,7 @@ signal.listen(room, function(msg) { 39 43 } else if (msg.request === 'text') { 40 44 signal.post(room, {sender: id, text: el.value}); 41 45 } else if (msg.text && !el.value) {42 -1 el.value = msg.text;43 -1 old = msg.text;44 -1 el.selectionStart = 0;45 -1 el.selectionEnd = 0;-1 46 setText(msg.text, 0, 0); 46 47 } 47 48 }); 48 49