fix: clarify text edit requires actual changes
This commit is contained in:
parent
edcbddb0fa
commit
1cf4cf3ac0
@ -204,6 +204,20 @@ export function AgentImageTextEditDialog({
|
|||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const hasTextEditChanges = useMemo(
|
||||||
|
() =>
|
||||||
|
textEditItems.some((item) => {
|
||||||
|
const originalText = item.originalText.trim();
|
||||||
|
const editedText = item.editedText.trim();
|
||||||
|
return (
|
||||||
|
originalText.length > 0 &&
|
||||||
|
(editedText.length === 0 || editedText !== originalText)
|
||||||
|
);
|
||||||
|
}) ||
|
||||||
|
deletedTextItems.some((item) => item.originalText.trim().length > 0),
|
||||||
|
[deletedTextItems, textEditItems]
|
||||||
|
);
|
||||||
|
|
||||||
const handleGenerateSuggestions = useCallback(
|
const handleGenerateSuggestions = useCallback(
|
||||||
async (item: AgentImageTextEditItem) => {
|
async (item: AgentImageTextEditItem) => {
|
||||||
if (!normalizedImageUrl) {
|
if (!normalizedImageUrl) {
|
||||||
@ -324,7 +338,7 @@ export function AgentImageTextEditDialog({
|
|||||||
|
|
||||||
const requestItems = [...changedItems, ...removedItems];
|
const requestItems = [...changedItems, ...removedItems];
|
||||||
if (requestItems.length === 0) {
|
if (requestItems.length === 0) {
|
||||||
toast.info("请先修改或删除至少一段文字");
|
toast.info("请先把要替换的文字改成新文案,或点击垃圾桶删除该文字");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -548,7 +562,7 @@ export function AgentImageTextEditDialog({
|
|||||||
disabled={
|
disabled={
|
||||||
isDetectingText ||
|
isDetectingText ||
|
||||||
isApplyingTextEdit ||
|
isApplyingTextEdit ||
|
||||||
(textEditItems.length === 0 && deletedTextItems.length === 0)
|
!hasTextEditChanges
|
||||||
}
|
}
|
||||||
onClick={() => void handleApplyTextEdit()}
|
onClick={() => void handleApplyTextEdit()}
|
||||||
>
|
>
|
||||||
@ -557,7 +571,7 @@ export function AgentImageTextEditDialog({
|
|||||||
) : (
|
) : (
|
||||||
<Type className="mr-2 h-4 w-4" />
|
<Type className="mr-2 h-4 w-4" />
|
||||||
)}
|
)}
|
||||||
确定生图
|
{hasTextEditChanges ? "确定生图" : "先修改文字"}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -4878,6 +4878,20 @@ export function ImageNode({
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const hasTextEditChanges = useMemo(
|
||||||
|
() =>
|
||||||
|
textEditItems.some((item) => {
|
||||||
|
const originalText = item.originalText.trim();
|
||||||
|
const editedText = item.editedText.trim();
|
||||||
|
return (
|
||||||
|
originalText.length > 0 &&
|
||||||
|
(editedText.length === 0 || editedText !== originalText)
|
||||||
|
);
|
||||||
|
}) ||
|
||||||
|
deletedTextItems.some((item) => item.originalText.trim().length > 0),
|
||||||
|
[deletedTextItems, textEditItems]
|
||||||
|
);
|
||||||
|
|
||||||
const handleApplyTextEdit = useCallback(async () => {
|
const handleApplyTextEdit = useCallback(async () => {
|
||||||
if (!data.src) {
|
if (!data.src) {
|
||||||
toast.error("请先上传图片");
|
toast.error("请先上传图片");
|
||||||
@ -4921,7 +4935,7 @@ export function ImageNode({
|
|||||||
const requestItems = [...changedItems, ...removedItems];
|
const requestItems = [...changedItems, ...removedItems];
|
||||||
|
|
||||||
if (requestItems.length === 0) {
|
if (requestItems.length === 0) {
|
||||||
toast.info("请先修改或删除至少一段文字");
|
toast.info("请先把要替换的文字改成新文案,或点击垃圾桶删除该文字");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -9369,7 +9383,7 @@ export function ImageNode({
|
|||||||
disabled={
|
disabled={
|
||||||
isDetectingText ||
|
isDetectingText ||
|
||||||
isApplyingTextEdit ||
|
isApplyingTextEdit ||
|
||||||
(textEditItems.length === 0 && deletedTextItems.length === 0)
|
!hasTextEditChanges
|
||||||
}
|
}
|
||||||
onClick={handleApplyTextEdit}
|
onClick={handleApplyTextEdit}
|
||||||
size="sm"
|
size="sm"
|
||||||
@ -9379,7 +9393,7 @@ export function ImageNode({
|
|||||||
) : (
|
) : (
|
||||||
<Check className="mr-1 h-3.5 w-3.5" />
|
<Check className="mr-1 h-3.5 w-3.5" />
|
||||||
)}
|
)}
|
||||||
确认替换
|
{hasTextEditChanges ? "确认替换" : "先修改文字"}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>,
|
</div>,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user