Merge pull request #83 from Hufe921/feature/shortcut

fix:evt key case conversion error
pr675
Hufe 3 years ago committed by GitHub
commit 7998d71633
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -315,8 +315,7 @@ export class CanvasEvent {
// 当前激活控件 // 当前激活控件
const isPartRangeInControlOutside = this.control.isPartRangeInControlOutside() const isPartRangeInControlOutside = this.control.isPartRangeInControlOutside()
const activeControl = this.control.getActiveControl() const activeControl = this.control.getActiveControl()
const evtKey = evt.key.toLocaleLowerCase() if (evt.key === KeyMap.Backspace) {
if (evtKey === KeyMap.Backspace) {
if (isReadonly || isPartRangeInControlOutside) return if (isReadonly || isPartRangeInControlOutside) return
let curIndex: number let curIndex: number
if (activeControl) { if (activeControl) {
@ -336,7 +335,7 @@ export class CanvasEvent {
} }
this.range.setRange(curIndex, curIndex) this.range.setRange(curIndex, curIndex)
this.draw.render({ curIndex }) this.draw.render({ curIndex })
} else if (evtKey === KeyMap.Delete) { } else if (evt.key === KeyMap.Delete) {
if (isReadonly || isPartRangeInControlOutside) return if (isReadonly || isPartRangeInControlOutside) return
let curIndex: number let curIndex: number
if (activeControl) { if (activeControl) {
@ -353,7 +352,7 @@ export class CanvasEvent {
} }
this.range.setRange(curIndex, curIndex) this.range.setRange(curIndex, curIndex)
this.draw.render({ curIndex }) this.draw.render({ curIndex })
} else if (evtKey === KeyMap.Enter) { } else if (evt.key === KeyMap.Enter) {
if (isReadonly || isPartRangeInControlOutside) return if (isReadonly || isPartRangeInControlOutside) return
// 表格需要上下文信息 // 表格需要上下文信息
const positionContext = this.position.getPositionContext() const positionContext = this.position.getPositionContext()
@ -380,7 +379,7 @@ export class CanvasEvent {
this.range.setRange(curIndex, curIndex) this.range.setRange(curIndex, curIndex)
this.draw.render({ curIndex }) this.draw.render({ curIndex })
evt.preventDefault() evt.preventDefault()
} else if (evtKey === KeyMap.Left) { } else if (evt.key === KeyMap.Left) {
if (isReadonly) return if (isReadonly) return
if (index > 0) { if (index > 0) {
const curIndex = index - 1 const curIndex = index - 1
@ -391,7 +390,7 @@ export class CanvasEvent {
isComputeRowList: false isComputeRowList: false
}) })
} }
} else if (evtKey === KeyMap.Right) { } else if (evt.key === KeyMap.Right) {
if (isReadonly) return if (isReadonly) return
if (index < position.length - 1) { if (index < position.length - 1) {
const curIndex = index + 1 const curIndex = index + 1
@ -402,12 +401,12 @@ export class CanvasEvent {
isComputeRowList: false isComputeRowList: false
}) })
} }
} else if (evtKey === KeyMap.Up || evtKey === KeyMap.Down) { } else if (evt.key === KeyMap.Up || evt.key === KeyMap.Down) {
if (isReadonly) return if (isReadonly) return
const { rowNo, index, coordinate: { leftTop, rightTop } } = cursorPosition const { rowNo, index, coordinate: { leftTop, rightTop } } = cursorPosition
if ((evtKey === KeyMap.Up && rowNo !== 0) || (evtKey === KeyMap.Down && rowNo !== this.draw.getRowCount())) { if ((evt.key === KeyMap.Up && rowNo !== 0) || (evt.key === KeyMap.Down && rowNo !== this.draw.getRowCount())) {
// 下一个光标点所在行位置集合 // 下一个光标点所在行位置集合
const probablePosition = evtKey === KeyMap.Up const probablePosition = evt.key === KeyMap.Up
? position.slice(0, index).filter(p => p.rowNo === rowNo - 1) ? position.slice(0, index).filter(p => p.rowNo === rowNo - 1)
: position.slice(index, position.length - 1).filter(p => p.rowNo === rowNo + 1) : position.slice(index, position.length - 1).filter(p => p.rowNo === rowNo + 1)
// 查找与当前位置元素点交叉最多的位置 // 查找与当前位置元素点交叉最多的位置
@ -444,56 +443,57 @@ export class CanvasEvent {
isComputeRowList: false isComputeRowList: false
}) })
} }
} else if (evt.ctrlKey && evtKey === KeyMap.Z) { } else if (evt.ctrlKey && evt.key === KeyMap.Z) {
if (isReadonly) return if (isReadonly) return
this.historyManager.undo() this.historyManager.undo()
evt.preventDefault() evt.preventDefault()
} else if (evt.ctrlKey && evtKey === KeyMap.Y) { } else if (evt.ctrlKey && evt.key === KeyMap.Y) {
if (isReadonly) return if (isReadonly) return
this.historyManager.redo() this.historyManager.redo()
evt.preventDefault() evt.preventDefault()
} else if (evt.ctrlKey && evtKey === KeyMap.C) { } else if (evt.ctrlKey && evt.key === KeyMap.C) {
this.copy() this.copy()
} else if (evt.ctrlKey && evtKey === KeyMap.X) { } else if (evt.ctrlKey && evt.key.toLocaleLowerCase() === KeyMap.X) {
if (isReadonly) return if (isReadonly) return
if (evt.shiftKey) { if (evt.shiftKey) {
this.strikeout() this.strikeout()
} else { } else {
this.cut() this.cut()
} }
} else if (evt.ctrlKey && evtKey === KeyMap.A) { } else if (evt.ctrlKey && evt.key === KeyMap.A) {
this.selectAll() this.selectAll()
} else if (evt.ctrlKey && evtKey === KeyMap.S) { } else if (evt.ctrlKey && evt.key === KeyMap.S) {
if (isReadonly) return if (isReadonly) return
if (this.listener.saved) { if (this.listener.saved) {
this.listener.saved(this.draw.getValue()) this.listener.saved(this.draw.getValue())
} }
evt.preventDefault() evt.preventDefault()
} else if (evt.ctrlKey && evtKey === KeyMap.LEFT_BRACKET) { } else if (evt.ctrlKey && evt.key === KeyMap.LEFT_BRACKET) {
this.sizeAdd() this.sizeAdd()
} else if (evt.ctrlKey && evtKey === KeyMap.RIGHT_BRACKET) { } else if (evt.ctrlKey && evt.key === KeyMap.RIGHT_BRACKET) {
this.sizeMinus() this.sizeMinus()
} else if (evt.ctrlKey && evtKey === KeyMap.B) { } else if (evt.ctrlKey && evt.key === KeyMap.B) {
this.bold() this.bold()
} else if (evt.ctrlKey && evtKey === KeyMap.I) { } else if (evt.ctrlKey && evt.key === KeyMap.I) {
this.italic() this.italic()
} else if (evt.ctrlKey && evtKey === KeyMap.U) { } else if (evt.ctrlKey && evt.key === KeyMap.U) {
this.underline() this.underline()
} else if (evt.ctrlKey && evt.shiftKey && evtKey === KeyMap.RIGHT_ANGLE_BRACKET) { evt.preventDefault()
} else if (evt.ctrlKey && evt.shiftKey && evt.key === KeyMap.RIGHT_ANGLE_BRACKET) {
this.superscript() this.superscript()
} else if (evt.ctrlKey && evt.shiftKey && evtKey === KeyMap.LEFT_ANGLE_BRACKET) { } else if (evt.ctrlKey && evt.shiftKey && evt.key === KeyMap.LEFT_ANGLE_BRACKET) {
this.subscript() this.subscript()
} else if (evt.ctrlKey && evtKey === KeyMap.L) { } else if (evt.ctrlKey && evt.key === KeyMap.L) {
this.rowFlex(RowFlex.LEFT) this.rowFlex(RowFlex.LEFT)
} else if (evt.ctrlKey && evtKey === KeyMap.E) { } else if (evt.ctrlKey && evt.key === KeyMap.E) {
this.rowFlex(RowFlex.CENTER) this.rowFlex(RowFlex.CENTER)
} else if (evt.ctrlKey && evtKey === KeyMap.R) { } else if (evt.ctrlKey && evt.key === KeyMap.R) {
this.rowFlex(RowFlex.RIGHT) this.rowFlex(RowFlex.RIGHT)
} else if (evt.ctrlKey && evtKey === KeyMap.J) { } else if (evt.ctrlKey && evt.key === KeyMap.J) {
this.rowFlex(RowFlex.ALIGNMENT) this.rowFlex(RowFlex.ALIGNMENT)
} else if (evtKey === KeyMap.ESC) { } else if (evt.key === KeyMap.ESC) {
this.clearPainterStyle() this.clearPainterStyle()
} else if (evtKey === KeyMap.TAB) { } else if (evt.key === KeyMap.TAB) {
this.draw.insertElementList([{ this.draw.insertElementList([{
type: ElementType.TAB, type: ElementType.TAB,
value: '' value: ''

Loading…
Cancel
Save