Merge pull request #221 from charmbracelet/bugfix/filepicker-in-cwd

Kujtim Hoxha created

fix: start filepicker in cwd instead of os.Homedir

Change summary

internal/app/app.go                                      |  5 +++
internal/tui/components/chat/editor/editor.go            |  2 
internal/tui/components/chat/editor/keys.go              |  3 ++
internal/tui/components/dialogs/filepicker/filepicker.go | 15 ++++++++-
internal/tui/page/chat/chat.go                           | 12 ++++++++
internal/tui/tui.go                                      |  2 
6 files changed, 35 insertions(+), 4 deletions(-)

Detailed changes

internal/app/app.go 🔗

@@ -92,6 +92,11 @@ func New(ctx context.Context, conn *sql.DB, cfg *config.Config) (*App, error) {
 	return app, nil
 }
 
+// Config returns the application configuration.
+func (app *App) Config() *config.Config {
+	return app.config
+}
+
 // RunNonInteractive handles the execution flow when a prompt is provided via CLI flag.
 func (app *App) RunNonInteractive(ctx context.Context, prompt string, quiet bool) error {
 	slog.Info("Running in non-interactive mode")

internal/tui/components/chat/editor/editor.go 🔗

@@ -72,7 +72,7 @@ var DeleteKeyMaps = DeleteAttachmentKeyMaps{
 	),
 	DeleteAllAttachments: key.NewBinding(
 		key.WithKeys("r"),
-		key.WithHelp("ctrl+r+r", "delete all attchments"),
+		key.WithHelp("ctrl+r+r", "delete all attachments"),
 	),
 }
 

internal/tui/components/chat/editor/keys.go 🔗

@@ -42,6 +42,9 @@ func (k EditorKeyMap) KeyBindings() []key.Binding {
 		k.SendMessage,
 		k.OpenEditor,
 		k.Newline,
+		AttachmentsKeyMaps.AttachmentDeleteMode,
+		AttachmentsKeyMaps.DeleteAllAttachments,
+		AttachmentsKeyMaps.Escape,
 	}
 }
 

internal/tui/components/dialogs/filepicker/filepicker.go 🔗

@@ -45,11 +45,22 @@ type model struct {
 	help            help.Model
 }
 
-func NewFilePickerCmp() FilePicker {
+func NewFilePickerCmp(workingDir string) FilePicker {
 	t := styles.CurrentTheme()
 	fp := filepicker.New()
 	fp.AllowedTypes = []string{".jpg", ".jpeg", ".png"}
-	fp.CurrentDirectory, _ = os.UserHomeDir()
+
+	if workingDir != "" {
+		fp.CurrentDirectory = workingDir
+	} else {
+		// Fallback to current working directory, then home directory
+		if cwd, err := os.Getwd(); err == nil {
+			fp.CurrentDirectory = cwd
+		} else {
+			fp.CurrentDirectory, _ = os.UserHomeDir()
+		}
+	}
+
 	fp.ShowPermissions = false
 	fp.ShowSize = false
 	fp.AutoHeight = false

internal/tui/page/chat/chat.go 🔗

@@ -838,6 +838,18 @@ func (p *chatPage) Help() help.KeyMap {
 						key.WithKeys("ctrl+v"),
 						key.WithHelp("ctrl+v", "open editor"),
 					),
+					key.NewBinding(
+						key.WithKeys("ctrl+r"),
+						key.WithHelp("ctrl+r+{i}", "delete attachment at index i"),
+					),
+					key.NewBinding(
+						key.WithKeys("ctrl+r", "r"),
+						key.WithHelp("ctrl+r+r", "delete all attachments"),
+					),
+					key.NewBinding(
+						key.WithKeys("esc"),
+						key.WithHelp("esc", "cancel delete mode"),
+					),
 				})
 		}
 		shortList = append(shortList,

internal/tui/tui.go 🔗

@@ -204,7 +204,7 @@ func (a *appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 			return a, util.CmdHandler(dialogs.CloseDialogMsg{})
 		}
 		return a, util.CmdHandler(dialogs.OpenDialogMsg{
-			Model: filepicker.NewFilePickerCmp(),
+			Model: filepicker.NewFilePickerCmp(a.app.Config().WorkingDir()),
 		})
 	// Permissions
 	case pubsub.Event[permission.PermissionRequest]: