Skip to content

Commit 3086a88

Browse files
authored
Fix mobile behavior and small issues, cleanup code (#47)
1 parent 8743f9b commit 3086a88

1 file changed

Lines changed: 13 additions & 20 deletions

File tree

index.html

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
font: 18px/1.6 "Menlo", "DejaVu Sans Mono", "Consolas", monospace;
4444
background: var(--bg);
4545
color: var(--text);
46-
height: 100vh;
46+
height: 100dvh;
4747
display: grid;
4848
grid-template-rows: auto 1fr auto;
4949
transition: background var(--transition);
@@ -53,13 +53,10 @@
5353
body,
5454
#editor,
5555
.btn,
56-
#editor::placeholder {
57-
transition: background var(--transition), color var(--transition), opacity var(--transition);
58-
}
59-
56+
#editor::placeholder,
6057
#count,
6158
[data-action="theme"] {
62-
transition: opacity var(--transition), color var(--transition);
59+
transition: background var(--transition), color var(--transition), opacity var(--transition);
6360
}
6461

6562
.controls {
@@ -103,7 +100,7 @@
103100

104101
#editor {
105102
width: 100%;
106-
height: min(80vh, 100%);
103+
height: min(80dvh, 100%);
107104
padding-inline: clamp(20px, 10vw, 20vh);
108105
padding-block: 2.5vh;
109106
font: inherit;
@@ -211,6 +208,8 @@
211208
}
212209

213210
bindEvents() {
211+
const isMac = navigator.platform.toUpperCase().indexOf('MAC') >= 0;
212+
214213
// Editor events
215214
this.editor.addEventListener('input', () => {
216215
this.saveText();
@@ -223,7 +222,6 @@
223222

224223
// Keyboard shortcuts
225224
document.addEventListener('keydown', (e) => {
226-
const isMac = navigator.platform.toUpperCase().indexOf('MAC') >= 0;
227225
const modKey = isMac ? e.metaKey : e.ctrlKey;
228226

229227
if (e.key === 'Tab' && e.target === this.editor) {
@@ -295,7 +293,7 @@
295293
this.editor.focus();
296294
});
297295

298-
window.addEventListener('resize', () => this.updateFade());
296+
window.addEventListener('resize', () => this.updateFade(), { passive: true });
299297

300298
// Control buttons
301299
const actions = {
@@ -311,9 +309,9 @@
311309
const action = e.target.dataset.action;
312310
if (action && actions[action]) {
313311
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+
}
317315
}
318316
});
319317

@@ -426,7 +424,6 @@
426424
if (!this.visible) {
427425
this.controls.forEach(c => c.classList.remove('hidden'));
428426
this.visible = true;
429-
this.updateCount();
430427
}
431428
}
432429

@@ -451,13 +448,9 @@
451448
}
452449

453450
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';
461454
}
462455

463456
// Actions

0 commit comments

Comments
 (0)