diff --git a/dev-dist/sw.js b/dev-dist/sw.js index 9adc105..fbcb384 100644 --- a/dev-dist/sw.js +++ b/dev-dist/sw.js @@ -85,7 +85,7 @@ define(['./workbox-8cfb3eb5'], (function (workbox) { 'use strict'; "revision": "3ca0b8505b4bec776b69afdba2768812" }, { "url": "index.html", - "revision": "0.8irmmrfvp3g" + "revision": "0.cbp336fi3v8" }], {}); workbox.cleanupOutdatedCaches(); workbox.registerRoute(new workbox.NavigationRoute(workbox.createHandlerBoundToURL("index.html"), { diff --git a/src/components/notes/NoteItem.tsx b/src/components/notes/NoteItem.tsx index 01fedb5..6d04046 100644 --- a/src/components/notes/NoteItem.tsx +++ b/src/components/notes/NoteItem.tsx @@ -59,6 +59,7 @@ export const NoteItem: React.FC = ({ const imageInputRef = useRef(null); const fileInputRef = useRef(null); const textNoteRef = useRef(null); + const shouldSetCursorToEndRef = useRef(false); const searchQuery = useAppSelector((state) => state.notes.searchQuery); const isPreviewMode = useAppSelector((state) => state.ui.isPreviewMode); const aiEnabled = useAppSelector((state) => state.profile.aiEnabled); @@ -77,6 +78,7 @@ export const NoteItem: React.FC = ({ setShowFloatingToolbar(false); setActiveFormats({ bold: false, italic: false, strikethrough: false }); setLocalPreviewMode(false); + shouldSetCursorToEndRef.current = true; // Устанавливаем флаг для установки курсора в конец }; const toggleLocalPreviewMode = () => { @@ -760,15 +762,20 @@ export const NoteItem: React.FC = ({ useEffect(() => { if (isEditing && editTextareaRef.current && !localPreviewMode) { setTimeout(() => { - editTextareaRef.current?.focus(); - // Устанавливаем курсор в конец текста const textarea = editTextareaRef.current; if (textarea) { - textarea.setSelectionRange(editContent.length, editContent.length); + textarea.focus(); + // Устанавливаем курсор в конец текста только при первом входе в режим редактирования + if (shouldSetCursorToEndRef.current) { + // Используем актуальное значение из textarea, а не из состояния + const contentLength = textarea.value.length; + textarea.setSelectionRange(contentLength, contentLength); + shouldSetCursorToEndRef.current = false; // Сбрасываем флаг после установки + } } }, 100); } - }, [isEditing, localPreviewMode, editContent]); + }, [isEditing, localPreviewMode]); // Убрали все зависимости от editContent // Отслеживание выделения текста useEffect(() => {