@@ -2,6 +2,7 @@ import { ZERO } from '../../../dataset/constant/Common'
|
|||||||
import { ElementType } from '../../../dataset/enum/Element'
|
import { ElementType } from '../../../dataset/enum/Element'
|
||||||
import { KeyMap } from '../../../dataset/enum/KeyMap'
|
import { KeyMap } from '../../../dataset/enum/KeyMap'
|
||||||
import { IElement, IElementPosition } from '../../../interface/Element'
|
import { IElement, IElementPosition } from '../../../interface/Element'
|
||||||
|
import { isMod } from '../../../utils/hotkey'
|
||||||
import { CanvasEvent } from '../CanvasEvent'
|
import { CanvasEvent } from '../CanvasEvent'
|
||||||
|
|
||||||
export function keydown(evt: KeyboardEvent, host: CanvasEvent) {
|
export function keydown(evt: KeyboardEvent, host: CanvasEvent) {
|
||||||
@@ -230,24 +231,24 @@ export function keydown(evt: KeyboardEvent, host: CanvasEvent) {
|
|||||||
isComputeRowList: false
|
isComputeRowList: false
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
} else if (evt.ctrlKey && evt.key === KeyMap.Z) {
|
} else if (isMod(evt) && evt.key === KeyMap.Z) {
|
||||||
if (isReadonly) return
|
if (isReadonly) return
|
||||||
historyManager.undo()
|
historyManager.undo()
|
||||||
evt.preventDefault()
|
evt.preventDefault()
|
||||||
} else if (evt.ctrlKey && evt.key === KeyMap.Y) {
|
} else if (isMod(evt) && evt.key === KeyMap.Y) {
|
||||||
if (isReadonly) return
|
if (isReadonly) return
|
||||||
historyManager.redo()
|
historyManager.redo()
|
||||||
evt.preventDefault()
|
evt.preventDefault()
|
||||||
} else if (evt.ctrlKey && evt.key === KeyMap.C) {
|
} else if (isMod(evt) && evt.key === KeyMap.C) {
|
||||||
host.copy()
|
host.copy()
|
||||||
evt.preventDefault()
|
evt.preventDefault()
|
||||||
} else if (evt.ctrlKey && evt.key === KeyMap.X) {
|
} else if (isMod(evt) && evt.key === KeyMap.X) {
|
||||||
host.cut()
|
host.cut()
|
||||||
evt.preventDefault()
|
evt.preventDefault()
|
||||||
} else if (evt.ctrlKey && evt.key === KeyMap.A) {
|
} else if (isMod(evt) && evt.key === KeyMap.A) {
|
||||||
host.selectAll()
|
host.selectAll()
|
||||||
evt.preventDefault()
|
evt.preventDefault()
|
||||||
} else if (evt.ctrlKey && evt.key === KeyMap.S) {
|
} else if (isMod(evt) && evt.key === KeyMap.S) {
|
||||||
if (isReadonly) return
|
if (isReadonly) return
|
||||||
const listener = draw.getListener()
|
const listener = draw.getListener()
|
||||||
if (listener.saved) {
|
if (listener.saved) {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { IRegisterShortcut } from '../../interface/shortcut/Shortcut'
|
|||||||
import { richtextKeys } from './keys/richtextKeys'
|
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'
|
||||||
|
|
||||||
export class Shortcut {
|
export class Shortcut {
|
||||||
|
|
||||||
@@ -61,7 +62,11 @@ export class Shortcut {
|
|||||||
for (let s = 0; s < shortCutList.length; s++) {
|
for (let s = 0; s < shortCutList.length; s++) {
|
||||||
const shortCut = shortCutList[s]
|
const shortCut = shortCutList[s]
|
||||||
if (
|
if (
|
||||||
evt.ctrlKey === !!shortCut.ctrl &&
|
(
|
||||||
|
shortCut.mod
|
||||||
|
? isMod(evt) === !!shortCut.mod
|
||||||
|
: evt.ctrlKey === !!shortCut.ctrl && evt.metaKey === !!shortCut.meta
|
||||||
|
) &&
|
||||||
evt.shiftKey === !!shortCut.shift &&
|
evt.shiftKey === !!shortCut.shift &&
|
||||||
evt.altKey === !!shortCut.alt &&
|
evt.altKey === !!shortCut.alt &&
|
||||||
evt.key === shortCut.key
|
evt.key === shortCut.key
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { Command } from '../../..'
|
import { Command } from '../../..'
|
||||||
import { KeyMap } from '../../../dataset/enum/KeyMap'
|
import { KeyMap } from '../../../dataset/enum/KeyMap'
|
||||||
import { IRegisterShortcut } from '../../../interface/shortcut/Shortcut'
|
import { IRegisterShortcut } from '../../../interface/shortcut/Shortcut'
|
||||||
|
import { isApple } from '../../../utils/ua'
|
||||||
|
|
||||||
export const richtextKeys: IRegisterShortcut[] = [
|
export const richtextKeys: IRegisterShortcut[] = [
|
||||||
{
|
{
|
||||||
@@ -13,50 +14,50 @@ export const richtextKeys: IRegisterShortcut[] = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: KeyMap.LEFT_BRACKET,
|
key: KeyMap.LEFT_BRACKET,
|
||||||
ctrl: true,
|
mod: true,
|
||||||
callback: (command: Command) => {
|
callback: (command: Command) => {
|
||||||
command.executeSizeAdd()
|
command.executeSizeAdd()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: KeyMap.RIGHT_BRACKET,
|
key: KeyMap.RIGHT_BRACKET,
|
||||||
ctrl: true,
|
mod: true,
|
||||||
callback: (command: Command) => {
|
callback: (command: Command) => {
|
||||||
command.executeSizeMinus()
|
command.executeSizeMinus()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: KeyMap.B,
|
key: KeyMap.B,
|
||||||
ctrl: true,
|
mod: true,
|
||||||
callback: (command: Command) => {
|
callback: (command: Command) => {
|
||||||
command.executeBold()
|
command.executeBold()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: KeyMap.I,
|
key: KeyMap.I,
|
||||||
ctrl: true,
|
mod: true,
|
||||||
callback: (command: Command) => {
|
callback: (command: Command) => {
|
||||||
command.executeItalic()
|
command.executeItalic()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: KeyMap.U,
|
key: KeyMap.U,
|
||||||
ctrl: true,
|
mod: true,
|
||||||
callback: (command: Command) => {
|
callback: (command: Command) => {
|
||||||
command.executeUnderline()
|
command.executeUnderline()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: KeyMap.RIGHT_ANGLE_BRACKET,
|
key: isApple ? KeyMap.COMMA : KeyMap.RIGHT_ANGLE_BRACKET,
|
||||||
ctrl: true,
|
mod: true,
|
||||||
shift: true,
|
shift: true,
|
||||||
callback: (command: Command) => {
|
callback: (command: Command) => {
|
||||||
command.executeSuperscript()
|
command.executeSuperscript()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: KeyMap.LEFT_ANGLE_BRACKET,
|
key: isApple ? KeyMap.PERIOD : KeyMap.LEFT_ANGLE_BRACKET,
|
||||||
ctrl: true,
|
mod: true,
|
||||||
shift: true,
|
shift: true,
|
||||||
callback: (command: Command) => {
|
callback: (command: Command) => {
|
||||||
command.executeSubscript()
|
command.executeSubscript()
|
||||||
@@ -64,28 +65,28 @@ export const richtextKeys: IRegisterShortcut[] = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: KeyMap.L,
|
key: KeyMap.L,
|
||||||
ctrl: true,
|
mod: true,
|
||||||
callback: (command: Command) => {
|
callback: (command: Command) => {
|
||||||
command.executeLeft()
|
command.executeLeft()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: KeyMap.E,
|
key: KeyMap.E,
|
||||||
ctrl: true,
|
mod: true,
|
||||||
callback: (command: Command) => {
|
callback: (command: Command) => {
|
||||||
command.executeCenter()
|
command.executeCenter()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: KeyMap.R,
|
key: KeyMap.R,
|
||||||
ctrl: true,
|
mod: true,
|
||||||
callback: (command: Command) => {
|
callback: (command: Command) => {
|
||||||
command.executeRight()
|
command.executeRight()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: KeyMap.J,
|
key: KeyMap.J,
|
||||||
ctrl: true,
|
mod: true,
|
||||||
callback: (command: Command) => {
|
callback: (command: Command) => {
|
||||||
command.executeAlignment()
|
command.executeAlignment()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ export enum KeyMap {
|
|||||||
Down = 'ArrowDown',
|
Down = 'ArrowDown',
|
||||||
ESC = 'Escape',
|
ESC = 'Escape',
|
||||||
TAB = 'Tab',
|
TAB = 'Tab',
|
||||||
|
META = 'Meta',
|
||||||
LEFT_BRACKET = '[',
|
LEFT_BRACKET = '[',
|
||||||
RIGHT_BRACKET = ']',
|
RIGHT_BRACKET = ']',
|
||||||
COMMA = ',',
|
COMMA = ',',
|
||||||
|
|||||||
@@ -4,8 +4,10 @@ import { KeyMap } from '../../dataset/enum/KeyMap'
|
|||||||
export interface IRegisterShortcut {
|
export interface IRegisterShortcut {
|
||||||
key: KeyMap;
|
key: KeyMap;
|
||||||
ctrl?: boolean;
|
ctrl?: boolean;
|
||||||
|
meta?: boolean;
|
||||||
|
mod?: boolean; // windows:ctrl || mac:command
|
||||||
shift?: boolean;
|
shift?: boolean;
|
||||||
alt?: boolean;
|
alt?: boolean; // windows:alt || mac:option
|
||||||
isGlobal?: boolean;
|
isGlobal?: boolean;
|
||||||
callback: (command: Command) => any;
|
callback: (command: Command) => any;
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import { isApple } from './ua'
|
||||||
|
|
||||||
|
export function isMod(evt: KeyboardEvent) {
|
||||||
|
return isApple ? evt.metaKey : evt.ctrlKey
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export const isApple = typeof navigator !== 'undefined' && /Mac OS X/.test(navigator.userAgent)
|
||||||
Reference in New Issue
Block a user