fix(annotate): 丢 mouseup 后自愈收笔 + 失焦/指针取消复位交互状态(修「画一次后画布不响应」)v1.20.2
This commit is contained in:
1 parent
9dd3b0985b
commit
329b4638c3
3 files changed
+63
-2
No files matched your search
@@ -357,6 +357,12 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
function onMouseMove(e) {
|
||||
// 记下修饰键:拖动按 Alt 时临时关掉吸附(想停在「差一点点」的位置时用)
|
||||
S._altDown = !!e.altKey
|
||||
// 自愈:拖出窗口/切换应用会丢 mouseup,isDrawing 会永远为 true,后续操作被忽略
|
||||
if (S.isDrawing && e.buttons === 0) {
|
||||
S.isDrawing = false
|
||||
const up = Object.prototype.hasOwnProperty.call(DRAW_UP_HANDLERS, S.tool) ? DRAW_UP_HANDLERS[S.tool] : null
|
||||
try { if (up) up(getPos(e)) } catch (err) { /* 收笔失败不影响后续 */ }
|
||||
}
|
||||
// 图片放置拖拽
|
||||
if (S.placingImage && S.placingHandle && S.placingStart) {
|
||||
onPlacementDragMove(e); return
|
||||
@@ -2640,6 +2646,25 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
}
|
||||
|
||||
/** 将 canvas 鼠标事件绑定到活跃图层 canvas(在 setupCanvas 后调用,仅绑定一次) */
|
||||
// 交互状态复位:窗口失焦 / 指针取消 / 切标签页时兜底
|
||||
function resetPointerState() {
|
||||
S.isDrawing = false
|
||||
S.marquee = null
|
||||
S.lassoPts = null
|
||||
S.textDrag = null
|
||||
S.bitmapDrag = null
|
||||
S.shapeDrag = null
|
||||
S.penDragPt = -1
|
||||
S.penDragPending = null
|
||||
S.placingHandle = null
|
||||
S.panning = false
|
||||
S.interaction = 'idle'
|
||||
if (S.strokeCanvas) S.strokeCanvas.style.display = 'none'
|
||||
document.body.style.cursor = ''
|
||||
document.body.style.userSelect = ''
|
||||
try { renderObjects() } catch (e) { /* ignore */ }
|
||||
}
|
||||
|
||||
export function bindCanvasEvents() {
|
||||
if (S._canvasEventsBound) return
|
||||
S._canvasEventsBound = true
|
||||
@@ -2649,6 +2674,9 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
S.canvasStack.addEventListener('mousemove', onMouseMove)
|
||||
S.canvasStack.addEventListener('mousemove', onCanvasHover)
|
||||
window.addEventListener('mouseup', onMouseUp)
|
||||
window.addEventListener('blur', resetPointerState)
|
||||
document.addEventListener('pointercancel', resetPointerState)
|
||||
document.addEventListener('visibilitychange', () => { if (document.hidden) resetPointerState() })
|
||||
S.canvasStack.addEventListener('contextmenu', (e) => {
|
||||
e.preventDefault()
|
||||
if (S.open && !S.placingImage) showSelectionContext(e)
|
||||
|
||||
Reference in new issue
Block a user