commit e8a56c506d15fa7831308701fb6e04f80f11ed60
parent a4e9723a00d72dd5813d0def5f24f8232af997c8
Author: Hunter
Date:   Fri, 19 Dec 2025 16:27:09 -0500

preserve editor position when leaving fullscreen (mobile)

Diffstat:
Mindex.html | 21++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/index.html b/index.html @@ -239,6 +239,8 @@ let updateTimer; let editorView; const preview = document.getElementById('preview'); + const editorPane = document.querySelector('.editor-pane'); + const previewPane = document.querySelector('.preview-pane'); const storageKey = 'html-lab-content'; let isFullscreen = false; let showLineNumbers = false; @@ -247,8 +249,6 @@ let lineWrappingCompartment; function toggleFullscreen() { - const previewPane = document.querySelector('.preview-pane'); - const editorPane = document.querySelector('.editor-pane'); isFullscreen = !isFullscreen; @@ -653,7 +653,22 @@ if (isKeyboardOpen && isEditorFocused) { document.body.classList.add('mobile-keyboard-open'); } else if (!isKeyboardOpen) { - document.body.classList.remove('mobile-keyboard-open'); + const wasKeyboardOpen = document.body.classList.contains('mobile-keyboard-open'); + + if (wasKeyboardOpen && editorView) { + // Hide editor, update layout, then scroll cursor into view + const pos = editorView.state.selection.main.head; + editorPane.style.opacity = '0'; + document.body.classList.remove('mobile-keyboard-open'); + requestAnimationFrame(() => requestAnimationFrame(() => { + const lineBlock = editorView.lineBlockAt(pos); + const targetScroll = lineBlock.top - (editorView.dom.clientHeight / 2); + editorView.scrollDOM.scrollTop = Math.max(0, targetScroll); + editorPane.style.opacity = ''; + })); + } else { + document.body.classList.remove('mobile-keyboard-open'); + } } }