Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions packages/core/src/core.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { Command, HistoryOptions } from '@core/types'

export type History = ReturnType<typeof createHistory>

/**
* Creates a history manager for undo/redo functionality.
*
Expand Down Expand Up @@ -40,11 +42,15 @@ export function createHistory({ size = 30, coalesce = true }: HistoryOptions) {
/**
* Whether there are commands available to undo.
*/
get canUndo() { return undoStack.length > 0 },
get canUndo() {
return undoStack.length > 0
},
/**
* Whether there are commands available to redo.
*/
get canRedo() { return redoStack.length > 0 },
get canRedo() {
return redoStack.length > 0
},
/**
* Executes a command and adds it to the history.
* Clears the redo stack.
Expand Down Expand Up @@ -84,8 +90,7 @@ export function createHistory({ size = 30, coalesce = true }: HistoryOptions) {

undoFn()
redoStack.push({ key: cmd.key, do: redoFn, undo: undoFn })
}
else {
} else {
cmd.undo()
redoStack.push(cmd)
}
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export type { History } from '@core/core'

/**
* Represents a command that can be executed, undone, and redone.
*/
Expand Down