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

fix: start filepicker in cwd instead of os.Homedir
This commit is contained in:
Kujtim Hoxha
2025-07-18 10:09:11 +02:00
committed by GitHub
6 changed files with 35 additions and 4 deletions

View File

@@ -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")

View File

@@ -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"),
),
}

View File

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

View File

@@ -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

View File

@@ -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,

View File

@@ -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]: