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
    })
相关推荐
YGY Webgis糕手之路2 分钟前
Cesium 快速入门(八)Primitive(图元)系统深度解析
前端·经验分享·笔记·vue·web
懋学的前端攻城狮2 分钟前
从 UI = f(state) 到 Fiber 架构:解构 React 设计哲学的“第一性原理”
前端·react.js·前端框架
三原6 分钟前
6年前端学习Java Spring boot 要怎么学?
java·前端·javascript
yourkin6669 分钟前
Bean Post-Processor
java·开发语言·前端
前端小咸鱼一条32 分钟前
React中的this绑定
前端·javascript·react.js
影子信息38 分钟前
vue vxe-table :edit-config=“editConfig“ 可以编辑的表格
前端·javascript·vue.js
YGY Webgis糕手之路38 分钟前
Cesium 快速入门(四)相机控制完全指南
前端·经验分享·笔记·vue·web
JavaDog程序狗41 分钟前
【软件环境】Windows安装NVM
前端·node.js
黑土豆1 小时前
为什么我要搞一个Markdown导入组件?说出来你可能不信...
前端·javascript·markdown
前端小巷子1 小时前
Vue 2 响应式系统
前端·vue.js·面试