From 73f9cfdf88afcfab4376bf3c4011b171c0669d2f Mon Sep 17 00:00:00 2001 From: Hufe921 Date: Wed, 13 Mar 2024 20:58:53 +0800 Subject: [PATCH] feat: add parameter for clearing font color and highlight color #461 --- docs/en/guide/command-execute.md | 4 ++-- docs/guide/command-execute.md | 4 ++-- src/editor/core/command/CommandAdapt.ts | 28 +++++++++++++++++++------ 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/docs/en/guide/command-execute.md b/docs/en/guide/command-execute.md index 67e522e..989204f 100644 --- a/docs/en/guide/command-execute.md +++ b/docs/en/guide/command-execute.md @@ -284,7 +284,7 @@ Feature: Font color Usage: ```javascript -instance.command.executeColor() +instance.command.executeColor(color: string | null) ``` ## executeHighlight @@ -294,7 +294,7 @@ Feature: Highlight Usage: ```javascript -instance.command.executeHighlight() +instance.command.executeHighlight(color: string | null) ``` ## executeTitle diff --git a/docs/guide/command-execute.md b/docs/guide/command-execute.md index 307268f..8f3e768 100644 --- a/docs/guide/command-execute.md +++ b/docs/guide/command-execute.md @@ -284,7 +284,7 @@ instance.command.executeSubscript() 用法: ```javascript -instance.command.executeColor() +instance.command.executeColor(color: string | null) ``` ## executeHighlight @@ -294,7 +294,7 @@ instance.command.executeColor() 用法: ```javascript -instance.command.executeHighlight() +instance.command.executeHighlight(color: string | null) ``` ## executeTitle diff --git a/src/editor/core/command/CommandAdapt.ts b/src/editor/core/command/CommandAdapt.ts index 0fbe282..6fe10fc 100644 --- a/src/editor/core/command/CommandAdapt.ts +++ b/src/editor/core/command/CommandAdapt.ts @@ -616,14 +616,18 @@ export class CommandAdapt { this.draw.render({ isSetCursor: false }) } - public color(payload: string) { + public color(payload: string | null) { const isDisabled = this.draw.isReadonly() || this.control.isDisabledControl() if (isDisabled) return const selection = this.range.getSelectionElementList() if (selection?.length) { selection.forEach(el => { - el.color = payload + if (payload) { + el.color = payload + } else { + delete el.color + } }) this.draw.render({ isSetCursor: false, @@ -634,20 +638,28 @@ export class CommandAdapt { const elementList = this.draw.getElementList() const enterElement = elementList[endIndex] if (enterElement?.value === ZERO) { - enterElement.color = payload + if (payload) { + enterElement.color = payload + } else { + delete enterElement.color + } this.draw.render({ curIndex: endIndex, isCompute: false }) } } } - public highlight(payload: string) { + public highlight(payload: string | null) { const isDisabled = this.draw.isReadonly() || this.control.isDisabledControl() if (isDisabled) return const selection = this.range.getSelectionElementList() if (selection?.length) { selection.forEach(el => { - el.highlight = payload + if (payload) { + el.highlight = payload + } else { + delete el.highlight + } }) this.draw.render({ isSetCursor: false, @@ -658,7 +670,11 @@ export class CommandAdapt { const elementList = this.draw.getElementList() const enterElement = elementList[endIndex] if (enterElement?.value === ZERO) { - enterElement.highlight = payload + if (payload) { + enterElement.highlight = payload + } else { + delete enterElement.highlight + } this.draw.render({ curIndex: endIndex, isCompute: false }) } }