-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdivmonitor.js
More file actions
45 lines (41 loc) · 1.14 KB
/
divmonitor.js
File metadata and controls
45 lines (41 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
This file includes the version of insertText()
for use when <div id="monitor" contentEditable>
06apr23
*/
function cursorEnd() {
document.getElementById('monitor').focus();
let n = document.getElementById('monitor').lastChild;
let r = new Range();
r.setStartAfter(n);
let s = document.getSelection();
s.removeAllRanges();
s.addRange(r);
}
function insertText(letter) {
if (letter=='')
return;
undoPush();
let s = document.getSelection();
let r = s.getRangeAt(0);
r.deleteContents();
let n = document.createTextNode(letter);
r.insertNode(n);
s.removeAllRanges();
r = r.cloneRange();
r.selectNode(n);
r.collapse(false);
s.addRange(r);
for (let position = 0; position < letter.length - 1; position++) {
s.modify("move", "right", "character");
}
document.getElementById('monitor').normalize();
document.getElementById('monitor').focus();
}
function removePending() { // removes pending letters
var m = document.getElementById('monitor');
var s = m.innerHTML;
s = s.replace(/\u200D.*\u200C/g,'');
m.innerHTML = s;
cursorEnd();
}