| 123 | } |
| 124 | |
| 125 | apply(host: Host): Promise<void> { |
| 126 | return host.read(this.path).then((content) => { |
| 127 | const prefix = content.substring(0, this.pos); |
| 128 | const suffix = content.substring(this.pos + this.oldText.length); |
| 129 | const text = content.substring(this.pos, this.pos + this.oldText.length); |
| 130 | |
| 131 | if (text !== this.oldText) { |
| 132 | return Promise.reject(new Error(`Invalid replace: "${text}" != "${this.oldText}".`)); |
| 133 | } |
| 134 | |
| 135 | // TODO: throw error if oldText doesn't match removed string. |
| 136 | return host.write(this.path, `${prefix}${this.newText}${suffix}`); |
| 137 | }); |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | export function applyToUpdateRecorder(recorder: UpdateRecorder, changes: Change[]): void { |