Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:修复笔记本触摸板点击节点事件失效 #1465

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions packages/core/src/view/node/BaseNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export default abstract class BaseNode extends Component<IProps, IState> {
}
stepDrag: StepDrag;
contextMenuTime: number;
mouseUpDrag: boolean;
startTime: number;
clickTimer: number;
modelDisposer: IReactionDisposer;
Expand Down Expand Up @@ -261,13 +262,17 @@ export default abstract class BaseNode extends Component<IProps, IState> {
const { model } = this.props;
model.isDragging = false;
};
handleMouseUp = () => {
const { model } = this.props;
this.mouseUpDrag = model.isDragging;
};
handleClick = (e: MouseEvent) => {
// 节点拖拽进画布之后,不触发click事件相关emit
// 点拖拽进画布没有触发mousedown事件,没有startTime,用这个值做区分
const isDragging = this.mouseUpDrag === false;
if (!this.startTime) return;
const time = new Date().getTime() - this.startTime;
if (time > 200) return; // 事件大于200ms,认为是拖拽, 不触发click事件。
const { model, graphModel } = this.props;
if (!isDragging) return; // 如果是拖拽, 不触发click事件。
// 节点数据,多为事件对象数据抛出
const nodeData = model.getData();
const position = graphModel.getPointByClient({
Expand Down Expand Up @@ -426,6 +431,7 @@ export default abstract class BaseNode extends Component<IProps, IState> {
<g
className={`${this.getStateClassName()} ${className}`}
onMouseDown={this.handleMouseDown}
onMouseUp={this.handleMouseUp}
onClick={this.handleClick}
onMouseEnter={this.setHoverON}
onMouseOver={this.setHoverON}
Expand Down