preserve editor position when leaving fullscreen (mobile)

Hunter
Friday, December 19th, 2025 at 4:27 PM

index.html+18-3

index.html
239  		let updateTimer;
240  		let editorView;
241  		const preview = document.getElementById('preview');
242 +		const editorPane = document.querySelector('.editor-pane');
243 +		const previewPane = document.querySelector('.preview-pane');
244  		const storageKey = 'html-lab-content';
245  		let isFullscreen = false;
246  		let showLineNumbers = false;

249  		let lineWrappingCompartment;
250  
251  		function toggleFullscreen() {
    -			const previewPane = document.querySelector('.preview-pane');
    -			const editorPane = document.querySelector('.editor-pane');
252  			
253  			isFullscreen = !isFullscreen;
254  			

653  			if (isKeyboardOpen && isEditorFocused) {
654  				document.body.classList.add('mobile-keyboard-open');
655  			} else if (!isKeyboardOpen) {
    -				document.body.classList.remove('mobile-keyboard-open');
656 +				const wasKeyboardOpen = document.body.classList.contains('mobile-keyboard-open');
657 +
658 +				if (wasKeyboardOpen && editorView) {
659 +					// Hide editor, update layout, then scroll cursor into view
660 +					const pos = editorView.state.selection.main.head;
661 +					editorPane.style.opacity = '0';
662 +					document.body.classList.remove('mobile-keyboard-open');
663 +					requestAnimationFrame(() => requestAnimationFrame(() => {
664 +						const lineBlock = editorView.lineBlockAt(pos);
665 +						const targetScroll = lineBlock.top - (editorView.dom.clientHeight / 2);
666 +						editorView.scrollDOM.scrollTop = Math.max(0, targetScroll);
667 +						editorPane.style.opacity = '';
668 +					}));
669 +				} else {
670 +					document.body.classList.remove('mobile-keyboard-open');
671 +				}
672  			}
673  		}
674