Обновлен компонент NoteItem для улучшения пользовательского опыта редактирования заметок. Добавлен флаг для установки курсора в конец текста при входе в режим редактирования. Упрощены зависимости в useEffect для повышения производительности.
This commit is contained in:
parent
7de8872f40
commit
2ec0fd4496
@ -85,7 +85,7 @@ define(['./workbox-8cfb3eb5'], (function (workbox) { 'use strict';
|
|||||||
"revision": "3ca0b8505b4bec776b69afdba2768812"
|
"revision": "3ca0b8505b4bec776b69afdba2768812"
|
||||||
}, {
|
}, {
|
||||||
"url": "index.html",
|
"url": "index.html",
|
||||||
"revision": "0.8irmmrfvp3g"
|
"revision": "0.cbp336fi3v8"
|
||||||
}], {});
|
}], {});
|
||||||
workbox.cleanupOutdatedCaches();
|
workbox.cleanupOutdatedCaches();
|
||||||
workbox.registerRoute(new workbox.NavigationRoute(workbox.createHandlerBoundToURL("index.html"), {
|
workbox.registerRoute(new workbox.NavigationRoute(workbox.createHandlerBoundToURL("index.html"), {
|
||||||
|
|||||||
@ -59,6 +59,7 @@ export const NoteItem: React.FC<NoteItemProps> = ({
|
|||||||
const imageInputRef = useRef<HTMLInputElement>(null);
|
const imageInputRef = useRef<HTMLInputElement>(null);
|
||||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||||
const textNoteRef = useRef<HTMLDivElement>(null);
|
const textNoteRef = useRef<HTMLDivElement>(null);
|
||||||
|
const shouldSetCursorToEndRef = useRef(false);
|
||||||
const searchQuery = useAppSelector((state) => state.notes.searchQuery);
|
const searchQuery = useAppSelector((state) => state.notes.searchQuery);
|
||||||
const isPreviewMode = useAppSelector((state) => state.ui.isPreviewMode);
|
const isPreviewMode = useAppSelector((state) => state.ui.isPreviewMode);
|
||||||
const aiEnabled = useAppSelector((state) => state.profile.aiEnabled);
|
const aiEnabled = useAppSelector((state) => state.profile.aiEnabled);
|
||||||
@ -77,6 +78,7 @@ export const NoteItem: React.FC<NoteItemProps> = ({
|
|||||||
setShowFloatingToolbar(false);
|
setShowFloatingToolbar(false);
|
||||||
setActiveFormats({ bold: false, italic: false, strikethrough: false });
|
setActiveFormats({ bold: false, italic: false, strikethrough: false });
|
||||||
setLocalPreviewMode(false);
|
setLocalPreviewMode(false);
|
||||||
|
shouldSetCursorToEndRef.current = true; // Устанавливаем флаг для установки курсора в конец
|
||||||
};
|
};
|
||||||
|
|
||||||
const toggleLocalPreviewMode = () => {
|
const toggleLocalPreviewMode = () => {
|
||||||
@ -760,15 +762,20 @@ export const NoteItem: React.FC<NoteItemProps> = ({
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isEditing && editTextareaRef.current && !localPreviewMode) {
|
if (isEditing && editTextareaRef.current && !localPreviewMode) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
editTextareaRef.current?.focus();
|
|
||||||
// Устанавливаем курсор в конец текста
|
|
||||||
const textarea = editTextareaRef.current;
|
const textarea = editTextareaRef.current;
|
||||||
if (textarea) {
|
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);
|
}, 100);
|
||||||
}
|
}
|
||||||
}, [isEditing, localPreviewMode, editContent]);
|
}, [isEditing, localPreviewMode]); // Убрали все зависимости от editContent
|
||||||
|
|
||||||
// Отслеживание выделения текста
|
// Отслеживание выделения текста
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user