-
-
Notifications
You must be signed in to change notification settings - Fork 408
feat: expose clearHistory() to reset the undo/redo stack #373
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
cb4d6a0
e6e688b
601dc4b
15a42c9
1e50bf0
90b0e0e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -88,6 +88,11 @@ export default function (mei: MindElixirInstance) { | |
| } | ||
| } | ||
| } | ||
| mei.clearHistory = function () { | ||
| history = [] | ||
| currentIndex = -1 | ||
| current = mei.getData() | ||
| } | ||
|
Comment on lines
+91
to
+96
|
||
| const handleOperation = function (operation: Operation) { | ||
| if (operation.name === 'beginEdit') return | ||
| history = history.slice(0, currentIndex + 1) | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -121,6 +121,13 @@ export interface MindElixirInstance extends Omit<Required<Options>, 'markdown' | | |||||||||||||||||||||||||||||||||
| history: Operation[] | ||||||||||||||||||||||||||||||||||
| undo: () => void | ||||||||||||||||||||||||||||||||||
| redo: () => void | ||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||
| * Reset the undo/redo stack and update the internal baseline snapshot to the | ||||||||||||||||||||||||||||||||||
| * current diagram state. Call this after loading new data into an existing | ||||||||||||||||||||||||||||||||||
| * instance (e.g. after `refresh()`) to prevent users from undoing back into | ||||||||||||||||||||||||||||||||||
| * a previously loaded diagram. | ||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||
| clearHistory: () => void | ||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in
|
||||||||||||||||||||||||||||||||||
| clearHistory: () => void | |
| clearHistory?: () => void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 15a42c9 — changed to clearHistory?: () => void and updated the JSDoc to note that it is only available when allowUndo is true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clearHistory()clears the history stack but leavescurrentSelectedNodesunchanged. Since the intended usage is right afterrefresh(), selection is typically cleared, and the next operation may incorrectly record the previous diagram’s selected node IDs incurrentSelected, which can break selection restoration on undo/redo. ResetcurrentSelectedNodesinsideclearHistory()(e.g., derive it frommei.currentNodes) or update the selection tracking to handle deselection events as well.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in
601dc4b— addedcurrentSelectedNodes = []toclearHistory()so stale node IDs from the previous diagram cannot affect selection restoration afterrefresh()+clearHistory().