Skip to content

Commit

Permalink
feat: cancel painter style setting #453
Browse files Browse the repository at this point in the history
  • Loading branch information
Hufe921 committed Mar 12, 2024
1 parent 86f4cf5 commit 51427c7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/editor/core/command/CommandAdapt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,11 @@ export class CommandAdapt {
}

public painter(options: IPainterOption) {
// 如果单击且已经有样式设置则取消设置
if (!options.isDblclick && this.draw.getPainterStyle()) {
this.canvasEvent.clearPainterStyle()
return
}
const selection = this.range.getSelection()
if (!selection) return
const painterStyle: IElementStyle = {}
Expand Down
24 changes: 19 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,28 @@ window.onload = function () {
const painterDom = document.querySelector<HTMLDivElement>(
'.menu-item__painter'
)!

let isFirstClick = true
let painterTimeout: number
painterDom.onclick = function () {
console.log('painter')
instance.command.executePainter({
isDblclick: false
})
if (isFirstClick) {
isFirstClick = false
painterTimeout = window.setTimeout(() => {
console.log('painter-click')
isFirstClick = true
instance.command.executePainter({
isDblclick: false
})
}, 200)
} else {
window.clearTimeout(painterTimeout)
}
}

painterDom.ondblclick = function () {
console.log('painter')
console.log('painter-dblclick')
isFirstClick = true
window.clearTimeout(painterTimeout)
instance.command.executePainter({
isDblclick: true
})
Expand Down

0 comments on commit 51427c7

Please sign in to comment.