(
this: CodeBlock,
strings: TemplateStringsArray,
...rest: (CodeModification | Code)[]
)
| 237 | */ |
| 238 | public edit(duration = 0.6, changeSelection: CodeRange[] | boolean = true) { |
| 239 | function* generator( |
| 240 | this: CodeBlock, |
| 241 | strings: TemplateStringsArray, |
| 242 | ...rest: (CodeModification | Code)[] |
| 243 | ): ThreadGenerator { |
| 244 | const from = { |
| 245 | language: this.language(), |
| 246 | spans: [...strings], |
| 247 | nodes: rest.map(modification => |
| 248 | isCodeModification(modification) ? modification.from : modification, |
| 249 | ), |
| 250 | }; |
| 251 | const to = { |
| 252 | language: this.language(), |
| 253 | spans: [...strings], |
| 254 | nodes: rest.map(modification => |
| 255 | isCodeModification(modification) ? modification.to : modification, |
| 256 | ), |
| 257 | }; |
| 258 | this.code(from); |
| 259 | |
| 260 | if (changeSelection) { |
| 261 | const task = yield this.code(to, duration); |
| 262 | yield* waitFor(duration * 0.2); |
| 263 | yield* this.selection([], duration * 0.3); |
| 264 | |
| 265 | const newSelection: CodeRange[] = |
| 266 | changeSelection === true |
| 267 | ? diff(from, to) |
| 268 | .filter(token => token.morph === 'create') |
| 269 | .map(token => [ |
| 270 | [token.to![1], token.to![0]], |
| 271 | [token.to![1], token.to![0] + token.code.length], |
| 272 | ]) |
| 273 | : changeSelection; |
| 274 | |
| 275 | yield* this.selection(newSelection, duration * 0.3); |
| 276 | yield* join(task); |
| 277 | } else { |
| 278 | yield* this.code(to, duration); |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | return generator.bind(this); |
| 283 | } |
nothing calls this directly
no test coverage detected