From 205d4ecfe6ec2b07f87f9250d969f6d8cc2538ef Mon Sep 17 00:00:00 2001 From: DarkPhoenix2704 Date: Sat, 28 Oct 2023 05:58:21 +0000 Subject: [PATCH] feat(nc-gui): keyboard support for multi fields editor --- .../components/smartsheet/details/Fields.vue | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/packages/nc-gui/components/smartsheet/details/Fields.vue b/packages/nc-gui/components/smartsheet/details/Fields.vue index 486f422d60..966fa572ad 100644 --- a/packages/nc-gui/components/smartsheet/details/Fields.vue +++ b/packages/nc-gui/components/smartsheet/details/Fields.vue @@ -3,6 +3,7 @@ import { diff } from 'deep-object-diff' import { message } from 'ant-design-vue' import { UITypes, isSystemColumn } from 'nocodb-sdk' import Draggable from 'vuedraggable' +import { onKeyDown, useMagicKeys } from '@vueuse/core' import type { ColumnType, SelectOptionsType } from 'nocodb-sdk' import { Icon } from '@iconify/vue' import { type Field, getUniqueColumnName, ref, useSmartsheetStoreOrThrow } from '#imports' @@ -39,6 +40,8 @@ const { getMeta } = useMetas() const { meta, view } = useSmartsheetStoreOrThrow() +const { openedViewsTab } = storeToRefs(useViewsStore()) + const moveOps = ref([]) const visibilityOps = ref([]) @@ -569,6 +572,33 @@ const toggleVisibility = async (checked: boolean, field: Field) => { }) } +onKeyDown('ArrowDown', () => { + const index = fields.value.findIndex((f) => compareCols(f, activeField.value)) + if (index === -1) changeField(fields.value[0]) + else if (index === fields.value.length - 1) changeField(fields.value[0]) + else changeField(fields.value[index + 1]) +}) +onKeyDown('ArrowUp', () => { + const index = fields.value.findIndex((f) => compareCols(f, activeField.value)) + if (index === -1) changeField(fields.value[0]) + else if (index === 0) changeField(fields.value[fields.value.length - 1]) + else changeField(fields.value[index - 1]) +}) + +onKeyDown('Delete', () => { + const isDeletedField = fieldStatus(activeField.value) === 'delete' + if (!isDeletedField && activeField.value) { + onFieldDelete(activeField.value) + } +}) + +const keys = useMagicKeys() + +whenever(keys.alt_c, () => { + if (!meta.value?.id) return + if (openedViewsTab.value === 'field') addField() +}) + const isColumnsValid = computed(() => fields.value.every((f) => isColumnValid(f))) onMounted(async () => {