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
    })
相关推荐
NiNg_1_23420 分钟前
JS模块化工具requirejs详解
开发语言·javascript·ecmascript
果子切克now25 分钟前
vue2与vue3知识点
前端·javascript·vue.js
积水成江1 小时前
Vite+Vue3+SpringBoot项目如何打包部署
java·前端·vue.js·windows·spring boot·后端·nginx
一丝晨光1 小时前
Web技术简史、前后端分离、游戏
前端·javascript·css·游戏·unity·前后端分离·cocos
假客套1 小时前
2024 uniapp入门教程 01:含有vue3基础 我的第一个uniapp页面
前端·uni-app·vue3·hbuilder x
柒小毓1 小时前
网站开发基础:HTML、CSS
前端·css·html
哪 吒2 小时前
华为OD机试 - 冠亚军排名(Python/JS/C/C++ 2024 E卷 100分)
javascript·python·华为od
&白帝&3 小时前
Vue.js 过渡 & 动画
前端·javascript
总是学不会.3 小时前
SpringBoot项目:前后端打包与部署(使用 Maven)
java·服务器·前端·后端·maven
Fanfffff7204 小时前
深入探索Vue3组合式API
前端·javascript·vue.js