feat:菜单栏状态边界处理
This commit is contained in:
@@ -27,28 +27,34 @@ export class GlobalEvent {
|
||||
this.setRangeStyle()
|
||||
})
|
||||
document.addEventListener('click', (evt) => {
|
||||
this.recoverCursor(evt)
|
||||
this.setRangeStyle()
|
||||
this.recoverEffect(evt)
|
||||
})
|
||||
document.addEventListener('mouseup', () => {
|
||||
this.setDragState()
|
||||
})
|
||||
}
|
||||
|
||||
recoverCursor(evt: MouseEvent) {
|
||||
recoverEffect(evt: MouseEvent) {
|
||||
if (!this.cursor) return
|
||||
const cursorDom = this.cursor.getCursorDom()
|
||||
const agentDom = this.cursor.getAgentDom()
|
||||
const innerDoms = [this.canvas, cursorDom, agentDom, document.body]
|
||||
if (innerDoms.includes(evt.target as any)) return
|
||||
if (innerDoms.includes(evt.target as any)) {
|
||||
this.setRangeStyle()
|
||||
return
|
||||
}
|
||||
// 编辑器外部dom
|
||||
const outerEditorDom = findParent(
|
||||
evt.target as Element,
|
||||
(node: Node & Element) => !!node && node.nodeType === 1 && !!node.getAttribute(EDITOR_COMPONENT),
|
||||
true
|
||||
)
|
||||
if (outerEditorDom) return
|
||||
if (outerEditorDom) {
|
||||
this.setRangeStyle()
|
||||
return
|
||||
}
|
||||
this.cursor.recoveryCursor()
|
||||
this.range.recoveryRangeStyle()
|
||||
}
|
||||
|
||||
setDragState() {
|
||||
|
||||
@@ -75,6 +75,24 @@ export class RangeManager {
|
||||
})
|
||||
}
|
||||
|
||||
public recoveryRangeStyle() {
|
||||
if (!this.listener.rangeStyleChange) return
|
||||
const painter = !!this.draw.getPainterStyle()
|
||||
const undo = this.historyManager.isCanUndo()
|
||||
const redo = this.historyManager.isCanRedo()
|
||||
this.listener.rangeStyleChange({
|
||||
undo,
|
||||
redo,
|
||||
painter,
|
||||
bold: false,
|
||||
italic: false,
|
||||
underline: false,
|
||||
strikeout: false,
|
||||
color: null,
|
||||
highlight: null
|
||||
})
|
||||
}
|
||||
|
||||
public render(x: number, y: number, width: number, height: number) {
|
||||
this.ctx.save()
|
||||
this.ctx.globalAlpha = this.options.rangeAlpha
|
||||
|
||||
Reference in New Issue
Block a user