feat:support mac os shortcut
This commit is contained in:
@@ -2,6 +2,7 @@ import { ZERO } from '../../../dataset/constant/Common'
|
||||
import { ElementType } from '../../../dataset/enum/Element'
|
||||
import { KeyMap } from '../../../dataset/enum/KeyMap'
|
||||
import { IElement, IElementPosition } from '../../../interface/Element'
|
||||
import { isMod } from '../../../utils/hotkey'
|
||||
import { CanvasEvent } from '../CanvasEvent'
|
||||
|
||||
export function keydown(evt: KeyboardEvent, host: CanvasEvent) {
|
||||
@@ -230,24 +231,24 @@ export function keydown(evt: KeyboardEvent, host: CanvasEvent) {
|
||||
isComputeRowList: false
|
||||
})
|
||||
}
|
||||
} else if (evt.ctrlKey && evt.key === KeyMap.Z) {
|
||||
} else if (isMod(evt) && evt.key === KeyMap.Z) {
|
||||
if (isReadonly) return
|
||||
historyManager.undo()
|
||||
evt.preventDefault()
|
||||
} else if (evt.ctrlKey && evt.key === KeyMap.Y) {
|
||||
} else if (isMod(evt) && evt.key === KeyMap.Y) {
|
||||
if (isReadonly) return
|
||||
historyManager.redo()
|
||||
evt.preventDefault()
|
||||
} else if (evt.ctrlKey && evt.key === KeyMap.C) {
|
||||
} else if (isMod(evt) && evt.key === KeyMap.C) {
|
||||
host.copy()
|
||||
evt.preventDefault()
|
||||
} else if (evt.ctrlKey && evt.key === KeyMap.X) {
|
||||
} else if (isMod(evt) && evt.key === KeyMap.X) {
|
||||
host.cut()
|
||||
evt.preventDefault()
|
||||
} else if (evt.ctrlKey && evt.key === KeyMap.A) {
|
||||
} else if (isMod(evt) && evt.key === KeyMap.A) {
|
||||
host.selectAll()
|
||||
evt.preventDefault()
|
||||
} else if (evt.ctrlKey && evt.key === KeyMap.S) {
|
||||
} else if (isMod(evt) && evt.key === KeyMap.S) {
|
||||
if (isReadonly) return
|
||||
const listener = draw.getListener()
|
||||
if (listener.saved) {
|
||||
|
||||
@@ -2,6 +2,7 @@ import { IRegisterShortcut } from '../../interface/shortcut/Shortcut'
|
||||
import { richtextKeys } from './keys/richtextKeys'
|
||||
import { Command } from '../command/Command'
|
||||
import { Draw } from '../draw/Draw'
|
||||
import { isMod } from '../../utils/hotkey'
|
||||
|
||||
export class Shortcut {
|
||||
|
||||
@@ -64,6 +65,7 @@ export class Shortcut {
|
||||
evt.ctrlKey === !!shortCut.ctrl &&
|
||||
evt.shiftKey === !!shortCut.shift &&
|
||||
evt.altKey === !!shortCut.alt &&
|
||||
isMod(evt) === !!shortCut.mod &&
|
||||
evt.key === shortCut.key
|
||||
) {
|
||||
shortCut.callback(this.command)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Command } from '../../..'
|
||||
import { KeyMap } from '../../../dataset/enum/KeyMap'
|
||||
import { IRegisterShortcut } from '../../../interface/shortcut/Shortcut'
|
||||
import { isApple } from '../../../utils/ua'
|
||||
|
||||
export const richtextKeys: IRegisterShortcut[] = [
|
||||
{
|
||||
@@ -13,50 +14,50 @@ export const richtextKeys: IRegisterShortcut[] = [
|
||||
},
|
||||
{
|
||||
key: KeyMap.LEFT_BRACKET,
|
||||
ctrl: true,
|
||||
mod: true,
|
||||
callback: (command: Command) => {
|
||||
command.executeSizeAdd()
|
||||
}
|
||||
},
|
||||
{
|
||||
key: KeyMap.RIGHT_BRACKET,
|
||||
ctrl: true,
|
||||
mod: true,
|
||||
callback: (command: Command) => {
|
||||
command.executeSizeMinus()
|
||||
}
|
||||
},
|
||||
{
|
||||
key: KeyMap.B,
|
||||
ctrl: true,
|
||||
mod: true,
|
||||
callback: (command: Command) => {
|
||||
command.executeBold()
|
||||
}
|
||||
},
|
||||
{
|
||||
key: KeyMap.I,
|
||||
ctrl: true,
|
||||
mod: true,
|
||||
callback: (command: Command) => {
|
||||
command.executeItalic()
|
||||
}
|
||||
},
|
||||
{
|
||||
key: KeyMap.U,
|
||||
ctrl: true,
|
||||
mod: true,
|
||||
callback: (command: Command) => {
|
||||
command.executeUnderline()
|
||||
}
|
||||
},
|
||||
{
|
||||
key: KeyMap.RIGHT_ANGLE_BRACKET,
|
||||
ctrl: true,
|
||||
key: isApple ? KeyMap.COMMA : KeyMap.RIGHT_ANGLE_BRACKET,
|
||||
mod: true,
|
||||
shift: true,
|
||||
callback: (command: Command) => {
|
||||
command.executeSuperscript()
|
||||
}
|
||||
},
|
||||
{
|
||||
key: KeyMap.LEFT_ANGLE_BRACKET,
|
||||
ctrl: true,
|
||||
key: isApple ? KeyMap.PERIOD : KeyMap.LEFT_ANGLE_BRACKET,
|
||||
mod: true,
|
||||
shift: true,
|
||||
callback: (command: Command) => {
|
||||
command.executeSubscript()
|
||||
@@ -64,28 +65,28 @@ export const richtextKeys: IRegisterShortcut[] = [
|
||||
},
|
||||
{
|
||||
key: KeyMap.L,
|
||||
ctrl: true,
|
||||
mod: true,
|
||||
callback: (command: Command) => {
|
||||
command.executeLeft()
|
||||
}
|
||||
},
|
||||
{
|
||||
key: KeyMap.E,
|
||||
ctrl: true,
|
||||
mod: true,
|
||||
callback: (command: Command) => {
|
||||
command.executeCenter()
|
||||
}
|
||||
},
|
||||
{
|
||||
key: KeyMap.R,
|
||||
ctrl: true,
|
||||
mod: true,
|
||||
callback: (command: Command) => {
|
||||
command.executeRight()
|
||||
}
|
||||
},
|
||||
{
|
||||
key: KeyMap.J,
|
||||
ctrl: true,
|
||||
mod: true,
|
||||
callback: (command: Command) => {
|
||||
command.executeAlignment()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user