mirror of
https://github.com/zadam/trilium.git
synced 2025-11-16 18:25:51 +01:00
chore(react/collections/table): slightly improve editing experience
This commit is contained in:
@@ -375,6 +375,7 @@ function Card({
|
|||||||
const { branchIdToEdit } = useContext(BoardViewContext);
|
const { branchIdToEdit } = useContext(BoardViewContext);
|
||||||
const isEditing = branch.branchId === branchIdToEdit;
|
const isEditing = branch.branchId === branchIdToEdit;
|
||||||
const colorClass = note.getColorClass() || '';
|
const colorClass = note.getColorClass() || '';
|
||||||
|
const editorRef = useRef<HTMLInputElement>(null);
|
||||||
|
|
||||||
const handleDragStart = useCallback((e: DragEvent) => {
|
const handleDragStart = useCallback((e: DragEvent) => {
|
||||||
e.dataTransfer!.effectAllowed = 'move';
|
e.dataTransfer!.effectAllowed = 'move';
|
||||||
@@ -390,6 +391,10 @@ function Card({
|
|||||||
openNoteContextMenu(api, e, note.noteId, branch.branchId, column);
|
openNoteContextMenu(api, e, note.noteId, branch.branchId, column);
|
||||||
}, [ api, note, branch, column ]);
|
}, [ api, note, branch, column ]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
editorRef.current?.focus();
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={`board-note ${colorClass} ${isDragging ? 'dragging' : ''} ${isEditing ? "editing" : ""}`}
|
className={`board-note ${colorClass} ${isDragging ? 'dragging' : ''} ${isEditing ? "editing" : ""}`}
|
||||||
@@ -403,10 +408,14 @@ function Card({
|
|||||||
<>{note.title}</>
|
<>{note.title}</>
|
||||||
) : (
|
) : (
|
||||||
<FormTextBox
|
<FormTextBox
|
||||||
|
inputRef={editorRef}
|
||||||
value={note.title}
|
value={note.title}
|
||||||
onKeyDown={(e) => {
|
onKeyDown={(e) => {
|
||||||
if (e.key === "Enter") {
|
if (e.key === "Enter") {
|
||||||
api.renameCard(note.noteId, e.currentTarget.value);
|
const newTitle = e.currentTarget.value;
|
||||||
|
if (newTitle !== note.title) {
|
||||||
|
api.renameCard(note.noteId, newTitle);
|
||||||
|
}
|
||||||
api.dismissEditingTitle();
|
api.dismissEditingTitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -414,6 +423,12 @@ function Card({
|
|||||||
api.dismissEditingTitle();
|
api.dismissEditingTitle();
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
onBlur={(newTitle) => {
|
||||||
|
if (newTitle !== note.title) {
|
||||||
|
api.renameCard(note.noteId, newTitle);
|
||||||
|
}
|
||||||
|
api.dismissEditingTitle();
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user