on main help sign in
Merge pull request #221 from charmbracelet/bugfix/filepicker-in-cwd

fix: start filepicker in cwd instead of os.Homedir

commit52346a2bfa3ea66d3873c401b1e230d2233efd51 authorKujtim Hoxha <kujtimii.h@gmail.com> dateFri 18 Jul 2025, 10:09 (1 year ago) parent1fe561cbb81e32
6 files changed+35−4
internal/app/app.go+5 internal/tui/components/chat/editor/editor.go+1−1 internal/tui/components/chat/editor/keys.go+3 internal/tui/components/dialogs/filepicker/filepicker.go+13−2 internal/tui/page/chat/chat.go+12 internal/tui/tui.go+1−1
internal/app/app.go+5
@@ -92,6 +92,11 @@ func New(ctx context.Context, conn *sql.DB, cfg *config.Config) (*App, error) {
9292 return app, nil
9393}
9494
95+// Config returns the application configuration.
96+func (app *App) Config() *config.Config {
97+ return app.config
98+}
99+
95100// RunNonInteractive handles the execution flow when a prompt is provided via CLI flag.
96101func (app *App) RunNonInteractive(ctx context.Context, prompt string, quiet bool) error {
97102 slog.Info("Running in non-interactive mode")
internal/tui/components/chat/editor/editor.go+1−1
@@ -72,7 +72,7 @@ var DeleteKeyMaps = DeleteAttachmentKeyMaps{
7272 ),
7373 DeleteAllAttachments: key.NewBinding(
7474 key.WithKeys("r"),
75− key.WithHelp("ctrl+r+r", "delete all attchments"),
75+ key.WithHelp("ctrl+r+r", "delete all attachments"),
7676 ),
7777}
7878
internal/tui/components/chat/editor/keys.go+3
@@ -42,6 +42,9 @@ func (k EditorKeyMap) KeyBindings() []key.Binding {
4242 k.SendMessage,
4343 k.OpenEditor,
4444 k.Newline,
45+ AttachmentsKeyMaps.AttachmentDeleteMode,
46+ AttachmentsKeyMaps.DeleteAllAttachments,
47+ AttachmentsKeyMaps.Escape,
4548 }
4649}
4750
internal/tui/components/dialogs/filepicker/filepicker.go+13−2
@@ -45,11 +45,22 @@ type model struct {
4545 help help.Model
4646}
4747
48−func NewFilePickerCmp() FilePicker {
48+func NewFilePickerCmp(workingDir string) FilePicker {
4949 t := styles.CurrentTheme()
5050 fp := filepicker.New()
5151 fp.AllowedTypes = []string{".jpg", ".jpeg", ".png"}
52− fp.CurrentDirectory, _ = os.UserHomeDir()
52+
53+ if workingDir != "" {
54+ fp.CurrentDirectory = workingDir
55+ } else {
56+ // Fallback to current working directory, then home directory
57+ if cwd, err := os.Getwd(); err == nil {
58+ fp.CurrentDirectory = cwd
59+ } else {
60+ fp.CurrentDirectory, _ = os.UserHomeDir()
61+ }
62+ }
63+
5364 fp.ShowPermissions = false
5465 fp.ShowSize = false
5566 fp.AutoHeight = false
internal/tui/page/chat/chat.go+12
@@ -838,6 +838,18 @@ func (p *chatPage) Help() help.KeyMap {
838838 key.WithKeys("ctrl+v"),
839839 key.WithHelp("ctrl+v", "open editor"),
840840 ),
841+ key.NewBinding(
842+ key.WithKeys("ctrl+r"),
843+ key.WithHelp("ctrl+r+{i}", "delete attachment at index i"),
844+ ),
845+ key.NewBinding(
846+ key.WithKeys("ctrl+r", "r"),
847+ key.WithHelp("ctrl+r+r", "delete all attachments"),
848+ ),
849+ key.NewBinding(
850+ key.WithKeys("esc"),
851+ key.WithHelp("esc", "cancel delete mode"),
852+ ),
841853 })
842854 }
843855 shortList = append(shortList,
internal/tui/tui.go+1−1
@@ -204,7 +204,7 @@ func (a *appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
204204 return a, util.CmdHandler(dialogs.CloseDialogMsg{})
205205 }
206206 return a, util.CmdHandler(dialogs.OpenDialogMsg{
207− Model: filepicker.NewFilePickerCmp(),
207+ Model: filepicker.NewFilePickerCmp(a.app.Config().WorkingDir()),
208208 })
209209 // Permissions
210210 case pubsub.Event[permission.PermissionRequest]: