Skip to content

Commit b9ac5bc

Browse files
authored
Fix flicker on text load (#41)
1 parent 3194614 commit b9ac5bc

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

index.html

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,15 @@
299299
}
300300

301301
loadText() {
302-
this.editor.value = localStorage.getItem(SHIRO_SAVED_TEXT) || '';
303-
this.loadCursorPosition();
304-
this.updateCount();
302+
// Hide editor until text is loaded to prevent flickering
303+
const editor = this.editor;
304+
editor.style.visibility = 'hidden';
305+
editor.value = localStorage.getItem(SHIRO_SAVED_TEXT) || '';
306+
requestAnimationFrame(() => {
307+
this.loadCursorPosition();
308+
editor.style.visibility = 'visible';
309+
this.updateCount();
310+
});
305311
}
306312

307313
saveCursorPosition() {
@@ -313,15 +319,14 @@
313319
if (saved) {
314320
const position = parseInt(saved);
315321
const editor = this.editor;
316-
setTimeout(() => {
322+
requestAnimationFrame(() => {
317323
editor.setSelectionRange(position, position);
318324
editor.focus({ preventScroll: true });
319325

320326
// Fix scroll jumping when cursor is on the first line
321327
const lineNumber = editor.value.substring(0, position).split('\n').length - 1;
322328
if (lineNumber === 0) editor.scrollTop = 0;
323-
324-
}, 0);
329+
});
325330
}
326331
}
327332

0 commit comments

Comments
 (0)