diff --git a/packages/nc-gui/components/cell/attachment/Carousel.vue b/packages/nc-gui/components/cell/attachment/Carousel.vue index c66ea621f6..7c2cf52ef0 100644 --- a/packages/nc-gui/components/cell/attachment/Carousel.vue +++ b/packages/nc-gui/components/cell/attachment/Carousel.vue @@ -3,13 +3,16 @@ import type { CarouselApi } from '../../nc/Carousel/interface' import { useAttachmentCell } from './utils' import { isOffice } from '~/utils/fileUtils' -const { selectedFile, visibleItems, downloadAttachment, removeFile, renameFile, isPublic, isReadonly } = useAttachmentCell()! +const { selectedFile, visibleItems, downloadAttachment, removeFile, renameFile, isPublic, isReadonly, isRenameModalOpen } = + useAttachmentCell()! const isExpandedFormOpen = inject(IsExpandedFormOpenInj, ref(false)) const { isSharedForm } = useSmartsheetStoreOrThrow() +/* const openComments = ref(false) +*/ const { isUIAllowed } = useRoles() @@ -99,10 +102,35 @@ watchOnce(emblaMainApi, async (emblaMainApi) => { }) }) -const toggleComment = () => { - openComments.value = !openComments.value +onMounted(() => { + document.addEventListener('keydown', onKeyDown) +}) + +onUnmounted(() => { + document.removeEventListener('keydown', onKeyDown) +}) + +function onKeyDown(event: KeyboardEvent) { + if (isRenameModalOpen.value) return + const prevKey = ['ArrowLeft', 'Left', 'a', 'A'] + const nextKey = ['ArrowRight', 'Right', 'd', 'D'] + + if (prevKey.includes(event.key)) { + event.preventDefault() + emblaMainApi.value?.scrollPrev() + return + } + + if (nextKey.includes(event.key)) { + event.preventDefault() + emblaMainApi.value?.scrollNext() + } } +/* const toggleComment = () => { + openComments.value = !openComments.value +} */ + onMounted(() => { if (!isPublic.value && !isExpandedFormOpen.value && isUIAllowed('commentList')) { const { loadComments } = useRowCommentsOrThrow() diff --git a/packages/nc-gui/components/cell/attachment/utils.ts b/packages/nc-gui/components/cell/attachment/utils.ts index 674104fb2a..dcc7f6f3e0 100644 --- a/packages/nc-gui/components/cell/attachment/utils.ts +++ b/packages/nc-gui/components/cell/attachment/utils.ts @@ -56,6 +56,8 @@ export const [useProvideAttachmentCell, useAttachmentCell] = useInjectionState( reset: true, }) + const isRenameModalOpen = ref(false) + const { appInfo } = useGlobal() const defaultAttachmentMeta = { @@ -266,6 +268,7 @@ export const [useProvideAttachmentCell, useAttachmentCell] = useInjectionState( async function renameFile(attachment: AttachmentType, idx: number, updateSelectedFile?: boolean) { return new Promise((resolve) => { + isRenameModalOpen.value = true const { close } = useDialog(RenameFile, { title: attachment.title, onRename: (newTitle: string) => { @@ -277,10 +280,12 @@ export const [useProvideAttachmentCell, useAttachmentCell] = useInjectionState( selectedFile.value = { ...attachment, title: newTitle } } + isRenameModalOpen.value = false resolve(true) }, onCancel: () => { close() + isRenameModalOpen.value = false resolve(true) }, }) @@ -429,6 +434,7 @@ export const [useProvideAttachmentCell, useAttachmentCell] = useInjectionState( stopCamera, videoStream, permissionGranted, + isRenameModalOpen, } }, 'useAttachmentCell', diff --git a/packages/nc-gui/components/nc/Carousel/index.vue b/packages/nc-gui/components/nc/Carousel/index.vue index 94bff7bd63..510a43c611 100644 --- a/packages/nc-gui/components/nc/Carousel/index.vue +++ b/packages/nc-gui/components/nc/Carousel/index.vue @@ -10,30 +10,6 @@ const emits = defineEmits() const carouselArgs = useProvideCarousel(props, emits) -onMounted(() => { - document.addEventListener('keydown', onKeyDown) -}) - -onUnmounted(() => { - document.removeEventListener('keydown', onKeyDown) -}) - -function onKeyDown(event: KeyboardEvent) { - const prevKey = props.orientation === 'vertical' ? ['ArrowUp', 'Up', 'w', 'W'] : ['ArrowLeft', 'Left', 'a', 'A'] - const nextKey = props.orientation === 'vertical' ? ['ArrowDown', 'Down', 's', 'S'] : ['ArrowRight', 'Right', 'd', 'D'] - - if (prevKey.includes(event.key)) { - event.preventDefault() - carouselArgs.scrollPrev() - return - } - - if (nextKey.includes(event.key)) { - event.preventDefault() - carouselArgs.scrollNext() - } -} - defineExpose(carouselArgs)