Skip to content

Commit 8ec8fc5

Browse files
committed
refactor(editor2): better history management
1 parent 2ae148c commit 8ec8fc5

File tree

13 files changed

+137
-113
lines changed

13 files changed

+137
-113
lines changed

src/components/editor2/EditorToolbar.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ const AutoSaveButton = () => {
179179
return {
180180
action: 'restore',
181181
desc: i18n.actions.editor2.restore_from_autosave,
182-
squash: false,
183182
}
184183
})
185184
}}

src/components/editor2/InfoEditor.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export const InfoEditor = memo(({ className }: InfoEditorProps) => {
5858
return {
5959
action: 'update-title',
6060
desc: i18n.actions.editor2.set_title,
61-
squash: true,
61+
squashBy: '',
6262
}
6363
})
6464
}}
@@ -83,7 +83,7 @@ export const InfoEditor = memo(({ className }: InfoEditorProps) => {
8383
return {
8484
action: 'update-details',
8585
desc: i18n.actions.editor2.set_description,
86-
squash: true,
86+
squashBy: '',
8787
}
8888
})
8989
}}
@@ -106,7 +106,6 @@ export const InfoEditor = memo(({ className }: InfoEditorProps) => {
106106
return {
107107
action: 'update-level',
108108
desc: i18n.actions.editor2.set_level,
109-
squash: false,
110109
}
111110
})
112111
}}
@@ -131,7 +130,6 @@ export const InfoEditor = memo(({ className }: InfoEditorProps) => {
131130
return {
132131
action: 'update-difficulty',
133132
desc: i18n.actions.editor2.set_difficulty,
134-
squash: false,
135133
}
136134
})
137135
}}
@@ -154,7 +152,7 @@ export const InfoEditor = memo(({ className }: InfoEditorProps) => {
154152
return {
155153
action: 'update-visibility',
156154
desc: i18n.actions.editor2.set_visibility,
157-
squash: true,
155+
squashBy: '',
158156
}
159157
})
160158
}}

src/components/editor2/action/ActionEditor.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ export const ActionEditor: FC<ActionEditorProps> = ({ className }) => {
6868
return {
6969
action: 'move-action',
7070
desc: i18n.components.editor2.ActionEditor.move_action,
71-
squash: false,
7271
}
7372
})
7473
}

