Skip to content

Commit 28f0c60

Browse files
author
昔梦
committed
feat:增加撤销、重做的画布快捷键功能,ctrl+z撤销 ctrl+Y重做,并增加文档描述
1 parent 161e529 commit 28f0c60

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

docs/xflow/api.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,14 @@ Handle 配置继承自 React Flow 的 Handle 配置,用于控制节点连接
202202
| key | 节点菜单项的key | `string` | |
203203
| nodeId | 节点ID | `string` | |
204204
| sourceHandle | 连接头ID | `string` | |
205+
206+
207+
## 画布快捷键
208+
209+
| 快捷键 | 功能描述 |
210+
|----------------------|------------------|
211+
| Ctrl/Cmd + C | 复制选中节点 |
212+
| Ctrl/Cmd + V | 粘贴节点 |
213+
| Delete/Backspace | 删除选中节点或边 |
214+
| Ctrl/Cmd + Z | 撤销 |
215+
| Ctrl/Cmd + Y | 重做 |

docs/xflow/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ group:
243243
<div class="feature-name">画布操作</div>
244244
<div class="feature-content">
245245
<div class="feature-desc">
246-
支持画布缩放、撤销/重置、节点添加、鼠标模式切换、节点整理、全屏展示等功能。提供丰富的画布操作工具,提升用户体验。
246+
支持画布缩放、撤销/重置、节点添加、鼠标模式切换、节点整理、全屏展示、画布快捷键等功能。提供丰富的画布操作工具,提升用户体验。
247247
</div>
248248
<div class="feature-image node-show-img">
249249
<img src="https://img.alicdn.com/imgextra/i3/O1CN01Pcb1wd1RKe0hVF7nG_!!6000000002093-0-tps-3172-1234.jpg" alt="画布操作" />

packages/x-flow/src/XFlow.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ const XFlow: FC<FlowProps> = memo(props => {
9191
const { onNodeClick, onEdgeClick, zoomOnScroll = true, panOnScroll = false, preventScrolling = true } = props;
9292
const nodeEditorRef = useRef(null);
9393
const { copyNode, pasteNodeSimple } = useFlow();
94+
const { undo, redo } = useTemporalStore();
9495

9596
useEffect(() => {
9697
zoomTo(0.8);
@@ -103,10 +104,14 @@ const XFlow: FC<FlowProps> = memo(props => {
103104
useEventListener('keydown', e => {
104105
if ((e.key === 'd' || e.key === 'D') && (e.ctrlKey || e.metaKey))
105106
e.preventDefault();
106-
if ((e.key === 'z' || e.key === 'Z') && (e.ctrlKey || e.metaKey))
107+
if ((e.key === 'z' || e.key === 'Z') && (e.ctrlKey || e.metaKey)) {
107108
e.preventDefault();
108-
if ((e.key === 'y' || e.key === 'Y') && (e.ctrlKey || e.metaKey))
109+
undo();
110+
}
111+
if ((e.key === 'y' || e.key === 'Y') && (e.ctrlKey || e.metaKey)) {
109112
e.preventDefault();
113+
redo();
114+
}
110115
if ((e.key === 's' || e.key === 'S') && (e.ctrlKey || e.metaKey))
111116
e.preventDefault();
112117
if ((e.key === 'c' || e.key === 'C') && (e.ctrlKey || e.metaKey)) {

0 commit comments

Comments
 (0)