Skip to content

Commit cf4dc63

Browse files
committed
fix(editor2): unable to change action's doc color when doc is empty
1 parent 8d42d20 commit cf4dc63

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/components/editor2/action/ActionItem.tsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -519,8 +519,11 @@ export const ActionItem: FC<ActionItemProps> = memo(
519519
/>
520520
</div>
521521
</div>
522-
{doc !== undefined && (
523-
<div className="flex items-center bg-gray-200 text-gray-500">
522+
{(doc !== undefined || action.docColor !== undefined) && (
523+
<div
524+
data-doc-section
525+
className="flex items-center bg-gray-200 text-gray-500"
526+
>
524527
<Select
525528
filterable={false}
526529
items={actionDocColors}
@@ -578,7 +581,7 @@ export const ActionItem: FC<ActionItemProps> = memo(
578581
}}
579582
inputRef={setDocInput}
580583
placeholder={t.components.editor2.ActionItem.doc_placeholder}
581-
value={doc}
584+
value={doc ?? ''}
582585
onChange={(e) => {
583586
edit(() => {
584587
setAction((draft) => {
@@ -593,15 +596,18 @@ export const ActionItem: FC<ActionItemProps> = memo(
593596
}}
594597
onBlur={(e) => {
595598
if (e.target.value === '') {
596-
setDocDraft(undefined)
599+
// 如果点击了 data-doc-section 以外的地方,且输入框为空,则删除 doc 和 docColor
600+
if (!e.relatedTarget?.closest('[data-doc-section]')) {
601+
setDocDraft(undefined)
597602

598-
if (action.doc !== undefined) {
599603
edit(() => {
600604
setAction((draft) => {
601-
draft.doc = undefined
605+
delete draft.doc
606+
delete draft.docColor
602607
})
603608
return {
604-
// 这里的 action 要和正常修改时的 action 一致,不然会导致多出一条记录
609+
// 这里的 action 要和正常修改时的 action 一致,因为如果用户手动清空输入框的话已经有了一条记录,
610+
// 这里不一致的话还会多出一条额外的记录
605611
action: 'set-action-doc',
606612
desc: i18n.actions.editor2.delete_action_doc,
607613
squashBy: action.id,

0 commit comments

Comments
 (0)