| 282 | * the plan read) are still valid when it lands. |
| 283 | */ |
| 284 | export function patchTransaction(state: EditorState, hunks: PatchHunk[]): Transaction | null { |
| 285 | if (hunks.length === 0) return null; |
| 286 | const tr = state.tr; |
| 287 | for (let k = hunks.length - 1; k >= 0; k--) tr.replaceWith(hunks[k].from, hunks[k].to, hunks[k].slice); |
| 288 | return tr; |
| 289 | } |
| 290 | |
| 291 | /** Plans and applies the patch to the live editor in ONE transaction. */ |
| 292 | export function applyPatch(editor: Editor, edits: PatchEdit[], ctx: PatchContext): PatchApplied | PatchRefusal { |