Browse Source

feat: shift + cmd + arrow keys to select multiple records

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/5847/head
mertmit 1 year ago
parent
commit
513e683f40
  1. 3
      packages/nc-gui/components/smartsheet/Grid.vue
  2. 58
      packages/nc-gui/composables/useMultiSelect/index.ts

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

@ -257,6 +257,9 @@ const {
if (cmdOrCtrl) { if (cmdOrCtrl) {
if (!isCellActive.value) return if (!isCellActive.value) return
// cmdOrCtrl+shift handled in useMultiSelect
if (e.shiftKey) return
switch (e.key) { switch (e.key) {
case 'ArrowUp': case 'ArrowUp':
e.preventDefault() e.preventDefault()

58
packages/nc-gui/composables/useMultiSelect/index.ts

@ -304,6 +304,8 @@ export function useMultiSelect(
return return
} }
const cmdOrCtrl = isMac() ? e.metaKey : e.ctrlKey
/** on tab key press navigate through cells */ /** on tab key press navigate through cells */
switch (e.key) { switch (e.key) {
case 'Tab': case 'Tab':
@ -355,11 +357,18 @@ export function useMultiSelect(
e.preventDefault() e.preventDefault()
if (e.shiftKey) { if (e.shiftKey) {
if ((selectedRange._end?.col || activeCell.col) < unref(columnLength) - 1) { if (cmdOrCtrl) {
editEnabled.value = false
selectedRange.endRange({
row: selectedRange._end?.row ?? activeCell.row,
col: unref(columnLength) - 1,
})
scrollToCell?.(selectedRange._end?.row, selectedRange._end?.col)
} else if ((selectedRange._end?.col ?? activeCell.col) < unref(columnLength) - 1) {
editEnabled.value = false editEnabled.value = false
selectedRange.endRange({ selectedRange.endRange({
row: selectedRange._end?.row || activeCell.row, row: selectedRange._end?.row ?? activeCell.row,
col: (selectedRange._end?.col || activeCell.col) + 1, col: (selectedRange._end?.col ?? activeCell.col) + 1,
}) })
scrollToCell?.(selectedRange._end?.row, selectedRange._end?.col) scrollToCell?.(selectedRange._end?.row, selectedRange._end?.col)
} }
@ -378,11 +387,18 @@ export function useMultiSelect(
e.preventDefault() e.preventDefault()
if (e.shiftKey) { if (e.shiftKey) {
if ((selectedRange._end?.col || activeCell.col) > 0) { if (cmdOrCtrl) {
editEnabled.value = false
selectedRange.endRange({
row: selectedRange._end?.row ?? activeCell.row,
col: 0,
})
scrollToCell?.(selectedRange._end?.row, selectedRange._end?.col)
} else if ((selectedRange._end?.col ?? activeCell.col) > 0) {
editEnabled.value = false editEnabled.value = false
selectedRange.endRange({ selectedRange.endRange({
row: selectedRange._end?.row || activeCell.row, row: selectedRange._end?.row ?? activeCell.row,
col: (selectedRange._end?.col || activeCell.col) - 1, col: (selectedRange._end?.col ?? activeCell.col) - 1,
}) })
scrollToCell?.(selectedRange._end?.row, selectedRange._end?.col) scrollToCell?.(selectedRange._end?.row, selectedRange._end?.col)
} }
@ -401,11 +417,20 @@ export function useMultiSelect(
e.preventDefault() e.preventDefault()
if (e.shiftKey) { if (e.shiftKey) {
if ((selectedRange._end?.row || activeCell.row) > 0) { if (cmdOrCtrl) {
editEnabled.value = false editEnabled.value = false
console.log(selectedRange._end?.col)
selectedRange.endRange({ selectedRange.endRange({
row: (selectedRange._end?.row || activeCell.row) - 1, row: 0,
col: selectedRange._end?.col || activeCell.col, col: selectedRange._end?.col ?? activeCell.col,
})
console.log(selectedRange._end?.col)
scrollToCell?.(selectedRange._end?.row, selectedRange._end?.col)
} else if ((selectedRange._end?.row ?? activeCell.row) > 0) {
editEnabled.value = false
selectedRange.endRange({
row: (selectedRange._end?.row ?? activeCell.row) - 1,
col: selectedRange._end?.col ?? activeCell.col,
}) })
scrollToCell?.(selectedRange._end?.row, selectedRange._end?.col) scrollToCell?.(selectedRange._end?.row, selectedRange._end?.col)
} }
@ -424,11 +449,18 @@ export function useMultiSelect(
e.preventDefault() e.preventDefault()
if (e.shiftKey) { if (e.shiftKey) {
if ((selectedRange._end?.row || activeCell.row) < unref(data).length - 1) { if (cmdOrCtrl) {
editEnabled.value = false
selectedRange.endRange({
row: unref(data).length - 1,
col: selectedRange._end?.col ?? activeCell.col,
})
scrollToCell?.(selectedRange._end?.row, selectedRange._end?.col)
} else if ((selectedRange._end?.row ?? activeCell.row) < unref(data).length - 1) {
editEnabled.value = false editEnabled.value = false
selectedRange.endRange({ selectedRange.endRange({
row: (selectedRange._end?.row || activeCell.row) + 1, row: (selectedRange._end?.row ?? activeCell.row) + 1,
col: selectedRange._end?.col || activeCell.col, col: selectedRange._end?.col ?? activeCell.col,
}) })
scrollToCell?.(selectedRange._end?.row, selectedRange._end?.col) scrollToCell?.(selectedRange._end?.row, selectedRange._end?.col)
} }
@ -461,7 +493,7 @@ export function useMultiSelect(
// select all - ctrl/cmd +a // select all - ctrl/cmd +a
case 65: case 65:
selectedRange.startRange({ row: 0, col: 0 }) selectedRange.startRange({ row: 0, col: 0 })
selectedRange.endRange({ row: unref(data).length - 1, col: unref(fields).length - 1 }) selectedRange.endRange({ row: unref(data).length - 1, col: unref(columnLength) - 1 })
break break
} }
} }

Loading…
Cancel
Save