( state: EditHistoryState, currentHashes: Record<string, string>, now: number, )
| 162 | } |
| 163 | |
| 164 | export function undoEditHistory( |
| 165 | state: EditHistoryState, |
| 166 | currentHashes: Record<string, string>, |
| 167 | now: number, |
| 168 | ): EditHistoryTransitionResult { |
| 169 | const entry = state.undo[state.undo.length - 1]; |
| 170 | if (!entry) return { ok: false, reason: "empty", state, filesToWrite: {} }; |
| 171 | |
| 172 | const check = canApplyEditHistoryEntry(entry, "undo", currentHashes); |
| 173 | if (!check.ok) { |
| 174 | return { ok: false, reason: check.reason, path: check.path, state, filesToWrite: {} }; |
| 175 | } |
| 176 | |
| 177 | return { |
| 178 | ok: true, |
| 179 | entry, |
| 180 | filesToWrite: Object.fromEntries( |
| 181 | Object.entries(entry.files).map(([path, snapshot]) => [path, snapshot.before]), |
| 182 | ), |
| 183 | state: { |
| 184 | version: 1, |
| 185 | updatedAt: now, |
| 186 | undo: state.undo.slice(0, -1), |
| 187 | redo: [...state.redo, entry], |
| 188 | }, |
| 189 | }; |
| 190 | } |
| 191 | |
| 192 | export function redoEditHistory( |
| 193 | state: EditHistoryState, |
no test coverage detected