src/components/editor2/action/ActionItem.tsx

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,9 @@ export const ActionItem: FC<ActionItemProps> = memo(
211211
draft.location = [v, draft.location?.[1] ?? 0]
212212
})
213213
return {
214-
action: 'set-action-location-x-' + action.id,
214+
action: 'set-action-location-x',
215215
desc: i18n.actions.editor2.set_action_location,
216-
squash: true,
216+
squashBy: action.id,
217217
}
218218
})
219219
}}
@@ -237,9 +237,9 @@ export const ActionItem: FC<ActionItemProps> = memo(
237237
draft.location = [draft.location?.[0] ?? 0, v]
238238
})
239239
return {
240-
action: 'set-action-location-y-' + action.id,
240+
action: 'set-action-location-y',
241241
desc: i18n.actions.editor2.set_action_location,
242-
squash: true,
242+
squashBy: action.id,
243243
}
244244
})
245245
}}
@@ -283,9 +283,9 @@ export const ActionItem: FC<ActionItemProps> = memo(
283283
draft.distance = [v, draft.distance?.[1] ?? 0]
284284
})
285285
return {
286-
action: 'set-action-distance-x-' + action.id,
286+
action: 'set-action-distance-x',
287287
desc: i18n.actions.editor2.set_action_distance,
288-
squash: true,
288+
squashBy: action.id,
289289
}
290290
})
291291
}}
@@ -309,9 +309,9 @@ export const ActionItem: FC<ActionItemProps> = memo(
309309
draft.distance = [draft.distance?.[0] ?? 0, v]
310310
})
311311
return {
312-
action: 'set-action-distance-y-' + action.id,
312+
action: 'set-action-distance-y',
313313
desc: i18n.actions.editor2.set_action_distance,
314-
squash: true,
314+
squashBy: action.id,
315315
}
316316
})
317317
}}
@@ -354,9 +354,8 @@ export const ActionItem: FC<ActionItemProps> = memo(
354354
draft.direction = dir
355355
})
356356
return {
357-
action: 'set-action-direction-' + action.id,
357+
action: 'set-action-direction',
358358
desc: i18n.actions.editor2.set_action_direction,
359-
squash: false,
360359
}
361360
})
362361
}}
@@ -422,12 +421,10 @@ export const ActionItem: FC<ActionItemProps> = memo(
422421
draft.skillTimes = v
423422
})
424423
return {
425-
action:
426-
'set-action-skillTimes-' +
427-
action.id,
424+
action: 'set-action-skillTimes',
428425
desc: i18n.actions.editor2
429426
.set_action_skill_times,
430-
squash: true,
427+
squashBy: action.id,
431428
}
432429
})
433430
}}
@@ -445,10 +442,9 @@ export const ActionItem: FC<ActionItemProps> = memo(
445442
draft.skillUsage = item.value as number
446443
})
447444
return {
448-
action: 'set-action-skillUsage-' + action.id,
445+
action: 'set-action-skillUsage',
449446
desc: i18n.actions.editor2
450447
.set_action_skill_usage,
451-
squash: false,
452448
}
453449
})
454450
}}
@@ -503,9 +499,8 @@ export const ActionItem: FC<ActionItemProps> = memo(
503499
before: actionAtom,
504500
})
505501
return {
506-
action: 'copy-action-' + action.id,
502+
action: 'duplicate-action',
507503
desc: i18n.actions.editor2.duplicate_action,
508-
squash: false,
509504
}
510505
})
511506
}}
@@ -523,9 +518,8 @@ export const ActionItem: FC<ActionItemProps> = memo(
523518
atom: actionAtom,
524519
})
525520
return {
526-
action: 'delete-action-' + action.id,
521+
action: 'delete-action',
527522
desc: i18n.actions.editor2.delete_action,
528-
squash: false,
529523
}
530524
})
531525
}}
@@ -566,9 +560,8 @@ export const ActionItem: FC<ActionItemProps> = memo(
566560
draft.docColor = item.value
567561
})
568562
return {
569-
action: 'set-action-docColor-' + action.id,
563+
action: 'set-action-docColor',
570564
desc: i18n.actions.editor2.set_action_doc_color,
571-
squash: false,
572565
}
573566
})
574567
}}
@@ -599,9 +592,9 @@ export const ActionItem: FC<ActionItemProps> = memo(
599592
draft.doc = e.target.value
600593
})
601594
return {
602-
action: 'set-action-doc-' + action.id,
595+
action: 'set-action-doc',
603596
desc: i18n.actions.editor2.set_action_doc,
604-
squash: true,
597+
squashBy: action.id,
605598
}
606599
})
607600
}}
@@ -616,9 +609,9 @@ export const ActionItem: FC<ActionItemProps> = memo(
616609
})
617610
return {
618611
// 这里的 action 要和正常修改时的 action 一致,不然会导致多出一条记录
619-
action: 'set-action-doc-' + action.id,
612+
action: 'set-action-doc',
620613
desc: i18n.actions.editor2.delete_action_doc,
621-
squash: true,
614+
squashBy: action.id,
622615
}
623616
})
624617
}
@@ -709,9 +702,8 @@ const ActionTarget: FC<{
709702
edit(() => {
710703
setAction({ ...action, name })
711704
return {
712-
action: 'set-action-name-' + action.id,
705+
action: 'set-action-name',
713706
desc: i18n.actions.editor2.set_action_target,
714-
squash: false,
715707
}
716708
})
717709
}}

src/components/editor2/action/ActionLinker.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,10 @@ export const ActionLinker: FC<ActionLinkerProps> = ({
131131
}
132132
})
133133
return {
134-
action: 'add-action-' + conditionType,
134+
action: 'add-action',
135135
desc: i18n.actions.editor2.add_action_condition({
136136
title: title(),
137137
}),
138-
squash: false,
139138
}
140139
})
141140
}}
@@ -321,11 +320,10 @@ const ConditionNode: FC<ConditionNodeProps> = ({
321320
draft[conditionKey] = undefined
322321
})
323322
return {
324-
action: `unset-action-${conditionKey}-${index}`,
323+
action: `unset-action-${conditionKey}`,
325324
desc: i18n.actions.editor2.delete_action_condition({
326325
title: typeInfo.title(),
327326
}),
328-
squash: false,
329327
}
330328
})
331329
}}
@@ -356,11 +354,11 @@ const ConditionNode: FC<ConditionNodeProps> = ({
356354
draft[conditionKey] = v
357355
})
358356
return {
359-
action: `set-action-${conditionKey}-${index}`,
357+
action: `set-action-${conditionKey}`,
360358
desc: i18n.actions.editor2.set_action_condition({
361359
title: typeInfo.title(),
362360
}),
363-
squash: true,
361+
squashBy: action.id,
364362
}
365363
})
366364
}}

src/components/editor2/action/CreateActionMenu.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ export const CreateActionMenu = forwardRef<
111111
return {
112112
action: 'add-action',
113113
desc: t.components.editor2.CreateActionMenu.add_action,
114-
squash: false,
115114
}
116115
})
117116
}}

0 commit comments

Comments
 (0)