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

fix: Shortcut helper firing when it shouldn't #18864

Merged
merged 10 commits into from
Nov 27, 2023
4 changes: 4 additions & 0 deletions frontend/src/lib/components/CommandBar/commandBarLogic.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { actions, afterMount, beforeUnmount, kea, path, reducers } from 'kea'
import { shouldIgnoreInput } from 'lib/utils'

import type { commandBarLogicType } from './commandBarLogicType'
import { BarStatus } from './types'
Expand Down Expand Up @@ -34,6 +35,9 @@ export const commandBarLogic = kea<commandBarLogicType>([
afterMount(({ actions, cache }) => {
// register keyboard shortcuts
cache.onKeyDown = (event: KeyboardEvent) => {
if (shouldIgnoreInput(event)) {
return
}
if ((event.ctrlKey || event.metaKey) && event.key === 'k') {
event.preventDefault()
if (event.shiftKey) {
Expand Down
11 changes: 1 addition & 10 deletions frontend/src/lib/components/HedgehogBuddy/HedgehogBuddy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useValues } from 'kea'
import { LemonButton } from 'lib/lemon-ui/LemonButton'
import { LemonDivider } from 'lib/lemon-ui/LemonDivider'
import { Popover } from 'lib/lemon-ui/Popover/Popover'
import { range, sampleOne } from 'lib/utils'
import { range, sampleOne, shouldIgnoreInput } from 'lib/utils'
import { MutableRefObject, useEffect, useRef, useState } from 'react'

import { HedgehogAccessories } from './HedgehogAccessories'
Expand All @@ -32,15 +32,6 @@ const randomChoiceList: string[] = Object.keys(standardAnimations).reduce((acc:
return [...acc, ...range(standardAnimations[key].randomChance || 0).map(() => key)]
}, [])

const shouldIgnoreInput = (e: KeyboardEvent): boolean => {
return (
['input', 'textarea'].includes((e.target as HTMLElement).tagName.toLowerCase()) ||
(e.target as HTMLElement).isContentEditable ||
(e.target as HTMLElement).parentElement?.isContentEditable ||
false
)
}

export class HedgehogActor {
animations = standardAnimations
iterationCount = 0
Expand Down
9 changes: 9 additions & 0 deletions frontend/src/lib/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1553,3 +1553,12 @@ export function flattenObject(ob: Record<string, any>): Record<string, any> {
}
return toReturn
}

export const shouldIgnoreInput = (e: KeyboardEvent): boolean => {
return (
['input', 'textarea'].includes((e.target as HTMLElement).tagName.toLowerCase()) ||
(e.target as HTMLElement).isContentEditable ||
(e.target as HTMLElement).parentElement?.isContentEditable ||
false
)
}
Loading