Skip to content

Commit

Permalink
More robust isTypingComment
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewwallacespeckle committed Dec 12, 2024
1 parent d33fb67 commit 5a68e55
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions packages/frontend-2/lib/viewer/composables/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import type {
ViewerShortcut,
ViewerShortcutAction
} from '~/lib/viewer/helpers/shortcuts/types'
import { useActiveElement } from '@vueuse/core'

export function useSectionBoxUtilities() {
const { instance } = useInjectedViewer()
Expand Down Expand Up @@ -510,21 +511,23 @@ export function useViewerShortcuts() {
const { ui } = useInjectedViewerState()
const { isSmallerOrEqualSm } = useIsSmallerOrEqualThanBreakpoint()
const { isEnabled: isEmbedEnabled } = useEmbed()
const activeElement = useActiveElement()

const isTypingComment = computed(() => {
// Check if any input-like element is focused
const activeElement = document.activeElement
const isInputFocused =
activeElement instanceof HTMLElement &&
(activeElement.tagName === 'INPUT' ||
activeElement.tagName === 'TEXTAREA' ||
activeElement.contentEditable === 'true')
if (
activeElement.value &&
(activeElement.value.tagName.toLowerCase() === 'input' ||
activeElement.value.tagName.toLowerCase() === 'textarea' ||
activeElement.value.getAttribute('contenteditable') === 'true')
) {
return true
}

// Check thread editor states
const isNewThreadEditorOpen = ui.threads.openThread.newThreadEditor.value
const isExistingThreadEditorOpen = !!ui.threads.openThread.thread.value

return isInputFocused || isNewThreadEditorOpen || isExistingThreadEditorOpen
return isNewThreadEditorOpen || isExistingThreadEditorOpen
})

const formatKey = (key: string) => {
Expand Down

0 comments on commit 5a68e55

Please sign in to comment.