@@ -72,6 +72,7 @@ export class SelectionSelect {
72
72
}
73
73
this . startPoint = undefined
74
74
this . endPoint = undefined
75
+ this . mouseDownInfo = null
75
76
76
77
// 移除事件监听
77
78
document . removeEventListener ( 'mousemove' , this . draw )
@@ -134,9 +135,14 @@ export class SelectionSelect {
134
135
// 禁用右键框选
135
136
const isRightClick = e . button === 2
136
137
if ( isRightClick ) return
137
-
138
138
// 清理之前可能存在的选区状态
139
139
this . cleanupSelectionState ( )
140
+ // 记录鼠标按下时的位置和时间
141
+ this . mouseDownInfo = {
142
+ x : e . clientX ,
143
+ y : e . clientY ,
144
+ time : Date . now ( ) ,
145
+ }
140
146
141
147
// 记录原始设置并临时禁止画布移动
142
148
this . originalStopMoveGraph = this . lf . getEditConfig ( ) . stopMoveGraph !
@@ -165,22 +171,6 @@ export class SelectionSelect {
165
171
document . addEventListener ( 'mouseup' , this . drawOff )
166
172
}
167
173
168
- onToolContainerMouseUp = ( e : MouseEvent ) => {
169
- if ( this . mouseDownInfo ) {
170
- const { x, y, time } = this . mouseDownInfo
171
- const now = Date . now ( )
172
- // 用 mouseDown 和 mouseUp 的位置偏移及时间间隔来判断是否是点击事件
173
- const isClickEvent =
174
- Math . abs ( e . clientX - x ) < 10 &&
175
- Math . abs ( e . clientY - y ) < 10 &&
176
- now - time < 100
177
- if ( isClickEvent ) {
178
- this . lf . clearSelectElements ( )
179
- }
180
- this . mouseDownInfo = null
181
- }
182
- }
183
-
184
174
/**
185
175
* 设置选中的灵敏度
186
176
* @param isWholeEdge 是否要边的起点终点都在选区范围才算选中。默认true
@@ -259,6 +249,21 @@ export class SelectionSelect {
259
249
}
260
250
}
261
251
private drawOff = ( e : MouseEvent ) => {
252
+ // 处理鼠标抬起事件
253
+ // 首先判断是否是点击,如果是,则清空框选
254
+ if ( this . mouseDownInfo ) {
255
+ const { x, y, time } = this . mouseDownInfo
256
+ const isClick =
257
+ Math . abs ( e . clientX - x ) < 5 &&
258
+ Math . abs ( e . clientY - y ) < 5 &&
259
+ Date . now ( ) - time < 200
260
+ if ( isClick ) {
261
+ this . lf . clearSelectElements ( )
262
+ this . cleanupSelectionState ( )
263
+ return
264
+ }
265
+ }
266
+
262
267
const curStartPoint = cloneDeep ( this . startPoint )
263
268
const curEndPoint = cloneDeep ( this . endPoint )
264
269
document . removeEventListener ( 'mousemove' , this . draw )
0 commit comments