annotate src/test/editor.html @ 19:da006d1c1eba

use contentEditable
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 13 Jul 2022 08:47:13 -0600
parents
children 3ea49246d6a7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19
da006d1c1eba use contentEditable
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 <!doctype html>
da006d1c1eba use contentEditable
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 <html>
da006d1c1eba use contentEditable
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 <head>
da006d1c1eba use contentEditable
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 <meta name="viewport" content="width=device-width, initial-scale=1">
da006d1c1eba use contentEditable
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 <style>
da006d1c1eba use contentEditable
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 [contentEditable] {
da006d1c1eba use contentEditable
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 padding: 7px;
da006d1c1eba use contentEditable
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 border: 1px solid #777;
da006d1c1eba use contentEditable
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 white-space: pre-wrap;
da006d1c1eba use contentEditable
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 }
da006d1c1eba use contentEditable
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 </style>
da006d1c1eba use contentEditable
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 <script>
da006d1c1eba use contentEditable
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 function log() {
da006d1c1eba use contentEditable
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 let edit = document.querySelector('[contentEditable]');
da006d1c1eba use contentEditable
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 console.log(edit.innerHTML);
da006d1c1eba use contentEditable
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 //console.log(edit.textContent);
da006d1c1eba use contentEditable
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 }
da006d1c1eba use contentEditable
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18 function test() {
da006d1c1eba use contentEditable
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 let edit = document.querySelector('[contentEditable]');
da006d1c1eba use contentEditable
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 edit.focus();
da006d1c1eba use contentEditable
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 let s = getSelection();
da006d1c1eba use contentEditable
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 let r = s.getRangeAt(0);
da006d1c1eba use contentEditable
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 //console.log(s);
da006d1c1eba use contentEditable
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 r.deleteContents();
da006d1c1eba use contentEditable
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 let t = document.createTextNode('\n');
da006d1c1eba use contentEditable
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 r.insertNode(t);
da006d1c1eba use contentEditable
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 r.collapse();
da006d1c1eba use contentEditable
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 }
da006d1c1eba use contentEditable
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 </script>
da006d1c1eba use contentEditable
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 </head>
da006d1c1eba use contentEditable
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 <body>
da006d1c1eba use contentEditable
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 <p>top</p>
da006d1c1eba use contentEditable
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33 <div contentEditable>
da006d1c1eba use contentEditable
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34 aaa <b>bbb</b> <i>iii</i>
da006d1c1eba use contentEditable
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 1
da006d1c1eba use contentEditable
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36 2
da006d1c1eba use contentEditable
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
37 3
da006d1c1eba use contentEditable
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
38 zzz
da006d1c1eba use contentEditable
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
39 </div>
da006d1c1eba use contentEditable
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
40 <p>
da006d1c1eba use contentEditable
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
41 <button onclick="log()">log</button>
da006d1c1eba use contentEditable
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
42 <button onclick="test()">test</button>
da006d1c1eba use contentEditable
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43 </p>
da006d1c1eba use contentEditable
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44 <p>bottom</p>
da006d1c1eba use contentEditable
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 </body>
da006d1c1eba use contentEditable
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46 </html>