| 904 | const historyLimit = 100; |
| 905 | |
| 906 | export const pushUndo = (currentState: TextBufferState): TextBufferState => { |
| 907 | const snapshot = { |
| 908 | lines: [...currentState.lines], |
| 909 | cursorRow: currentState.cursorRow, |
| 910 | cursorCol: currentState.cursorCol, |
| 911 | }; |
| 912 | const newStack = [...currentState.undoStack, snapshot]; |
| 913 | if (newStack.length > historyLimit) { |
| 914 | newStack.shift(); |
| 915 | } |
| 916 | return { ...currentState, undoStack: newStack, redoStack: [] }; |
| 917 | }; |
| 918 | |
| 919 | export type TextBufferAction = |
| 920 | | { type: 'set_text'; payload: string; pushToUndo?: boolean } |