Skip to content

Commit

Permalink
fix: not trigger keyboard event whith delete key in contenteditable e…
Browse files Browse the repository at this point in the history
…lem (#2965)
  • Loading branch information
NewByVector authored Nov 29, 2022
1 parent 8eb4387 commit 4978110
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ module.exports = function (config, base, karmaTypescriptConfig) {
},
coverageOptions: {
instrumentation: !isDebug,
exclude: /\.test|spec\.ts$/,
exclude: /(\.test)|(spec\.ts$)/,
},
reports: {
html: reportsDir,
Expand Down
9 changes: 6 additions & 3 deletions packages/x6-plugin-keyboard/src/keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,18 @@ export class KeyboardImpl extends Disposable implements IDisablable {
isInputEvent(e: KeyboardEvent | Dom.MouseUpEvent) {
const target = e.target as Element
const tagName = target?.tagName?.toLowerCase()
return ['input', 'textarea'].includes(tagName)
let isInput = ['input', 'textarea'].includes(tagName)
if (Dom.attr(target, 'contenteditable') === 'true') {
isInput = true
}
return isInput
}

isEnabledForEvent(e: KeyboardEvent) {
const allowed = !this.disabled && this.isGraphEvent(e)
const isInputEvent = this.isInputEvent(e)
if (allowed) {
const code = e.keyCode || e.which
if (isInputEvent && (code === 8 || code === 46)) {
if (isInputEvent && (e.key === 'Backspace' || e.key === 'Delete')) {
return false
}
if (this.options.guard) {
Expand Down

0 comments on commit 4978110

Please sign in to comment.