Add context-aware items to the command palette
When opened with Ctrl-K, the palette now prepends entries for whatever is currently focused: - Focused scratchpad: Delete / Rename (inline form) / Edit (fire-and- forget zed launch with stdio detached so the TUI is not suspended). - Focused agent: Rename (inline form) / Close. - Focused process: Rename / Delete (drops the entry; SIGKILL if alive) / Stop (SIGTERM, keep entry) / Restart (same argv). The rename UX is a single-field inline form that mirrors the existing spawn-process form, so the modal-input contract is unchanged. scratchpad.Store grows Delete / Rename / Path so the palette can act on a pad file by name. focusedPad is plumbed onto uiState ahead of the scratchpad-focus UI work; until that lands it stays empty and the scratchpad-context entries simply never surface. Tested with palette_context_test.go and a new rename_process_via_palette harness scenario.
This commit is contained in:
@@ -148,6 +148,52 @@ func (s *Store) Append(name, content string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// Delete removes the scratchpad file. Missing files are reported as
|
||||
// errors; callers that want "delete if exists" can ignore os.ErrNotExist.
|
||||
func (s *Store) Delete(name string) error {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
p, err := s.safePath(name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return os.Remove(p)
|
||||
}
|
||||
|
||||
// Rename moves a scratchpad file to a new name within the same project
|
||||
// directory. Returns os.ErrExist if newName already exists; the caller
|
||||
// is expected to surface that to the user rather than clobber.
|
||||
func (s *Store) Rename(oldName, newName string) error {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
src, err := s.safePath(oldName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dst, err := s.safePath(newName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if src == dst {
|
||||
return nil
|
||||
}
|
||||
if _, err := os.Stat(dst); err == nil {
|
||||
return fmt.Errorf("scratchpad: %q already exists", newName)
|
||||
} else if !errors.Is(err, os.ErrNotExist) {
|
||||
return err
|
||||
}
|
||||
return os.Rename(src, dst)
|
||||
}
|
||||
|
||||
// Path returns the absolute path of a scratchpad file. The file does
|
||||
// not need to exist; callers like "Edit scratchpad" rely on this to
|
||||
// hand the path to an external editor.
|
||||
func (s *Store) Path(name string) (string, error) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
return s.safePath(name)
|
||||
}
|
||||
|
||||
func (s *Store) safePath(name string) (string, error) {
|
||||
if name == "" || strings.ContainsAny(name, "/\\") || name == "." || name == ".." {
|
||||
return "", errors.New("scratchpad: invalid name")
|
||||
|
||||
Reference in New Issue
Block a user