antv/x6 键盘快捷键事件

antv/x6 键盘快捷键事件

引用插件

安装

javascript 复制代码
npm install @antv/x6-plugin-selection --save
npm install @antv/x6-plugin-keyboard --save
npm install @antv/x6-plugin-clipboard --save
npm install @antv/x6-plugin-history --save

导入

javascript 复制代码
import { Selection } from '@antv/x6-plugin-selection'
import { Keyboard } from '@antv/x6-plugin-keyboard'
import { Clipboard } from '@antv/x6-plugin-clipboard'
import { History } from '@antv/x6-plugin-history'

取消/重做

javascript 复制代码
    this.graph.bindKey(['meta+z', 'ctrl+z'], () => {
      if (this.graph.canUndo()) {
        this.graph.undo()
      }
      return false
    })
    this.graph.bindKey(['meta+y', 'ctrl+y'], () => {
      if (this.graph.canRedo()) {
        this.graph.redo()
      }
      return false
    })

放大/缩小

javascript 复制代码
    this.graph.bindKey(['ctrl+1', 'meta+1'], () => {
      const zoom = this.graph.zoom()
      if (zoom < 1.5) {
        this.graph.zoom(0.1)
      }
    })
    this.graph.bindKey(['ctrl+2', 'meta+2'], () => {
      const zoom = this.graph.zoom()
      if (zoom > 0.5) {
        this.graph.zoom(-0.1)
      }
    })

复制/剪切/粘贴

javascript 复制代码
    this.graph.bindKey(['meta+c', 'ctrl+c'], () => {
      const cells = this.graph.getSelectedCells()
      if (cells.length) {
        this.graph.copy(cells)
      }
      return false
    })
    
	this.graph.bindKey(['meta+x', 'ctrl+x'], () => {
	  const cells = graph.getSelectedCells()
	  if (cells.length) {
	    graph.cut(cells)
	  }
	  return false
	})

    this.graph.bindKey(['meta+v', 'ctrl+v'], () => {
      if (!this.graph.isClipboardEmpty()) {
        const cells = this.graph.paste({ offset: 32 })
        this.graph.cleanSelection()
        this.graph.select(cells)
      }
      return false
    })
相关推荐
xdl25992 分钟前
CSS flex 布局中没有 justify-items
前端·css
百撕可乐2 分钟前
WenDoraAi官网NextJS实战04:HTTP 请求封装与SSR
前端·网络·网络协议·react.js·http
Sestid4 分钟前
前端AI编程使用技巧(后续会更新cursor和claude code for vscode)
前端·vscode·ai编程·claude·cursor
freeWayWalker7 分钟前
Vue通用缩放容器
前端·javascript·vue.js
Hello--_--World15 分钟前
VUE:逻辑复用
前端·javascript·vue.js
陶甜也31 分钟前
3D智慧城市:blender建模、骨骼、动画、VUE、threeJs引入渲染,飞行视角,涟漪、人物行走
前端·3d·vue·blender·threejs·模型
患得患失94937 分钟前
【前端websocket】企业级功能清单
前端·websocket·网络协议
落魄江湖行37 分钟前
基础篇四 Nuxt4 全局样式与 CSS 模块
前端·css·typescript·nuxt4
禅思院38 分钟前
前端性能优化:从"术"到"道"的完整修炼指南
前端·架构·前端框架