()
| 4 | const { command, project } = ctx; |
| 5 | return { |
| 6 | init() { |
| 7 | command.registerCommand({ |
| 8 | name: 'undo', |
| 9 | description: 'Undo the last operation.', |
| 10 | handler: () => { |
| 11 | const state = project.currentDocument?.history.getState() || 0; |
| 12 | const enable = !!(state & 1); |
| 13 | if (!enable) { |
| 14 | throw new Error('Can not undo.'); |
| 15 | } |
| 16 | project.currentDocument?.history.back(); |
| 17 | }, |
| 18 | }); |
| 19 | |
| 20 | command.registerCommand({ |
| 21 | name: 'redo', |
| 22 | description: 'Redo the last operation.', |
| 23 | handler: () => { |
| 24 | const state = project.currentDocument?.history.getState() || 0; |
| 25 | const enable = !!(state & 2); |
| 26 | if (!enable) { |
| 27 | throw new Error('Can not redo.'); |
| 28 | } |
| 29 | project.currentDocument?.history.forward(); |
| 30 | }, |
| 31 | }); |
| 32 | }, |
| 33 | destroy() { |
| 34 | command.unregisterCommand('history:undo'); |
| 35 | command.unregisterCommand('history:redo'); |
nothing calls this directly
no test coverage detected
searching dependent graphs…