()
| 161 | } |
| 162 | |
| 163 | const undo = () => { |
| 164 | if (currentHistoryIndex <= 0) return |
| 165 | |
| 166 | const canvas = canvasRef.current |
| 167 | if (!canvas) return |
| 168 | |
| 169 | const ctx = canvas.getContext('2d') |
| 170 | if (!ctx) return |
| 171 | |
| 172 | const newIndex = currentHistoryIndex - 1 |
| 173 | ctx.putImageData(history[newIndex].imageData, 0, 0) |
| 174 | setCurrentHistoryIndex(newIndex) |
| 175 | } |
| 176 | |
| 177 | const redo = () => { |
| 178 | if (currentHistoryIndex >= history.length - 1) return |