this.data.editorCtx.format('bold', true)
我使用上面两种都有问题,正常没有加粗的文字,第一次点加粗按钮执行上面函数会加粗,但是我手机鸿蒙5.1系统第一次点没有加粗,要第二次点次我的加粗按钮,再执行上述函数才变加粗,然后第三次点就是取消加粗,第四次点就是加粗,以此类推切换。也就是说两次执行上述函数是反着来的。安卓机或者鸿蒙4没有问题。
AI说不用传第二个参数,我试了下面这个也一样的问题。
this.data.editorCtx.format('bold')
代码片段:
// 切换粗体
async toggleBold() {
if (!this.data.editorCtx) return
try {
await this.restoreSelection()
} catch (error) {
console.log('恢复选中状态失败,继续执行格式操作')
}
// 先更新状态,再执行格式操作
const newBoldState = !this.data.formatState.bold
this.setData({
'formatState.bold': newBoldState
})
this.data.editorCtx.format('bold', newBoldState)
},
