mirror of
https://github.com/zadam/trilium.git
synced 2025-10-21 23:59:02 +02:00
feat(collections/board): restore focus
This commit is contained in:
parent
d845343e97
commit
f2e60f52d2
@ -63,7 +63,7 @@ export default function Card({
|
|||||||
setBranchIdToEdit?.(branch.branchId);
|
setBranchIdToEdit?.(branch.branchId);
|
||||||
}, [ setBranchIdToEdit, branch ]);
|
}, [ setBranchIdToEdit, branch ]);
|
||||||
|
|
||||||
const handleKeyUp = useCallback((e: KeyboardEvent) => {
|
const handleKeyDown = useCallback((e: KeyboardEvent) => {
|
||||||
if (e.key === "Enter") {
|
if (e.key === "Enter") {
|
||||||
api.openNote(note.noteId);
|
api.openNote(note.noteId);
|
||||||
} else if (e.key === "F2") {
|
} else if (e.key === "F2") {
|
||||||
@ -91,7 +91,7 @@ export default function Card({
|
|||||||
onDragEnd={handleDragEnd}
|
onDragEnd={handleDragEnd}
|
||||||
onContextMenu={handleContextMenu}
|
onContextMenu={handleContextMenu}
|
||||||
onClick={!isEditing ? handleOpen : undefined}
|
onClick={!isEditing ? handleOpen : undefined}
|
||||||
onKeyUp={handleKeyUp}
|
onKeyDown={handleKeyDown}
|
||||||
style={{
|
style={{
|
||||||
display: !isVisible ? "none" : undefined
|
display: !isVisible ? "none" : undefined
|
||||||
}}
|
}}
|
||||||
|
@ -227,10 +227,12 @@ export function TitleEditor({ currentValue, placeholder, save, dismiss, multilin
|
|||||||
isNewItem?: boolean;
|
isNewItem?: boolean;
|
||||||
}) {
|
}) {
|
||||||
const inputRef = useRef<any>(null);
|
const inputRef = useRef<any>(null);
|
||||||
|
const focusElRef = useRef<Element>(null);
|
||||||
const dismissOnNextRefreshRef = useRef(false);
|
const dismissOnNextRefreshRef = useRef(false);
|
||||||
const shouldDismiss = useRef(false);
|
const shouldDismiss = useRef(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
focusElRef.current = document.activeElement;
|
||||||
inputRef.current?.focus();
|
inputRef.current?.focus();
|
||||||
inputRef.current?.select();
|
inputRef.current?.select();
|
||||||
}, [ inputRef ]);
|
}, [ inputRef ]);
|
||||||
@ -254,8 +256,11 @@ export function TitleEditor({ currentValue, placeholder, save, dismiss, multilin
|
|||||||
onKeyDown={(e: TargetedKeyboardEvent<HTMLInputElement | HTMLTextAreaElement>) => {
|
onKeyDown={(e: TargetedKeyboardEvent<HTMLInputElement | HTMLTextAreaElement>) => {
|
||||||
if (e.key === "Enter" || e.key === "Escape") {
|
if (e.key === "Enter" || e.key === "Escape") {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
shouldDismiss.current = (e.key === "Escape");
|
shouldDismiss.current = (e.key === "Escape");
|
||||||
e.currentTarget.blur();
|
if (focusElRef.current instanceof HTMLElement) {
|
||||||
|
focusElRef.current.focus();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
onBlur={(newValue) => {
|
onBlur={(newValue) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user