diff --git a/web/src/components/Settings/TagRecommendationSection.tsx b/web/src/components/Settings/TagRecommendationSection.tsx index fc802eb93..10f9ad122 100644 --- a/web/src/components/Settings/TagRecommendationSection.tsx +++ b/web/src/components/Settings/TagRecommendationSection.tsx @@ -36,6 +36,7 @@ const TagRecommendationSection = observer(({ aiSetting, onSettingChange, disable ); const [tagConfig, setTagConfig] = useState(originalTagConfig); const [defaultPrompt, setDefaultPrompt] = useState(""); + const [hasAutoFilledDefault, setHasAutoFilledDefault] = useState(false); // Sync local state when aiSetting changes useEffect(() => { @@ -49,6 +50,8 @@ const TagRecommendationSection = observer(({ aiSetting, onSettingChange, disable setOriginalTagConfig(newTagConfig); setTagConfig(newTagConfig); + // Reset auto-fill state when aiSetting changes + setHasAutoFilledDefault(false); }, [aiSetting]); // Fetch default system prompt on component mount @@ -93,6 +96,28 @@ const TagRecommendationSection = observer(({ aiSetting, onSettingChange, disable const updateTagConfig = (partial: Partial) => { setTagConfig(WorkspaceSetting_TagRecommendationConfig.fromPartial({ ...tagConfig, ...partial })); + + // Reset auto-fill state when user manually changes the content + if (partial.systemPrompt !== undefined && partial.systemPrompt.trim() === "") { + setHasAutoFilledDefault(false); + } + }; + + const handleTextareaFocus = async (e: React.FocusEvent) => { + // Only auto-fill if the textarea is empty and we haven't already auto-filled + if (!tagConfig.systemPrompt.trim() && !hasAutoFilledDefault && defaultPrompt) { + // Set the default prompt + updateTagConfig({ systemPrompt: defaultPrompt }); + setHasAutoFilledDefault(true); + + // Move cursor to the end after the content is set + setTimeout(() => { + const textarea = e.target; + const length = defaultPrompt.length; + textarea.setSelectionRange(length, length); + textarea.focus(); + }, 0); + } }; const saveTagConfig = async () => { @@ -153,10 +178,11 @@ const TagRecommendationSection = observer(({ aiSetting, onSettingChange, disable