Skip to content

Commit b10d935

Browse files
committed
fix(editor2): editor history not being reset
1 parent 597c2ee commit b10d935

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

src/components/editor2/EditorToolbar.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ const AutoSaveButton = (buttonProps: ButtonProps) => {
147147
<Callout
148148
intent="primary"
149149
icon={null}
150-
className="p-0 pl-2 flex items-center"
150+
className="p-0 pl-2 flex items-center gap-2"
151151
>
152152
{t.components.editor2.EditorToolbar.auto_save_interval({
153153
count: AUTO_SAVE_INTERVAL / 1000 / 60,
@@ -157,7 +157,6 @@ const AutoSaveButton = (buttonProps: ButtonProps) => {
157157
<Button
158158
icon="floppy-disk"
159159
intent="primary"
160-
className=""
161160
onClick={() => {
162161
try {
163162
save()
@@ -335,7 +334,9 @@ const ErrorButton = (buttonProps: ButtonProps) => {
335334
? t.components.editor2.EditorToolbar.errors_header
336335
: t.components.editor2.EditorToolbar.no_errors
337336
}
338-
text={allErrors.length || undefined}
337+
text={
338+
allErrors.length || <Icon className="!-ml-px" icon="small-tick" />
339+
}
339340
/>
340341
</Popover2>
341342
)

src/components/editor2/editor-state.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ export const editorAtoms = {
279279
reset: atom(
280280
null,
281281
(get, set, editorState: EditorState = defaultEditorState) => {
282+
set(historyAtom, 'RESET')
282283
set(editorAtom, editorState)
283284
set(editorGlobalErrorsAtom, [])
284285
set(editorEntityErrorsAtom, {})

src/components/editor2/history.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ interface HistoryTracker<T extends {}> {
3434
_current?: HistoryRecord<T>
3535
}
3636

37-
function createInitialEditorHistoryState<T extends {}>(
37+
function createInitialTrackerState<T extends {}>(
3838
limit: number,
3939
): InternalHistoryTracker<T> {
4040
const record = {
@@ -54,7 +54,7 @@ export function createHistoryAtom<T extends {}>(
5454
stateAtom: PrimitiveAtom<T>,
5555
limit: number,
5656
) {
57-
const historyTrackerAtom = atom(createInitialEditorHistoryState<T>(limit))
57+
const historyTrackerAtom = atom(createInitialTrackerState<T>(limit))
5858

5959
const fromInternal = <T extends {}>(
6060
tracker: InternalHistoryTracker<T>,
@@ -93,9 +93,18 @@ export function createHistoryAtom<T extends {}>(
9393

9494
return atom(
9595
(get) => fromInternal(get(historyTrackerAtom), get(stateAtom)),
96-
(get, set, update: SetStateAction<HistoryTracker<T>>) => {
96+
(get, set, update: SetStateAction<HistoryTracker<T>> | 'RESET') => {
97+
const internalTracker = get(historyTrackerAtom)
98+
99+
if (update === 'RESET') {
100+
set(
101+
historyTrackerAtom,
102+
createInitialTrackerState<T>(internalTracker.limit),
103+
)
104+
return
105+
}
97106
const { _current, ...tracker } = fromInternal(
98-
get(historyTrackerAtom),
107+
internalTracker,
99108
get(stateAtom),
100109
)
101110
if (typeof update === 'function') {

0 commit comments

Comments
 (0)