From cf974fd6c82e39df68e5b7b244d08b9fdd2a9ade Mon Sep 17 00:00:00 2001 From: Pranav C Date: Sat, 18 Feb 2023 15:22:54 +0530 Subject: [PATCH] feat(gui): Avoid closing the LTAR model if the element is added by holding ALT/OPT key Signed-off-by: Pranav C --- .../virtual-cell/components/ListItems.vue | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/packages/nc-gui/components/virtual-cell/components/ListItems.vue b/packages/nc-gui/components/virtual-cell/components/ListItems.vue index 711030c443..b779171289 100644 --- a/packages/nc-gui/components/virtual-cell/components/ListItems.vue +++ b/packages/nc-gui/components/virtual-cell/components/ListItems.vue @@ -48,14 +48,20 @@ const saveRow = inject(SaveRowInj, () => {}) const selectedRowIndex = ref(0) +const isAltKeyDown = ref(false) + const linkRow = async (row: Record) => { if (isNew.value) { addLTARRef(row, column?.value as ColumnType) - saveRow() + saveRow!() } else { await link(row) } - vModel.value = false + if (isAltKeyDown.value) { + loadChildrenExcludedList() + } else { + vModel.value = false + } } /** reload list on modal open */ @@ -159,6 +165,27 @@ useSelectedCellKeyupListener(vModel, (e: KeyboardEvent) => { const activeRow = (vNode?: InstanceType) => { vNode?.$el?.scrollIntoView({ block: 'nearest', inline: 'nearest' }) } + +// set variable to true when alt key is pressed +const keyDownHandler = (e: KeyboardEvent) => { + isAltKeyDown.value = e.altKey +} + +// set variable to false when key is released +const keyUpHandler = (e: KeyboardEvent) => { + isAltKeyDown.value = e.altKey +} + +// add event listeners when vModel is true and remove when false +watch(vModel, (nextVal) => { + if (nextVal) { + document.addEventListener('keydown', keyDownHandler) + document.addEventListener('keyup', keyUpHandler) + } else { + document.removeEventListener('keydown', keyDownHandler) + document.removeEventListener('keyup', keyUpHandler) + } +})