(callbacks: ApplyCallbacks)
| 171 | }); |
| 172 | }, |
| 173 | async undo(callbacks: ApplyCallbacks): Promise<ApplyResult> { |
| 174 | return mutate<ApplyResult>(async (currentState) => { |
| 175 | const entry = currentState.undo[currentState.undo.length - 1]; |
| 176 | if (!entry) { |
| 177 | return { |
| 178 | state: currentState, |
| 179 | result: { ok: false, reason: "empty" }, |
| 180 | }; |
| 181 | } |
| 182 | const { currentFiles, currentHashes } = await readCurrentFileHashes( |
| 183 | Object.keys(entry.files), |
| 184 | callbacks.readFile, |
| 185 | ); |
| 186 | const result = undoEditHistory(currentState, currentHashes, now()); |
| 187 | if (!result.ok) { |
| 188 | return { |
| 189 | state: currentState, |
| 190 | result: { ok: false, reason: result.reason }, |
| 191 | }; |
| 192 | } |
| 193 | await writeFilesWithRollback({ |
| 194 | files: result.filesToWrite, |
| 195 | rollbackFiles: currentFiles, |
| 196 | writeFile: callbacks.writeFile, |
| 197 | }); |
| 198 | return { |
| 199 | state: result.state, |
| 200 | result: { ok: true, label: result.entry.label, paths: Object.keys(result.entry.files) }, |
| 201 | }; |
| 202 | }); |
| 203 | }, |
| 204 | async redo(callbacks: ApplyCallbacks): Promise<ApplyResult> { |
| 205 | return mutate<ApplyResult>(async (currentState) => { |
| 206 | const entry = currentState.redo[currentState.redo.length - 1]; |
nothing calls this directly
no test coverage detected