feat: add list and title shortcuts

pr675
Hufe921 3 years ago
parent 797b9a14df
commit bb2875516c

@ -153,7 +153,7 @@
</div>
</div>
<div class="menu-item__list">
<i title="列表"></i>
<i></i>
<div class="options">
<ul>
<li>

@ -428,10 +428,12 @@ export class CommandAdapt {
// 需要改变的元素列表
const changeElementList = this.range.getRangeElementList()
if (!changeElementList || !changeElementList.length) return
// 如果包含列表则设置为取消列表
const isUnsetList = changeElementList.find(el => el.listType)
// 设置值
const listId = getUUID()
changeElementList.forEach(el => {
if (listType) {
if (!isUnsetList && listType) {
el.listId = listId
el.listType = listType
el.listStyle = listStyle

@ -3,6 +3,8 @@ import { richtextKeys } from './keys/richtextKeys'
import { Command } from '../command/Command'
import { Draw } from '../draw/Draw'
import { isMod } from '../../utils/hotkey'
import { titleKeys } from './keys/titleKeys'
import { listKeys } from './keys/listKeys'
export class Shortcut {
@ -16,7 +18,9 @@ export class Shortcut {
this.agentShortcutList = []
// 内部快捷键
this._addShortcutList([
...richtextKeys
...richtextKeys,
...titleKeys,
...listKeys
])
// 全局快捷键
this._addEvent()

@ -0,0 +1,22 @@
import { Command, ListStyle, ListType } from '../../..'
import { KeyMap } from '../../../dataset/enum/KeyMap'
import { IRegisterShortcut } from '../../../interface/shortcut/Shortcut'
export const listKeys: IRegisterShortcut[] = [
{
key: KeyMap.I,
shift: true,
mod: true,
callback: (command: Command) => {
command.executeList(ListType.UL, ListStyle.DISC)
}
},
{
key: KeyMap.U,
shift: true,
mod: true,
callback: (command: Command) => {
command.executeList(ListType.OL)
}
}
]

@ -0,0 +1,56 @@
import { Command, TitleLevel } from '../../..'
import { KeyMap } from '../../../dataset/enum/KeyMap'
import { IRegisterShortcut } from '../../../interface/shortcut/Shortcut'
export const titleKeys: IRegisterShortcut[] = [
{
key: KeyMap.ZERO,
alt: true,
ctrl: true,
callback: (command: Command) => {
command.executeTitle(null)
}
}, {
key: KeyMap.ONE,
alt: true,
ctrl: true,
callback: (command: Command) => {
command.executeTitle(TitleLevel.FIRST)
}
}, {
key: KeyMap.TWO,
alt: true,
ctrl: true,
callback: (command: Command) => {
command.executeTitle(TitleLevel.SECOND)
}
}, {
key: KeyMap.THREE,
alt: true,
ctrl: true,
callback: (command: Command) => {
command.executeTitle(TitleLevel.THIRD)
}
}, {
key: KeyMap.FOUR,
alt: true,
ctrl: true,
callback: (command: Command) => {
command.executeTitle(TitleLevel.FOURTH)
}
}, {
key: KeyMap.FIVE,
alt: true,
ctrl: true,
callback: (command: Command) => {
command.executeTitle(TitleLevel.FIFTH)
}
}, {
key: KeyMap.SIX,
alt: true,
ctrl: true,
callback: (command: Command) => {
command.executeTitle(TitleLevel.SIXTH)
}
}
]

@ -178,6 +178,10 @@ window.onload = function () {
const titleDom = document.querySelector<HTMLDivElement>('.menu-item__title')!
const titleSelectDom = titleDom.querySelector<HTMLDivElement>('.select')!
const titleOptionDom = titleDom.querySelector<HTMLDivElement>('.options')!
titleOptionDom.querySelectorAll('li').forEach((li, index) => {
li.title = `Ctrl+${isApple ? 'Option' : 'Alt'}+${index}`
})
titleDom.onclick = function () {
console.log('title')
titleOptionDom.classList.toggle('visible')
@ -228,6 +232,7 @@ window.onload = function () {
}
const listDom = document.querySelector<HTMLDivElement>('.menu-item__list')!
listDom.title = `列表(${isApple ? '⌘' : 'Ctrl'}+Shift+U)`
const listOptionDom = listDom.querySelector<HTMLDivElement>('.options')!
listDom.onclick = function () {
console.log('list')

Loading…
Cancel
Save