fix(workspace): ensure immediate cursor autofocus and select on note title creation
MindSift CI & Docker Release / Build, Test in Container & Push (push) Failing after 19s
MindSift CI & Docker Release / Build, Test in Container & Push (push) Failing after 19s
This commit is contained in:
1 parent
ffa14b01a2
commit
5144f7b01b
1 file changed
+20
-11
@@ -165,17 +165,28 @@ export const DocumentEditor: React.FC<DocumentEditorProps> = ({
|
||||
const [showFolderMenu, setShowFolderMenu] = useState<boolean>(false);
|
||||
const [zoomedBlockId, setZoomedBlockId] = useState<string | null>(null);
|
||||
|
||||
const titleInputRef = useRef<HTMLInputElement | null>(null);
|
||||
const titleDebounceRef = useRef<number | null>(null);
|
||||
const docRef = useRef<Document | null>(doc);
|
||||
docRef.current = doc;
|
||||
|
||||
useEffect(() => {
|
||||
if (autoFocusTitle || (doc?.title === 'Neue Notiz' && !doc?.markdownCache)) {
|
||||
const timer = setTimeout(() => {
|
||||
if (!loading && (autoFocusTitle || (doc?.title === 'Neue Notiz' && (!doc?.blocks || doc?.blocks.length <= 1)))) {
|
||||
const focusTitle = () => {
|
||||
if (titleInputRef.current) {
|
||||
titleInputRef.current.focus();
|
||||
titleInputRef.current.select();
|
||||
}
|
||||
}, 60);
|
||||
return () => clearTimeout(timer);
|
||||
};
|
||||
focusTitle();
|
||||
const t1 = setTimeout(focusTitle, 50);
|
||||
const t2 = setTimeout(focusTitle, 150);
|
||||
return () => {
|
||||
clearTimeout(t1);
|
||||
clearTimeout(t2);
|
||||
};
|
||||
}
|
||||
}, [autoFocusTitle]);
|
||||
}, [loading, autoFocusTitle, doc?.id]);
|
||||
|
||||
useEffect(() => {
|
||||
if (zoomedBlockId && !blocks.some((b) => b.id === zoomedBlockId)) {
|
||||
@@ -191,11 +202,6 @@ export const DocumentEditor: React.FC<DocumentEditorProps> = ({
|
||||
return computeBreadcrumbs(title || doc?.title || 'Dokument', blocks, zoomedBlockId);
|
||||
}, [title, doc?.title, blocks, zoomedBlockId]);
|
||||
|
||||
const titleInputRef = useRef<HTMLInputElement | null>(null);
|
||||
const titleDebounceRef = useRef<number | null>(null);
|
||||
const docRef = useRef<Document | null>(doc);
|
||||
docRef.current = doc;
|
||||
|
||||
// Crucial fix: Collaborator with write permission can edit!
|
||||
const canEdit = useMemo(() => {
|
||||
if (!doc) return true;
|
||||
@@ -342,7 +348,9 @@ export const DocumentEditor: React.FC<DocumentEditorProps> = ({
|
||||
// Fetch isolated document state on mount
|
||||
useEffect(() => {
|
||||
let isCancelled = false;
|
||||
setLoading(true);
|
||||
if (!initialDoc) {
|
||||
setLoading(true);
|
||||
}
|
||||
setError(null);
|
||||
|
||||
api
|
||||
@@ -989,6 +997,7 @@ export const DocumentEditor: React.FC<DocumentEditorProps> = ({
|
||||
type="text"
|
||||
value={title}
|
||||
readOnly={!canEdit}
|
||||
autoFocus={autoFocusTitle}
|
||||
onChange={handleTitleChange}
|
||||
onBlur={handleTitleBlur}
|
||||
placeholder="Titel der Notiz…"
|
||||
|
||||
Reference in new issue
Block a user