From: PhiTux Date: Thu, 2 Oct 2025 15:11:11 +0000 (+0200) Subject: fixed double-GET & change editor focus on mobile X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=eacff807f2f242b92dd84b31373fcfa00f2c50ae;p=DailyTxT.git fixed double-GET & change editor focus on mobile --- diff --git a/frontend/src/routes/(authed)/write/+page.svelte b/frontend/src/routes/(authed)/write/+page.svelte index 9fd93e5..6458773 100644 --- a/frontend/src/routes/(authed)/write/+page.svelte +++ b/frontend/src/routes/(authed)/write/+page.svelte @@ -49,6 +49,7 @@ let cancelDownload = new AbortController(); let tinyMDE; + let isMobile = false; onMount(() => { // If we come from read mode, keep the last visible day as the active selected day if ($readingDate) { @@ -56,6 +57,12 @@ } $readingDate = null; // no reading-highlighting when in write mode + // Detect mobile (simple heuristic: viewport width OR user agent) + isMobile = + typeof window !== 'undefined' && + (window.matchMedia('(max-width: 768px)').matches || + /Mobi|Android/i.test(navigator.userAgent)); + tinyMDE = new TinyMDE.Editor({ element: 'editor', content: '' }); let commandBar = new TinyMDE.CommandBar({ element: 'toolbar', editor: tinyMDE }); document.getElementsByClassName('TinyMDE')[0].classList.add('focus-ring'); @@ -247,8 +254,19 @@ savedLog = currentLog; + // Update editor content tinyMDE.setContent(currentLog); - tinyMDE.setSelection({ row: 0, col: 0 }); + // Only auto-focus/select on non-mobile devices + if (!isMobile) { + try { + tinyMDE.setSelection({ row: 0, col: 0 }); + // Ensure the underlying editable div gets focus + const editorEl = document.querySelector( + '#editor .TinyMDE textarea, #editor .TinyMDE [contenteditable="true"]' + ); + if (editorEl) editorEl.focus(); + } catch {} + } logDateWritten = response.data.date_written; @@ -292,9 +310,11 @@ } // Re-trigger aLookBack when settings are loaded/changed + let initial_aLookBack = $state(false); $effect(() => { - if ($settings && $settings.useALookBack !== undefined) { + if (!initial_aLookBack && $settings && $settings.useALookBack) { getALookBack(); + initial_aLookBack = true; } });