-
Notifications
You must be signed in to change notification settings - Fork 11
🤖 Add customizable F-key macros #305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
ammar-agent
wants to merge
10
commits into
main
Choose a base branch
from
f-keys
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4a235a7
🤖 Add customizable F-key macros
ammar-agent 5fc7cd8
Move F-key bar above workspace title bar
ammar-agent 069e9cc
Make F-key buttons more compact and keyboard-like
ammar-agent a72ccc2
Fix modal layout conflict in EditKeybindModal
ammar-agent 7372539
Change F-key behavior: append to existing messages, auto-send when empty
ammar-agent d3f4cba
Fix F-key auto-send by bypassing state update delay
ammar-agent c5e8083
Refactor ChatInput: eliminate duplicated send logic
ammar-agent 39c3916
Move FKeyBar above chat input for better UX
ammar-agent 1e6cd92
Match FKeyBar background with chat area
ammar-agent 846b8ff
Make FKeyBar appear only when chat input is focused
ammar-agent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,168 @@ | ||
| import React, { useState, useEffect, useRef } from "react"; | ||
| import styled from "@emotion/styled"; | ||
| import { Modal } from "./Modal"; | ||
|
|
||
| const ModalContent = styled.div` | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: 16px; | ||
| min-width: 500px; | ||
| `; | ||
|
|
||
| const Label = styled.label` | ||
| font-size: 13px; | ||
| color: #ccc; | ||
| margin-bottom: 6px; | ||
| display: block; | ||
| `; | ||
|
|
||
| const TextArea = styled.textarea` | ||
| width: 100%; | ||
| min-height: 100px; | ||
| padding: 8px; | ||
| background: #1e1e1e; | ||
| border: 1px solid #3e3e42; | ||
| border-radius: 3px; | ||
| color: #d4d4d4; | ||
| font-family: var(--font-monospace); | ||
| font-size: 13px; | ||
| resize: vertical; | ||
|
|
||
| &:focus { | ||
| outline: none; | ||
| border-color: #007acc; | ||
| } | ||
| `; | ||
|
|
||
| const ButtonRow = styled.div` | ||
| display: flex; | ||
| gap: 8px; | ||
| justify-content: flex-end; | ||
| `; | ||
|
|
||
| const Button = styled.button<{ variant?: "primary" | "danger" }>` | ||
| padding: 6px 16px; | ||
| border-radius: 3px; | ||
| font-size: 13px; | ||
| cursor: pointer; | ||
| border: none; | ||
| transition: all 0.15s ease; | ||
|
|
||
| ${(props) => { | ||
| if (props.variant === "primary") { | ||
| return ` | ||
| background: #007acc; | ||
| color: white; | ||
| &:hover { background: #005a9e; } | ||
| &:disabled { | ||
| background: #555; | ||
| color: #888; | ||
| cursor: not-allowed; | ||
| } | ||
| `; | ||
| } else if (props.variant === "danger") { | ||
| return ` | ||
| background: #c72e2e; | ||
| color: white; | ||
| &:hover { background: #a02020; } | ||
| `; | ||
| } else { | ||
| return ` | ||
| background: #3e3e42; | ||
| color: #ccc; | ||
| &:hover { background: #505055; } | ||
| `; | ||
| } | ||
| }} | ||
| `; | ||
|
|
||
| const HintText = styled.div` | ||
| font-size: 12px; | ||
| color: #888; | ||
| line-height: 1.4; | ||
| `; | ||
|
|
||
| interface EditKeybindModalProps { | ||
| isOpen: boolean; | ||
| fKey: string; | ||
| currentMessage: string; | ||
| onSave: (message: string) => void; | ||
| onClear: () => void; | ||
| onClose: () => void; | ||
| } | ||
|
|
||
| export function EditKeybindModal({ | ||
| isOpen, | ||
| fKey, | ||
| currentMessage, | ||
| onSave, | ||
| onClear, | ||
| onClose, | ||
| }: EditKeybindModalProps) { | ||
| const [message, setMessage] = useState(currentMessage); | ||
| const textareaRef = useRef<HTMLTextAreaElement>(null); | ||
|
|
||
| // Reset message when modal opens with new key | ||
| useEffect(() => { | ||
| setMessage(currentMessage); | ||
| }, [currentMessage, isOpen]); | ||
|
|
||
| // Focus textarea when modal opens | ||
| useEffect(() => { | ||
| if (isOpen && textareaRef.current) { | ||
| textareaRef.current.focus(); | ||
| } | ||
| }, [isOpen]); | ||
|
|
||
| const handleSave = () => { | ||
| onSave(message.trim()); | ||
| }; | ||
|
|
||
| const handleClear = () => { | ||
| onClear(); | ||
| }; | ||
|
|
||
| const handleKeyDown = (e: React.KeyboardEvent) => { | ||
| // Ctrl+Enter / Cmd+Enter to save | ||
| if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) { | ||
| e.preventDefault(); | ||
| handleSave(); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <Modal isOpen={isOpen} onClose={onClose} title={`Edit ${fKey} Macro`}> | ||
| <ModalContent> | ||
| <div> | ||
| <Label htmlFor="keybind-message">Message to send:</Label> | ||
| <TextArea | ||
| ref={textareaRef} | ||
| id="keybind-message" | ||
| value={message} | ||
| onChange={(e) => setMessage(e.target.value)} | ||
| onKeyDown={handleKeyDown} | ||
| placeholder="Enter message (supports slash commands like /edit, /compact, etc.)" | ||
| /> | ||
| </div> | ||
|
|
||
| <HintText> | ||
| Tip: You can use slash commands like <code>/edit</code>, <code>/compact</code>, or any | ||
| other message. Press Ctrl+Enter to save. | ||
| </HintText> | ||
|
|
||
| <ButtonRow> | ||
| {currentMessage && ( | ||
| <Button variant="danger" onClick={handleClear}> | ||
| Clear | ||
| </Button> | ||
| )} | ||
| <Button onClick={onClose}>Cancel</Button> | ||
| <Button variant="primary" onClick={handleSave}> | ||
| Save | ||
| </Button> | ||
| </ButtonRow> | ||
| </ModalContent> | ||
| </Modal> | ||
| ); | ||
| } | ||
|
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new
sendMessagehelper inserts the macro text and then triggershandleSendvia a delayed callback, buthandleSendcaptures theinputvalue from the previous render. When the timeout fires, the closure still sees the old (often empty)inputand returns immediately, leaving the macro message sitting in the input field instead of being sent. This means F‑key macros don’t actually transmit anything unless the user manually hits Enter afterward. The helper needs to send the message without relying on the stale closure—e.g. by passing the text directly into the send routine or by using a ref to a stable sender.Useful? React with 👍 / 👎.