diff --git a/src/editor/core/command/CommandAdapt.ts b/src/editor/core/command/CommandAdapt.ts index 5ae1a65..0fbe282 100644 --- a/src/editor/core/command/CommandAdapt.ts +++ b/src/editor/core/command/CommandAdapt.ts @@ -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 = {} diff --git a/src/main.ts b/src/main.ts index 5e91d99..cebac5a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -96,14 +96,28 @@ window.onload = function () { const painterDom = document.querySelector( '.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 })