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 | |
parent | bd202df41755c581844d0ab1773ba55968b15450 (diff) | |
download | sncontinue-7bf8e5b56a518979bc1d2602b8eb4a2caf2b5fdb.tar.gz sncontinue-7bf8e5b56a518979bc1d2602b8eb4a2caf2b5fdb.tar.bz2 sncontinue-7bf8e5b56a518979bc1d2602b8eb4a2caf2b5fdb.zip |
feat: :lipstick: improvements to keyboard shortcuts
-rw-r--r-- | extension/react-app/src/components/ComboBox.tsx | 30 | ||||
-rw-r--r-- | extension/react-app/src/components/PillButton.tsx | 45 | ||||
-rw-r--r-- | extension/src/activation/activate.ts | 11 |
3 files changed, 55 insertions, 31 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 diff --git a/extension/react-app/src/components/PillButton.tsx b/extension/react-app/src/components/PillButton.tsx index 5895a91c..0dcd43eb 100644 --- a/extension/react-app/src/components/PillButton.tsx +++ b/extension/react-app/src/components/PillButton.tsx @@ -84,8 +84,34 @@ interface PillButtonProps { index: number; addingHighlightedCode?: boolean; areMultipleItems?: boolean; + onDelete?: () => void; } +interface StyledButtonProps { + warning: string; + editing?: boolean; + areMultipleItems?: boolean; +} + +const StyledButton = styled(Button)<StyledButtonProps>` + position: relative; + border-color: ${(props) => + props.warning + ? "red" + : props.editing && props.areMultipleItems + ? vscForeground + : "transparent"}; + border-width: 1px; + border-style: solid; + + &:focus { + outline: none; + border-color: red; + border-width: 1px; + border-style: solid; + } +`; + const PillButton = (props: PillButtonProps) => { const [isHovered, setIsHovered] = useState(false); const client = useContext(GUIClientContext); @@ -132,17 +158,10 @@ const PillButton = (props: PillButtonProps) => { return ( <> <div style={{ position: "relative" }}> - <Button - style={{ - position: "relative", - borderColor: props.warning - ? "red" - : props.item.editing && props.areMultipleItems - ? vscForeground - : "transparent", - borderWidth: "1px", - borderStyle: "solid", - }} + <StyledButton + areMultipleItems={props.areMultipleItems} + warning={props.warning || ""} + editing={props.item.editing} onMouseEnter={() => { setIsHovered(true); if (props.onHover) { @@ -158,7 +177,7 @@ const PillButton = (props: PillButtonProps) => { className="pill-button" onKeyDown={(e) => { if (e.key === "Backspace") { - client?.deleteContextWithIds([props.item.description.id]); + props.onDelete?.(); } }} > @@ -202,7 +221,7 @@ const PillButton = (props: PillButtonProps) => { </GridDiv> )} {props.item.description.name} - </Button> + </StyledButton> <StyledTooltip id={`edit-${props.index}`}> {props.item.editing ? "Editing this section (with entire file as context)" diff --git a/extension/src/activation/activate.ts b/extension/src/activation/activate.ts index 7a2fdfc3..d07719a8 100644 --- a/extension/src/activation/activate.ts +++ b/extension/src/activation/activate.ts @@ -61,17 +61,6 @@ export async function activateExtension(context: vscode.ExtensionContext) { startContinuePythonServer().then(() => { resolve(null); }); - - vscode.window - .showInformationMessage( - "Click here to view the server logs, or use the 'continue.viewLogs' VS Code command.", - "View Logs" - ) - .then((selection) => { - if (selection === "View Logs") { - vscode.commands.executeCommand("continue.viewLogs"); - } - }); }); console.log("Continue server started"); |