Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable keyfilter only for keydown, keyup, and keypress. #613

Merged
merged 4 commits into from Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/core/action_descriptor.ts
Expand Up @@ -44,13 +44,21 @@ const descriptorPattern = /^(?:(.+?)(?:\.(.+?))?(?:@(window|document))?->)?(.+?)
export function parseActionDescriptorString(descriptorString: string): Partial<ActionDescriptor> {
const source = descriptorString.trim()
const matches = source.match(descriptorPattern) || []
let eventName = matches[1]
let keyFilter = matches[2]

if (keyFilter && !["keydown", "keyup", "keypress"].includes(eventName)) {
eventName += `.${keyFilter}`
keyFilter = ""
}

return {
eventTarget: parseEventTarget(matches[3]),
eventName: matches[1],
eventName,
eventOptions: matches[6] ? parseEventOptions(matches[6]) : {},
identifier: matches[4],
methodName: matches[5],
keyFilter: matches[2],
keyFilter,
}
}

Expand Down
15 changes: 15 additions & 0 deletions src/tests/modules/core/action_keyboard_filter_tests.ts
Expand Up @@ -21,6 +21,7 @@ export default class ActionKeyboardFilterTests extends LogControllerTestCase {
<button id="button7"></button>
<button id="button8" data-action="keydown.a->a#log keydown.b->a#log2"></button>
<button id="button9" data-action="keydown.shift+a->a#log keydown.a->a#log2 keydown.ctrl+shift+a->a#log3">
<button id="button10" data-action="jquery.custom.event->a#log jquery.a->a#log2">
</div>
`

Expand Down Expand Up @@ -182,4 +183,18 @@ export default class ActionKeyboardFilterTests extends LogControllerTestCase {
await this.triggerKeyboardEvent(button, "keydown", { key: "A", ctrlKey: true, shiftKey: true })
this.assertActions({ name: "log3", identifier: "a", eventType: "keydown", currentTarget: button })
}

async "test ignore filter syntax when not a keyboard event"() {
const button = this.findElement("#button10")
await this.nextFrame
await this.triggerEvent(button, "jquery.custom.event")
this.assertActions({ name: "log", identifier: "a", eventType: "jquery.custom.event", currentTarget: button })
}

async "test ignore filter syntax when not a keyboard event (case2)"() {
const button = this.findElement("#button10")
await this.nextFrame
await this.triggerEvent(button, "jquery.a")
this.assertActions({ name: "log2", identifier: "a", eventType: "jquery.a", currentTarget: button })
}
}