feat: add list and title shortcuts
This commit is contained in:
+1
-1
@@ -153,7 +153,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="menu-item__list">
|
<div class="menu-item__list">
|
||||||
<i title="列表"></i>
|
<i></i>
|
||||||
<div class="options">
|
<div class="options">
|
||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>
|
||||||
|
|||||||
@@ -428,10 +428,12 @@ export class CommandAdapt {
|
|||||||
// 需要改变的元素列表
|
// 需要改变的元素列表
|
||||||
const changeElementList = this.range.getRangeElementList()
|
const changeElementList = this.range.getRangeElementList()
|
||||||
if (!changeElementList || !changeElementList.length) return
|
if (!changeElementList || !changeElementList.length) return
|
||||||
|
// 如果包含列表则设置为取消列表
|
||||||
|
const isUnsetList = changeElementList.find(el => el.listType)
|
||||||
// 设置值
|
// 设置值
|
||||||
const listId = getUUID()
|
const listId = getUUID()
|
||||||
changeElementList.forEach(el => {
|
changeElementList.forEach(el => {
|
||||||
if (listType) {
|
if (!isUnsetList && listType) {
|
||||||
el.listId = listId
|
el.listId = listId
|
||||||
el.listType = listType
|
el.listType = listType
|
||||||
el.listStyle = listStyle
|
el.listStyle = listStyle
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ import { richtextKeys } from './keys/richtextKeys'
|
|||||||
import { Command } from '../command/Command'
|
import { Command } from '../command/Command'
|
||||||
import { Draw } from '../draw/Draw'
|
import { Draw } from '../draw/Draw'
|
||||||
import { isMod } from '../../utils/hotkey'
|
import { isMod } from '../../utils/hotkey'
|
||||||
|
import { titleKeys } from './keys/titleKeys'
|
||||||
|
import { listKeys } from './keys/listKeys'
|
||||||
|
|
||||||
export class Shortcut {
|
export class Shortcut {
|
||||||
|
|
||||||
@@ -16,7 +18,9 @@ export class Shortcut {
|
|||||||
this.agentShortcutList = []
|
this.agentShortcutList = []
|
||||||
// 内部快捷键
|
// 内部快捷键
|
||||||
this._addShortcutList([
|
this._addShortcutList([
|
||||||
...richtextKeys
|
...richtextKeys,
|
||||||
|
...titleKeys,
|
||||||
|
...listKeys
|
||||||
])
|
])
|
||||||
// 全局快捷键
|
// 全局快捷键
|
||||||
this._addEvent()
|
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 titleDom = document.querySelector<HTMLDivElement>('.menu-item__title')!
|
||||||
const titleSelectDom = titleDom.querySelector<HTMLDivElement>('.select')!
|
const titleSelectDom = titleDom.querySelector<HTMLDivElement>('.select')!
|
||||||
const titleOptionDom = titleDom.querySelector<HTMLDivElement>('.options')!
|
const titleOptionDom = titleDom.querySelector<HTMLDivElement>('.options')!
|
||||||
|
titleOptionDom.querySelectorAll('li').forEach((li, index) => {
|
||||||
|
li.title = `Ctrl+${isApple ? 'Option' : 'Alt'}+${index}`
|
||||||
|
})
|
||||||
|
|
||||||
titleDom.onclick = function () {
|
titleDom.onclick = function () {
|
||||||
console.log('title')
|
console.log('title')
|
||||||
titleOptionDom.classList.toggle('visible')
|
titleOptionDom.classList.toggle('visible')
|
||||||
@@ -228,6 +232,7 @@ window.onload = function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const listDom = document.querySelector<HTMLDivElement>('.menu-item__list')!
|
const listDom = document.querySelector<HTMLDivElement>('.menu-item__list')!
|
||||||
|
listDom.title = `列表(${isApple ? '⌘' : 'Ctrl'}+Shift+U)`
|
||||||
const listOptionDom = listDom.querySelector<HTMLDivElement>('.options')!
|
const listOptionDom = listDom.querySelector<HTMLDivElement>('.options')!
|
||||||
listDom.onclick = function () {
|
listDom.onclick = function () {
|
||||||
console.log('list')
|
console.log('list')
|
||||||
|
|||||||
Reference in New Issue
Block a user