@@ -24,6 +24,7 @@ const (
24 MaxAttachmentSize = int64(5 * 1024 * 1024) // 5MB
24 MaxAttachmentSize = int64(5 * 1024 * 1024) // 5MB
25 FilePickerID = "filepicker"
25 FilePickerID = "filepicker"
26 fileSelectionHeight = 10
26 fileSelectionHeight = 10
29type FilePickedMsg struct {
30type FilePickedMsg struct {
@@ -160,13 +161,25 @@ func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
160func (m *model) View() string {
161func (m *model) View() string {
161 t := styles.CurrentTheme()
162 t := styles.CurrentTheme()
163− content := lipgloss.JoinVertical(
164+ strs := []string{
165 t.S().Base.Padding(0, 1, 1, 1).Render(core.Title("Add Image", m.width-4)),
165 t.S().Base.Padding(0, 1, 1, 1).Render(core.Title("Add Image", m.width-4)),
168+ // hide image preview if the terminal is too small
169+ if x, y := m.imagePreviewSize(); x > 0 && y > 0 {
166− m.imagePreview(),
170+ strs = append(strs, m.imagePreview())
167 m.filePicker.View(),
175 m.filePicker.View(),
168 t.S().Base.Width(m.width-2).PaddingLeft(1).AlignHorizontal(lipgloss.Left).Render(m.help.View(m.keyMap)),
176 t.S().Base.Width(m.width-2).PaddingLeft(1).AlignHorizontal(lipgloss.Left).Render(m.help.View(m.keyMap)),
179+ content := lipgloss.JoinVertical(
170 return m.style().Render(content)
183 return m.style().Render(content)
@@ -180,12 +193,15 @@ func (m *model) currentImage() string {
182func (m *model) imagePreview() string {
195func (m *model) imagePreview() string {
183 t := styles.CurrentTheme()
198 t := styles.CurrentTheme()
184 w, h := m.imagePreviewSize()
199 w, h := m.imagePreviewSize()
185 if m.currentImage() == "" {
201 if m.currentImage() == "" {
186 imgPreview := t.S().Base.
202 imgPreview := t.S().Base.
187− Width(w).
203+ Width(w - padding).
188− Height(h).
204+ Height(h - padding).
189 Background(t.BgOverlay)
205 Background(t.BgOverlay)
191 return m.imagePreviewStyle().Render(imgPreview.Render())
207 return m.imagePreviewStyle().Render(imgPreview.Render())
@@ -200,7 +216,10 @@ func (m *model) imagePreviewStyle() lipgloss.Style {
202func (m *model) imagePreviewSize() (int, int) {
218func (m *model) imagePreviewSize() (int, int) {
219+ if m.wHeight-fileSelectionHeight-8 > previewHeight {
203− return m.width - 4, min(20, m.wHeight/2)
220+ return m.width - 4, previewHeight
206func (m *model) style() lipgloss.Style {
225func (m *model) style() lipgloss.Style {
@@ -218,7 +237,10 @@ func (m *model) ID() dialogs.DialogID {
219// Position implements FilePicker.
238// Position implements FilePicker.
220func (m *model) Position() (int, int) {
239func (m *model) Position() (int, int) {
240+ _, imageHeight := m.imagePreviewSize()
241+ dialogHeight := fileSelectionHeight + imageHeight + 4
221− row := m.wHeight/4 - 2 // just a bit above the center
242+ row := (m.wHeight - dialogHeight) / 2
222 col := m.wWidth / 2
244 col := m.wWidth / 2
223 col -= m.width / 2
245 col -= m.width / 2
224 return row, col
246 return row, col