From 64ff32f201f9261d49de0865846d71be9888930c Mon Sep 17 00:00:00 2001 From: Adam Berecz Date: Sat, 7 Oct 2023 08:57:32 +0200 Subject: [PATCH] fix: trigger deselect on tags backspace fix #335 --- src/composables/useKeyboard.js | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/src/composables/useKeyboard.js b/src/composables/useKeyboard.js index 6fb5d31..018d897 100644 --- a/src/composables/useKeyboard.js +++ b/src/composables/useKeyboard.js @@ -15,6 +15,7 @@ export default function useKeyboard (props, context, dep) const iv = dep.iv const update = dep.update + const deselect = dep.deselect const search = dep.search const setPointer = dep.setPointer const selectPointer = dep.selectPointer @@ -61,23 +62,6 @@ export default function useKeyboard (props, context, dep) } } - const removeLastRemovable = (arr) => { - // Find the index of the last object in the array that doesn't have a "remove" property set to false - let indexToRemove = arr.length - 1 - while (indexToRemove >= 0 && (arr[indexToRemove].remove === false || arr[indexToRemove].disabled)) { - indexToRemove-- - } - - // If all objects have a "remove" property set to false, don't remove anything and return the original array - if (indexToRemove < 0) { - return arr - } - - // Remove the object at the found index and return the updated array - arr.splice(indexToRemove, 1); - return arr - } - const handleKeydown = (e) => { context.emit('keydown', e, $this) @@ -103,7 +87,11 @@ export default function useKeyboard (props, context, dep) return } - update(removeLastRemovable([...iv.value])) + let deselectables = iv.value.filter(v=>!v.disabled && v.remove !== false) + + if (deselectables.length) { + deselect(deselectables[deselectables.length - 1]) + } break case 'Enter':