From: PhiTux Date: Wed, 22 Oct 2025 14:22:28 +0000 (+0200) Subject: cursor is placed on end of entry when date is selected X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=3221ef4628889550c4bc21d5788548a99524943f;p=DailyTxT.git cursor is placed on end of entry when date is selected --- diff --git a/frontend/src/routes/(authed)/write/+page.svelte b/frontend/src/routes/(authed)/write/+page.svelte index 9d3f1ec..f9298c5 100644 --- a/frontend/src/routes/(authed)/write/+page.svelte +++ b/frontend/src/routes/(authed)/write/+page.svelte @@ -284,15 +284,28 @@ // Update editor content tinyMDE.setContent(currentLog); - // Only auto-focus/select on non-mobile devices + // Only auto-focus and place caret at end on non-mobile devices if (!isMobile) { try { - tinyMDE.setSelection({ row: 0, col: 0 }); - // Ensure the underlying editable div gets focus + const content = + typeof tinyMDE.getContent === 'function' ? tinyMDE.getContent() : currentLog || ''; + const text = typeof content === 'string' ? content : currentLog || ''; + const lines = text.split('\n'); + const lastRow = Math.max(0, lines.length - 1); + const lastCol = (lines[lastRow] && lines[lastRow].length) || 0; + + // Focus the underlying editable element first const editorEl = document.querySelector( '#editor .TinyMDE textarea, #editor .TinyMDE [contenteditable="true"]' ); if (editorEl) editorEl.focus(); + + // Then set the selection at the end on the next frame + requestAnimationFrame(() => { + try { + tinyMDE.setSelection({ row: lastRow, col: lastCol }); + } catch {} + }); } catch {} }