From 5ce95ef38dd825cfcf5feba3b59c2f7a262f347e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E4=BA=91=E9=A3=9E?= Date: Wed, 16 Mar 2022 17:18:27 +0800 Subject: [PATCH] feat:add interface for cypress --- src/editor/core/command/Command.ts | 6 ++++ src/editor/core/command/CommandAdapt.ts | 4 +++ src/editor/core/event/CanvasEvent.ts | 39 +++++++++++++------------ 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/src/editor/core/command/Command.ts b/src/editor/core/command/Command.ts index a98b5cb..73c1b71 100644 --- a/src/editor/core/command/Command.ts +++ b/src/editor/core/command/Command.ts @@ -17,6 +17,7 @@ export class Command { private static undo: Function private static redo: Function private static painter: Function + private static applyPainterStyle: Function private static format: Function private static font: Function private static sizeAdd: Function @@ -67,6 +68,7 @@ export class Command { Command.undo = adapt.undo.bind(adapt) Command.redo = adapt.redo.bind(adapt) Command.painter = adapt.painter.bind(adapt) + Command.applyPainterStyle = adapt.applyPainterStyle.bind(adapt) Command.format = adapt.format.bind(adapt) Command.font = adapt.font.bind(adapt) Command.sizeAdd = adapt.sizeAdd.bind(adapt) @@ -149,6 +151,10 @@ export class Command { return Command.painter() } + public executeApplyPainterStyle() { + return Command.applyPainterStyle() + } + public executeFormat() { return Command.format() } diff --git a/src/editor/core/command/CommandAdapt.ts b/src/editor/core/command/CommandAdapt.ts index f56bf24..a26f396 100644 --- a/src/editor/core/command/CommandAdapt.ts +++ b/src/editor/core/command/CommandAdapt.ts @@ -140,6 +140,10 @@ export class CommandAdapt { this.draw.setPainterStyle(painterStyle) } + public applyPainterStyle() { + this.canvasEvent.applyPainterStyle() + } + public format() { const isReadonly = this.draw.isReadonly() if (isReadonly) return diff --git a/src/editor/core/event/CanvasEvent.ts b/src/editor/core/event/CanvasEvent.ts index 74102dc..c64343d 100644 --- a/src/editor/core/event/CanvasEvent.ts +++ b/src/editor/core/event/CanvasEvent.ts @@ -68,27 +68,30 @@ export class CanvasEvent { public setIsAllowDrag(payload: boolean) { this.isAllowDrag = payload - if (payload === false) { - this.pageList.forEach(p => { - p.style.cursor = 'text' - }) - // 应用格式刷样式 - const painterStyle = this.draw.getPainterStyle() - if (!painterStyle) return - const selection = this.range.getSelection() - if (!selection) return - const painterStyleKeys = Object.keys(painterStyle) - selection.forEach(s => { - painterStyleKeys.forEach(pKey => { - const key = pKey as keyof typeof ElementStyleKey - s[key] = painterStyle[key] as any - }) - }) - this.draw.setPainterStyle(null) - this.draw.render({ isSetCursor: false }) + if (!payload) { + this.applyPainterStyle() } } + public applyPainterStyle() { + this.pageList.forEach(p => { + p.style.cursor = 'text' + }) + const painterStyle = this.draw.getPainterStyle() + if (!painterStyle) return + const selection = this.range.getSelection() + if (!selection) return + const painterStyleKeys = Object.keys(painterStyle) + selection.forEach(s => { + painterStyleKeys.forEach(pKey => { + const key = pKey as keyof typeof ElementStyleKey + s[key] = painterStyle[key] as any + }) + }) + this.draw.setPainterStyle(null) + this.draw.render({ isSetCursor: false }) + } + public mousemove(evt: MouseEvent) { if (!this.isAllowDrag || !this.mouseDownStartPosition) return const target = evt.target as HTMLDivElement