Add ability to edit existing snippet content
This PR implements the ability to edit existing snippet content directly from the TUI, addressing a commonly requested feature for fixing typos and making content updates.
Changes Made
User Interface
- Added "edit content" as the first option in the file browser menu
- Integrated textarea component for multiline editing with line numbers
- Uses Ctrl+S to save changes, Esc to cancel (standard editor conventions)
- Automatically filters out binary files (consistent with extension editing behavior)
Backend Integration
- Leverages existing
UpdateFiledatabase method - no schema changes required - Properly handles file compression using the
SetContentmethod - Automatically updates file size and modification timestamp
- Maintains existing metrics and logging patterns
Key Implementation Details
File: internal/tui/views/prompt/kind.go
const (
None Kind = iota
ChangeExtension
ChangeVisibility
GenerateSignedURL
DeleteFile
EditContent // New prompt type
)
File: internal/tui/views/browser/options.go
- Added "edit content" option at the top of the menu
- Excluded binary files from content editing (same logic as extension editing)
File: internal/tui/views/prompt/prompt.go
- Added textarea component with proper initialization and sizing
- Modified key handling to use Ctrl+S for saving in edit mode (Enter adds newlines)
- Implemented content update logic using
SetContent()for proper compression handling - Added window resize handling for textarea
Usage
- Navigate to any text file in the TUI browser
- Press Tab to focus the options panel
- Select "edit content" (first option)
- Edit the content in the textarea
- Press Ctrl+S to save changes
- Press Esc to cancel without saving
Validation
- Database layer tests confirm content update functionality works correctly
- Compression handling validated to ensure files are stored properly
- Binary file filtering prevents editing of non-text content
- Integration maintains all existing error handling and user feedback
Fixes #218.
[!WARNING]
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
cdn.fwupd.org
- Triggering command:
/usr/bin/fwupdmgr refresh(dns block)If you need me to access, download, or install something from one of these locations, you can either:
- Configure Actions setup steps to set up my environment, which run before the firewall is enabled
- Add the appropriate URLs or hosts to my firewall allow list
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.
Looks pretty good for a first pass!
However I did notice some bugs:
- The first time I attempt to edit the file contents, it is empty. I need to view the contents first, then select edit content.
- The edit mode starts at the end of the file, can you make it start at the beginning?
- The file editor is very short, can you make it the full length of the window
- The toolbar on the bottom of the page like
? helpis not relevant for the edit contents page
Can you suggest (but don't implement) how you would go about versioning file changes. Be sure to include:
- Changes to database schema (and any indexes)
- URL additions and preserving original behavior/paths
- UI changes to indicate previous versions and navigate back and forth.
- What are the potential costs associated? Will we store the entire (compressed) new version? Or should we store deltas. Can we quantify the amount of edits to the current enforced file limits?
Looks pretty good for a first pass!
![]()
...
Fixed all the issues in 4086a8a:
- Empty content - Added loadFileContentCmd to ensure content gets loaded regardless of event order
- Cursor position - Using CursorStart() to place cursor at beginning of file
- Editor height - Made editor height responsive and much taller (window height - 10)
- Toolbar - Created a custom keymap for edit mode showing only the relevant ctrl+s and esc options
Are the images for humans or copilot?