Skip to content

Commit

Permalink
fix: Shortcut helper firing when it shouldn't (#18864)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjackwhite authored Nov 27, 2023
1 parent 0582506 commit c5193a6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
)
}

0 comments on commit c5193a6

Please sign in to comment.