From 51427c7dc462ea5a33ae6a92836d1e7ded7cf43d Mon Sep 17 00:00:00 2001 From: Hufe921 Date: Tue, 12 Mar 2024 22:41:23 +0800 Subject: [PATCH] feat: cancel painter style setting #453 --- src/editor/core/command/CommandAdapt.ts | 5 +++++ src/main.ts | 24 +++++++++++++++++++----- 2 files changed, 24 insertions(+), 5 deletions(-) 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 })