(editor: Editor, oldSrc: string, newSrc: string)
| 51 | } |
| 52 | |
| 53 | function swapImageSrc(editor: Editor, oldSrc: string, newSrc: string): void { |
| 54 | const { state } = editor; |
| 55 | const { tr } = state; |
| 56 | let found = false; |
| 57 | |
| 58 | state.doc.descendants((node, pos) => { |
| 59 | if (found) return false; |
| 60 | if (node.type.name === 'image' && node.attrs.src === oldSrc) { |
| 61 | tr.setNodeMarkup(pos, undefined, { ...node.attrs, src: newSrc }); |
| 62 | found = true; |
| 63 | return false; |
| 64 | } |
| 65 | }); |
| 66 | |
| 67 | if (found) { |
| 68 | editor.view.dispatch(tr); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | function removeImageBySrc(editor: Editor, src: string): void { |
| 73 | const { state } = editor; |
no test coverage detected