|
43 | 43 | font: 18px/1.6 "Menlo", "DejaVu Sans Mono", "Consolas", monospace; |
44 | 44 | background: var(--bg); |
45 | 45 | color: var(--text); |
46 | | - height: 100vh; |
| 46 | + height: 100dvh; |
47 | 47 | display: grid; |
48 | 48 | grid-template-rows: auto 1fr auto; |
49 | 49 | transition: background var(--transition); |
|
53 | 53 | body, |
54 | 54 | #editor, |
55 | 55 | .btn, |
56 | | - #editor::placeholder { |
57 | | - transition: background var(--transition), color var(--transition), opacity var(--transition); |
58 | | - } |
59 | | - |
| 56 | + #editor::placeholder, |
60 | 57 | #count, |
61 | 58 | [data-action="theme"] { |
62 | | - transition: opacity var(--transition), color var(--transition); |
| 59 | + transition: background var(--transition), color var(--transition), opacity var(--transition); |
63 | 60 | } |
64 | 61 |
|
65 | 62 | .controls { |
|
103 | 100 |
|
104 | 101 | #editor { |
105 | 102 | width: 100%; |
106 | | - height: min(80vh, 100%); |
| 103 | + height: min(80dvh, 100%); |
107 | 104 | padding-inline: clamp(20px, 10vw, 20vh); |
108 | 105 | padding-block: 2.5vh; |
109 | 106 | font: inherit; |
|
211 | 208 | } |
212 | 209 |
|
213 | 210 | bindEvents() { |
| 211 | + const isMac = navigator.platform.toUpperCase().indexOf('MAC') >= 0; |
| 212 | + |
214 | 213 | // Editor events |
215 | 214 | this.editor.addEventListener('input', () => { |
216 | 215 | this.saveText(); |
|
223 | 222 |
|
224 | 223 | // Keyboard shortcuts |
225 | 224 | document.addEventListener('keydown', (e) => { |
226 | | - const isMac = navigator.platform.toUpperCase().indexOf('MAC') >= 0; |
227 | 225 | const modKey = isMac ? e.metaKey : e.ctrlKey; |
228 | 226 |
|
229 | 227 | if (e.key === 'Tab' && e.target === this.editor) { |
|
295 | 293 | this.editor.focus(); |
296 | 294 | }); |
297 | 295 |
|
298 | | - window.addEventListener('resize', () => this.updateFade()); |
| 296 | + window.addEventListener('resize', () => this.updateFade(), { passive: true }); |
299 | 297 |
|
300 | 298 | // Control buttons |
301 | 299 | const actions = { |
|
311 | 309 | const action = e.target.dataset.action; |
312 | 310 | if (action && actions[action]) { |
313 | 311 | actions[action](); |
314 | | - this.editor.focus(); |
315 | | - } else if (e.target !== this.editor) { |
316 | | - this.editor.focus(); |
| 312 | + if (!('ontouchstart' in window)) { |
| 313 | + this.editor.focus(); |
| 314 | + } |
317 | 315 | } |
318 | 316 | }); |
319 | 317 |
|
|
426 | 424 | if (!this.visible) { |
427 | 425 | this.controls.forEach(c => c.classList.remove('hidden')); |
428 | 426 | this.visible = true; |
429 | | - this.updateCount(); |
430 | 427 | } |
431 | 428 | } |
432 | 429 |
|
|
451 | 448 | } |
452 | 449 |
|
453 | 450 | updateFade() { |
454 | | - const editor = this.editor; |
455 | | - const top = this.fadeTop; |
456 | | - const bottom = this.fadeBottom; |
457 | | - const { scrollTop, scrollHeight, clientHeight } = editor; |
458 | | - |
459 | | - top.style.opacity = scrollTop > 0 ? '1' : '0'; |
460 | | - bottom.style.opacity = Math.ceil(scrollTop + clientHeight) < scrollHeight ? '1' : '0'; |
| 451 | + const { scrollTop, scrollHeight, clientHeight } = this.editor; |
| 452 | + this.fadeTop.style.opacity = scrollTop > 0 ? '1' : '0'; |
| 453 | + this.fadeBottom.style.opacity = Math.ceil(scrollTop + clientHeight) < scrollHeight ? '1' : '0'; |
461 | 454 | } |
462 | 455 |
|
463 | 456 | // Actions |
|
0 commit comments