Browse Source

feat(nc-gui): keyboard maneuver for json cell

pull/4482/head
Wing-Kam Wong 2 years ago
parent
commit
507a1f496a
  1. 32
      packages/nc-gui/components/cell/Json.vue
  2. 4
      packages/nc-gui/components/smartsheet/Grid.vue

32
packages/nc-gui/components/cell/Json.vue

@ -1,5 +1,17 @@
<script setup lang="ts">
import { Modal as AModal, EditModeInj, IsFormInj, ReadonlyInj, computed, inject, ref, useVModel, watch } from '#imports'
import {
Modal as AModal,
ActiveCellInj,
EditModeInj,
IsFormInj,
ReadonlyInj,
computed,
inject,
ref,
useSelectedCellKeyupListener,
useVModel,
watch,
} from '#imports'
interface Props {
modelValue: string | Record<string, any> | undefined
@ -15,6 +27,8 @@ const emits = defineEmits<Emits>()
const editEnabled = inject(EditModeInj, ref(false))
const active = inject(ActiveCellInj, ref(false))
const isForm = inject(IsFormInj, ref(false))
const readonly = inject(ReadonlyInj)
@ -89,6 +103,22 @@ watch(editEnabled, () => {
localValue.value = vModel.value
})
useSelectedCellKeyupListener(active, (e) => {
switch (e.key) {
case 'Enter':
e.stopPropagation()
if (e.shiftKey) {
return true
}
if (editEnabled.value) {
onSave()
} else {
editEnabled.value = true
}
break
}
})
</script>
<template>

4
packages/nc-gui/components/smartsheet/Grid.vue

@ -205,6 +205,10 @@ const { selectCell, selectBlock, selectedRange, clearRangeRows, startSelectRange
return true
}
} else if (e.key === 'Enter') {
if (e.shiftKey) {
// add a line break for types like LongText / JSON
return true
}
if (editEnabled) {
editEnabled = false
return true

Loading…
Cancel
Save