diff options
author | Nate Sesti <sestinj@gmail.com> | 2023-08-04 14:27:29 -0700 |
---|---|---|
committer | Nate Sesti <sestinj@gmail.com> | 2023-08-04 14:27:29 -0700 |
commit | 7bf8e5b56a518979bc1d2602b8eb4a2caf2b5fdb (patch) | |
tree | dcbf57274f94e90233c637d558964864ed4d8c2e /extension/react-app/src/components/ComboBox.tsx | |
parent | bd202df41755c581844d0ab1773ba55968b15450 (diff) | |
download | sncontinue-7bf8e5b56a518979bc1d2602b8eb4a2caf2b5fdb.tar.gz sncontinue-7bf8e5b56a518979bc1d2602b8eb4a2caf2b5fdb.tar.bz2 sncontinue-7bf8e5b56a518979bc1d2602b8eb4a2caf2b5fdb.zip |
feat: :lipstick: improvements to keyboard shortcuts
Diffstat (limited to 'extension/react-app/src/components/ComboBox.tsx')
-rw-r--r-- | extension/react-app/src/components/ComboBox.tsx | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/extension/react-app/src/components/ComboBox.tsx b/extension/react-app/src/components/ComboBox.tsx index 9b15713e..14e04a84 100644 --- a/extension/react-app/src/components/ComboBox.tsx +++ b/extension/react-app/src/components/ComboBox.tsx @@ -244,7 +244,9 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => { (item) => item === document.activeElement ); console.log(focusedItemIndex, focusableItems); - if (focusedItemIndex !== -1) { + if (focusedItemIndex === focusableItemsArray.length - 1) { + inputRef.current?.focus(); + } else if (focusedItemIndex !== -1) { const nextItem = focusableItemsArray[ (focusedItemIndex + 1) % focusableItemsArray.length @@ -256,15 +258,27 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => { } }; + useEffect(() => { + if (typeof window !== "undefined") { + const listener = (e: any) => { + if (e.key === "Tab") { + e.preventDefault(); + handleTabPressed(); + } + }; + window.addEventListener("keydown", listener); + return () => { + window.removeEventListener("keydown", listener); + }; + } + }, []); + const [metaKeyPressed, setMetaKeyPressed] = useState(false); const [focused, setFocused] = useState(false); useEffect(() => { const handleKeyDown = (e: KeyboardEvent) => { if (e.key === "Meta") { setMetaKeyPressed(true); - } else if (e.key === "Tab") { - e.preventDefault(); - handleTabPressed(); } }; const handleKeyUp = (e: KeyboardEvent) => { @@ -319,6 +333,10 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => { } addingHighlightedCode={props.addingHighlightedCode} index={idx} + onDelete={() => { + client?.deleteContextWithIds([item.description.id]); + inputRef.current?.focus(); + }} /> ); })} @@ -337,7 +355,7 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => { onClick={() => { props.onToggleAddContext(); }} - className="pill-button" + className="pill-button focus:outline-none focus:border-red-600 focus:border focus:border-solid" onKeyDown={(e: KeyboardEvent) => { e.preventDefault(); if (e.key === "Enter") { @@ -395,8 +413,6 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => { event.preventDefault(); } else if (event.key === "Tab") { (event.nativeEvent as any).preventDownshiftDefault = true; - event.preventDefault(); - handleTabPressed(); } else if ( (event.key === "ArrowUp" || event.key === "ArrowDown") && event.currentTarget.value.split("\n").length > 1 |