feat: add parameter for clearing font color and highlight color #461

pr675
Hufe921 2 years ago
parent a058c5956c
commit 73f9cfdf88

@ -284,7 +284,7 @@ Feature: Font color
Usage: Usage:
```javascript ```javascript
instance.command.executeColor() instance.command.executeColor(color: string | null)
``` ```
## executeHighlight ## executeHighlight
@ -294,7 +294,7 @@ Feature: Highlight
Usage: Usage:
```javascript ```javascript
instance.command.executeHighlight() instance.command.executeHighlight(color: string | null)
``` ```
## executeTitle ## executeTitle

@ -284,7 +284,7 @@ instance.command.executeSubscript()
用法: 用法:
```javascript ```javascript
instance.command.executeColor() instance.command.executeColor(color: string | null)
``` ```
## executeHighlight ## executeHighlight
@ -294,7 +294,7 @@ instance.command.executeColor()
用法: 用法:
```javascript ```javascript
instance.command.executeHighlight() instance.command.executeHighlight(color: string | null)
``` ```
## executeTitle ## executeTitle

@ -616,14 +616,18 @@ export class CommandAdapt {
this.draw.render({ isSetCursor: false }) this.draw.render({ isSetCursor: false })
} }
public color(payload: string) { public color(payload: string | null) {
const isDisabled = const isDisabled =
this.draw.isReadonly() || this.control.isDisabledControl() this.draw.isReadonly() || this.control.isDisabledControl()
if (isDisabled) return if (isDisabled) return
const selection = this.range.getSelectionElementList() const selection = this.range.getSelectionElementList()
if (selection?.length) { if (selection?.length) {
selection.forEach(el => { selection.forEach(el => {
el.color = payload if (payload) {
el.color = payload
} else {
delete el.color
}
}) })
this.draw.render({ this.draw.render({
isSetCursor: false, isSetCursor: false,
@ -634,20 +638,28 @@ export class CommandAdapt {
const elementList = this.draw.getElementList() const elementList = this.draw.getElementList()
const enterElement = elementList[endIndex] const enterElement = elementList[endIndex]
if (enterElement?.value === ZERO) { if (enterElement?.value === ZERO) {
enterElement.color = payload if (payload) {
enterElement.color = payload
} else {
delete enterElement.color
}
this.draw.render({ curIndex: endIndex, isCompute: false }) this.draw.render({ curIndex: endIndex, isCompute: false })
} }
} }
} }
public highlight(payload: string) { public highlight(payload: string | null) {
const isDisabled = const isDisabled =
this.draw.isReadonly() || this.control.isDisabledControl() this.draw.isReadonly() || this.control.isDisabledControl()
if (isDisabled) return if (isDisabled) return
const selection = this.range.getSelectionElementList() const selection = this.range.getSelectionElementList()
if (selection?.length) { if (selection?.length) {
selection.forEach(el => { selection.forEach(el => {
el.highlight = payload if (payload) {
el.highlight = payload
} else {
delete el.highlight
}
}) })
this.draw.render({ this.draw.render({
isSetCursor: false, isSetCursor: false,
@ -658,7 +670,11 @@ export class CommandAdapt {
const elementList = this.draw.getElementList() const elementList = this.draw.getElementList()
const enterElement = elementList[endIndex] const enterElement = elementList[endIndex]
if (enterElement?.value === ZERO) { if (enterElement?.value === ZERO) {
enterElement.highlight = payload if (payload) {
enterElement.highlight = payload
} else {
delete enterElement.highlight
}
this.draw.render({ curIndex: endIndex, isCompute: false }) this.draw.render({ curIndex: endIndex, isCompute: false })
} }
} }

Loading…
Cancel
Save