feat:菜单栏状态边界处理

pr675
黄云飞 4 years ago
parent 6027141c2b
commit fd43ea9fbf

@ -27,28 +27,34 @@ export class GlobalEvent {
this.setRangeStyle() this.setRangeStyle()
}) })
document.addEventListener('click', (evt) => { document.addEventListener('click', (evt) => {
this.recoverCursor(evt) this.recoverEffect(evt)
this.setRangeStyle()
}) })
document.addEventListener('mouseup', () => { document.addEventListener('mouseup', () => {
this.setDragState() this.setDragState()
}) })
} }
recoverCursor(evt: MouseEvent) { recoverEffect(evt: MouseEvent) {
if (!this.cursor) return if (!this.cursor) return
const cursorDom = this.cursor.getCursorDom() const cursorDom = this.cursor.getCursorDom()
const agentDom = this.cursor.getAgentDom() const agentDom = this.cursor.getAgentDom()
const innerDoms = [this.canvas, cursorDom, agentDom, document.body] 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 // 编辑器外部dom
const outerEditorDom = findParent( const outerEditorDom = findParent(
evt.target as Element, evt.target as Element,
(node: Node & Element) => !!node && node.nodeType === 1 && !!node.getAttribute(EDITOR_COMPONENT), (node: Node & Element) => !!node && node.nodeType === 1 && !!node.getAttribute(EDITOR_COMPONENT),
true true
) )
if (outerEditorDom) return if (outerEditorDom) {
this.setRangeStyle()
return
}
this.cursor.recoveryCursor() this.cursor.recoveryCursor()
this.range.recoveryRangeStyle()
} }
setDragState() { 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) { public render(x: number, y: number, width: number, height: number) {
this.ctx.save() this.ctx.save()
this.ctx.globalAlpha = this.options.rangeAlpha this.ctx.globalAlpha = this.options.rangeAlpha

@ -18,6 +18,12 @@ window.onload = function () {
const i = text.indexOf(b) const i = text.indexOf(b)
return ~i ? Array(b.length).fill(i).map((_, j) => i + j) : [] return ~i ? Array(b.length).fill(i).map((_, j) => i + j) : []
}).flat() }).flat()
// 模拟高亮字
const highlightText = ['血细胞比容']
const highlightIndex: number[] = highlightText.map(b => {
const i = text.indexOf(b)
return ~i ? Array(b.length).fill(i).map((_, j) => i + j) : []
}).flat()
// 组合数据 // 组合数据
const data = text.split('').map((value, index) => { const data = text.split('').map((value, index) => {
if (boldIndex.includes(index)) { if (boldIndex.includes(index)) {
@ -34,6 +40,12 @@ window.onload = function () {
size: 16 size: 16
} }
} }
if (highlightIndex.includes(index)) {
return {
value,
highlight: '#F2F27F'
}
}
return { return {
value, value,
size: 16 size: 16

Loading…
Cancel
Save