feat: add word tool

pr675
Hufe921 3 years ago
parent f189c83a51
commit 2a3c2e2ec6

@ -0,0 +1 @@
<svg width="16" height="16" xmlns="http://www.w3.org/2000/svg"><g fill="#3D4757" fill-rule="evenodd"><path d="M1 0h1v15H1zm5 4h7v1H6zm-3 6h7v1H3z"/><path d="M1 0h4v1H1zm10 14h4v1h-4zM3 7h10v1H3z"/><path d="M14 0h1v15h-1zM8 0l3 3V0zm6 0h-3v1h3zM8 15l-3-3v3zm-6-1h3v1H2z"/></g></svg>

After

Width:  |  Height:  |  Size: 281 B

@ -89,6 +89,7 @@ export class Command {
private static setLocale: CommandAdapt['setLocale']
private static getCatalog: CommandAdapt['getCatalog']
private static locationCatalog: CommandAdapt['locationCatalog']
private static wordTool: CommandAdapt['wordTool']
constructor(adapt: CommandAdapt) {
Command.mode = adapt.mode.bind(adapt)
@ -170,6 +171,7 @@ export class Command {
Command.setLocale = adapt.setLocale.bind(adapt)
Command.getCatalog = adapt.getCatalog.bind(adapt)
Command.locationCatalog = adapt.locationCatalog.bind(adapt)
Command.wordTool = adapt.wordTool.bind(adapt)
}
// 全局命令
@ -495,4 +497,8 @@ export class Command {
return Command.locationCatalog(titleId)
}
public executeWordTool() {
return Command.wordTool()
}
}

@ -1,4 +1,4 @@
import { WRAP, ZERO } from '../../dataset/constant/Common'
import { NBSP, WRAP, ZERO } from '../../dataset/constant/Common'
import { EDITOR_ELEMENT_STYLE_ATTR } from '../../dataset/constant/Element'
import { titleSizeMapping } from '../../dataset/constant/Title'
import { defaultWatermarkOption } from '../../dataset/constant/Watermark'
@ -1698,4 +1698,32 @@ export class CommandAdapt {
})
}
public wordTool() {
const elementList = this.draw.getMainElementList()
let isApply = false
for (let i = 0; i < elementList.length; i++) {
const element = elementList[i]
// 删除空行、行首空格
if (element.value === ZERO) {
while (i + 1 < elementList.length) {
const nextElement = elementList[i + 1]
if (nextElement.value !== ZERO && nextElement.value !== NBSP) break
elementList.splice(i + 1, 1)
isApply = true
}
}
}
if (!isApply) {
// 避免输入框光标丢失
const isCollapsed = this.range.getIsCollapsed()
this.draw.getCursor().drawCursor({
isShow: isCollapsed
})
} else {
this.draw.render({
isSetCursor: false
})
}
}
}

@ -40,6 +40,11 @@ export class RangeManager {
this.setRange(-1, -1)
}
public getIsCollapsed(): boolean {
const { startIndex, endIndex } = this.range
return startIndex === endIndex
}
public getSelection(): IElement[] | null {
const { startIndex, endIndex } = this.range
if (startIndex === endIndex) return null

@ -1243,6 +1243,16 @@ window.onload = function () {
}
})
}
},
{
name: '格式整理',
icon: 'word-tool',
when: (payload) => {
return !payload.isReadonly
},
callback: (command: Command) => {
command.executeWordTool()
}
}
])

@ -906,3 +906,7 @@ ul {
.ce-contextmenu-signature {
background-image: url('./assets/images/signature.svg');
}
.ce-contextmenu-word-tool {
background-image: url('./assets/images/word-tool.svg');
}
Loading…
Cancel
Save