在cell:mouseleave的时候cell.removeTools({name:'button-remove'}) ,然而边上的edge-editor也会跟着一起被删除
问题描述
双击添加边上的edge-editor,原有的功能是划入在cell上添加button-remove,移除的时候删除,但是他在移出的时候会将edge-editor一起个删除了
重现链接
https://codesandbox.io/s/silly-goldberg-ejilkq?file=/src/app.tsx
重现步骤
在边上双击然后鼠标移出边
预期行为
只删除button-remove
平台
- 操作系统: [macOS, Windows, Linux, React Native ...]
- 网页浏览器: [Google Chrome, Safari, Firefox]
- X6 版本: [1.28.2 ... ]
屏幕截图或视频(可选)
https://user-images.githubusercontent.com/56207464/236983109-3fab9e26-a0dd-4789-a083-fe5b657cb75b.mp4
补充说明(可选)
No response
现在确实有这个问题,在移除 button-remove 工具的时候会刷新所有工具,导致文本编辑消失。暂时还没有好的方式来解决。我们会继续跟踪这个问题。
是只有移除button-remove的时候会有这个问题吗?我可以使用自定义的工具规避这个问题吗?
@nanfb 不是,是添加、删除任何工具都会导致 editor 刷新。
@NewByVector 为什么会有这样的设计呢?那这样的话removeTools传递参数还有什么意义呢?
@nanfb 这样的设计确实存在一些问题,每次工具更新都会刷新所有工具,虽然一定程度上降低了维护的复杂性,但是在一些特殊交互,比如你的场景中就难以支持。我们好好考虑一下这块的设计。
遇到类似的问题,恳请尽快解决: graph.on('edge:mouseenter', ({ cell }) => { // 添加连线的端点方便移动位置, source-arrowhead, target-arrowhead graph.on('edge:mouseleave', ({ cell }) => { // 删除 source-arrowhead, target-arrowhead, 导致 edge-editor 被无辜删除
同遇到了,期待后续更好的实现方式
一般情况下可以隐藏工具而不是删除来解决问题。
暂时可以用未暴露出来的方法去实现
graph.on('edge:mouseenter', (params) => {
const buttonRemove = (params.view?.tools?.tools || []).find((tool) => tool.name === 'button-remove');
buttonRemove?.show();
});
graph.on('edge:mouseleave', (params) => {
const buttonRemove = (params.view?.tools?.tools || []).find((tool) => tool.name === 'button-remove');
buttonRemove?.hide();
});
// edge hover移除删除按钮 graph.on('edge:mouseleave', ({ edge }) => { setTimeout(() => { //立即移除会导致edge-editor输入内容消失 edge.removeTool('button-remove'); }, 499); }); 暂时用了延迟移除解决了此问题,希望后续能有更优雅的解决方案