Skip to content

Commit 01ea381

Browse files
committed
fix(core): 修复节点选中偶发失焦问题
1 parent 12020c3 commit 01ea381

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

packages/core/src/view/node/BaseNode.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createElement as h, Component } from 'preact/compat'
22
import { reaction, IReactionDisposer } from 'mobx'
3-
import { map } from 'lodash-es'
3+
import { map, isNil, isFunction } from 'lodash-es'
44
import Anchor from '../Anchor'
55
import { BaseText } from '../text'
66
import LogicFlow from '../../LogicFlow'
@@ -403,6 +403,15 @@ export abstract class BaseNode<P extends IProps = IProps> extends Component<
403403
} else {
404404
graphModel.eventCenter.emit(EventType.ELEMENT_CLICK, eventOptions)
405405
graphModel.eventCenter.emit(EventType.NODE_CLICK, eventOptions)
406+
// 复制粘贴后会出现点击节点时,节点会失去焦点的问题,这里手动让节点获焦以解决这个问题
407+
const el = e.currentTarget as HTMLElement
408+
const rAF =
409+
!isNil(window) && isFunction(window.requestAnimationFrame)
410+
? window.requestAnimationFrame.bind(window)
411+
: (fn: () => void) => setTimeout(fn, 0)
412+
rAF(() => {
413+
el.focus()
414+
})
406415
}
407416
}
408417

0 commit comments

Comments
 (0)