forked from alibaba/lowcode-engine
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathhistory-command.ts
More file actions
43 lines (40 loc) · 1.25 KB
/
history-command.ts
File metadata and controls
43 lines (40 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { IPublicModelPluginContext, IPublicTypePlugin } from '@felce/lowcode-types';
export const historyCommand: IPublicTypePlugin = (ctx: IPublicModelPluginContext) => {
const { command, project } = ctx;
return {
init() {
command.registerCommand({
name: 'undo',
description: 'Undo the last operation.',
handler: () => {
const state = project.currentDocument?.history.getState() || 0;
const enable = !!(state & 1);
if (!enable) {
throw new Error('Can not undo.');
}
project.currentDocument?.history.back();
},
});
command.registerCommand({
name: 'redo',
description: 'Redo the last operation.',
handler: () => {
const state = project.currentDocument?.history.getState() || 0;
const enable = !!(state & 2);
if (!enable) {
throw new Error('Can not redo.');
}
project.currentDocument?.history.forward();
},
});
},
destroy() {
command.unregisterCommand('history:undo');
command.unregisterCommand('history:redo');
},
};
};
historyCommand.pluginName = '___history_command___';
historyCommand.meta = {
commandScope: 'history',
};