mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-30 18:05:55 +01:00 
			
		
		
		
	fix(react/dialogs): recent notes not triggered in autocomplete
This commit is contained in:
		| @@ -452,6 +452,21 @@ function init() { | |||||||
|     }; |     }; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * Convenience function which triggers the display of recent notes in the autocomplete input and focuses it. | ||||||
|  |  * | ||||||
|  |  * @param inputElement - The input element to trigger recent notes on. | ||||||
|  |  */ | ||||||
|  | export function triggerRecentNotes(inputElement: HTMLInputElement | null | undefined) { | ||||||
|  |     if (!inputElement) { | ||||||
|  |         return; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     const $el = $(inputElement); | ||||||
|  |     showRecentNotes($el); | ||||||
|  |     $el.trigger("focus").trigger("select"); | ||||||
|  | } | ||||||
|  |  | ||||||
| export default { | export default { | ||||||
|     autocompleteSourceForCKEditor, |     autocompleteSourceForCKEditor, | ||||||
|     initNoteAutocomplete, |     initNoteAutocomplete, | ||||||
|   | |||||||
| @@ -9,7 +9,7 @@ import froca from "../../services/froca"; | |||||||
| import FormGroup from "../react/FormGroup"; | import FormGroup from "../react/FormGroup"; | ||||||
| import FormTextBox from "../react/FormTextBox"; | import FormTextBox from "../react/FormTextBox"; | ||||||
| import Button from "../react/Button"; | import Button from "../react/Button"; | ||||||
| import note_autocomplete, { Suggestion } from "../../services/note_autocomplete"; | import { Suggestion, triggerRecentNotes } from "../../services/note_autocomplete"; | ||||||
| import { logError } from "../../services/ws"; | import { logError } from "../../services/ws"; | ||||||
| import tree from "../../services/tree"; | import tree from "../../services/tree"; | ||||||
| import branches from "../../services/branches"; | import branches from "../../services/branches"; | ||||||
| @@ -44,10 +44,7 @@ function CloneToDialogComponent({ clonedNoteIds }: CloneToDialogProps) { | |||||||
|             size="lg" |             size="lg" | ||||||
|             footer={<Button text={t("clone_to.clone_to_selected_note")} keyboardShortcut="Enter" />} |             footer={<Button text={t("clone_to.clone_to_selected_note")} keyboardShortcut="Enter" />} | ||||||
|             onSubmit={onSubmit} |             onSubmit={onSubmit} | ||||||
|             onShown={() => { |             onShown={() => triggerRecentNotes(autoCompleteRef.current)} | ||||||
|                 autoCompleteRef.current?.focus(); |  | ||||||
|                 note_autocomplete.showRecentNotes($(autoCompleteRef.current)); |  | ||||||
|             }} |  | ||||||
|         > |         > | ||||||
|             <h5>{t("clone_to.notes_to_clone")}</h5> |             <h5>{t("clone_to.notes_to_clone")}</h5> | ||||||
|             <NoteList style={{ maxHeight: "200px", overflow: "auto" }} noteIds={clonedNoteIds} /> |             <NoteList style={{ maxHeight: "200px", overflow: "auto" }} noteIds={clonedNoteIds} /> | ||||||
|   | |||||||
| @@ -8,7 +8,7 @@ import Modal from "../react/Modal"; | |||||||
| import NoteAutocomplete from "../react/NoteAutocomplete"; | import NoteAutocomplete from "../react/NoteAutocomplete"; | ||||||
| import ReactBasicWidget from "../react/ReactBasicWidget"; | import ReactBasicWidget from "../react/ReactBasicWidget"; | ||||||
| import Button from "../react/Button"; | import Button from "../react/Button"; | ||||||
| import note_autocomplete, { Suggestion } from "../../services/note_autocomplete"; | import { Suggestion, triggerRecentNotes } from "../../services/note_autocomplete"; | ||||||
| import tree from "../../services/tree"; | import tree from "../../services/tree"; | ||||||
| import froca from "../../services/froca"; | import froca from "../../services/froca"; | ||||||
| import EditableTextTypeWidget from "../type_widgets/editable_text"; | import EditableTextTypeWidget from "../type_widgets/editable_text"; | ||||||
| @@ -20,17 +20,14 @@ interface IncludeNoteDialogProps { | |||||||
| function IncludeNoteDialogComponent({ textTypeWidget }: IncludeNoteDialogProps) { | function IncludeNoteDialogComponent({ textTypeWidget }: IncludeNoteDialogProps) { | ||||||
|     const [suggestion, setSuggestion] = useState<Suggestion | null>(null); |     const [suggestion, setSuggestion] = useState<Suggestion | null>(null); | ||||||
|     const [boxSize, setBoxSize] = useState("medium"); |     const [boxSize, setBoxSize] = useState("medium"); | ||||||
|     const inputRef = useRef<HTMLInputElement>(null); |     const autoCompleteRef = useRef<HTMLInputElement>(null); | ||||||
|  |  | ||||||
|     return (textTypeWidget && |     return (textTypeWidget && | ||||||
|         <Modal |         <Modal | ||||||
|             className="include-note-dialog" |             className="include-note-dialog" | ||||||
|             title={t("include_note.dialog_title")} |             title={t("include_note.dialog_title")} | ||||||
|             size="lg" |             size="lg" | ||||||
|             onShown={() => { |             onShown={() => triggerRecentNotes(autoCompleteRef.current)} | ||||||
|                 inputRef.current?.focus(); |  | ||||||
|                 note_autocomplete.showRecentNotes($(inputRef.current!)); |  | ||||||
|             }} |  | ||||||
|             onSubmit={() => { |             onSubmit={() => { | ||||||
|                 if (!suggestion?.notePath) { |                 if (!suggestion?.notePath) { | ||||||
|                     return; |                     return; | ||||||
| @@ -47,7 +44,7 @@ function IncludeNoteDialogComponent({ textTypeWidget }: IncludeNoteDialogProps) | |||||||
|                 <NoteAutocomplete |                 <NoteAutocomplete | ||||||
|                     placeholder={t("include_note.placeholder_search")} |                     placeholder={t("include_note.placeholder_search")} | ||||||
|                     onChange={setSuggestion} |                     onChange={setSuggestion} | ||||||
|                     inputRef={inputRef} |                     inputRef={autoCompleteRef} | ||||||
|                 /> |                 /> | ||||||
|             </FormGroup> |             </FormGroup> | ||||||
|  |  | ||||||
|   | |||||||
| @@ -8,7 +8,7 @@ import FormGroup from "../react/FormGroup"; | |||||||
| import NoteAutocomplete from "../react/NoteAutocomplete"; | import NoteAutocomplete from "../react/NoteAutocomplete"; | ||||||
| import Button from "../react/Button"; | import Button from "../react/Button"; | ||||||
| import { useRef, useState } from "preact/compat"; | import { useRef, useState } from "preact/compat"; | ||||||
| import note_autocomplete, { Suggestion } from "../../services/note_autocomplete"; | import { Suggestion, triggerRecentNotes } from "../../services/note_autocomplete"; | ||||||
| import tree from "../../services/tree"; | import tree from "../../services/tree"; | ||||||
| import froca from "../../services/froca"; | import froca from "../../services/froca"; | ||||||
| import branches from "../../services/branches"; | import branches from "../../services/branches"; | ||||||
| @@ -48,10 +48,7 @@ function MoveToDialogComponent({ movedBranchIds }: MoveToDialogProps) { | |||||||
|             title={t("move_to.dialog_title")} |             title={t("move_to.dialog_title")} | ||||||
|             footer={<Button text={t("move_to.move_button")} keyboardShortcut="Enter" />} |             footer={<Button text={t("move_to.move_button")} keyboardShortcut="Enter" />} | ||||||
|             onSubmit={onSubmit} |             onSubmit={onSubmit} | ||||||
|             onShown={() => { |             onShown={() => triggerRecentNotes(autoCompleteRef.current)} | ||||||
|                 autoCompleteRef.current?.focus(); |  | ||||||
|                 note_autocomplete.showRecentNotes($(autoCompleteRef.current)); |  | ||||||
|             }} |  | ||||||
|         > |         > | ||||||
|             <h5>{t("move_to.notes_to_move")}</h5> |             <h5>{t("move_to.notes_to_move")}</h5> | ||||||
|             <NoteList branchIds={movedBranchIds} /> |             <NoteList branchIds={movedBranchIds} /> | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user