diff --git a/internal/tui/view.go b/internal/tui/view.go index 8b76462..bd91745 100644 --- a/internal/tui/view.go +++ b/internal/tui/view.go @@ -320,8 +320,15 @@ func (m Model) viewObservationDetail() string { b.WriteString(sectionHeadingStyle.Render(" Content")) b.WriteString("\n") - // Split content into lines and apply scroll - contentLines := strings.Split(obs.Content, "\n") + // Wrap content based on terminal width + wrapWidth := m.Width - 6 // basic padding + if wrapWidth < 20 { + wrapWidth = 20 + } + wrappedContent := detailContentStyle.Width(wrapWidth).Render(obs.Content) + + // Split wrapped content into lines + contentLines := strings.Split(wrappedContent, "\n") maxLines := m.Height - 16 if maxLines < 5 { maxLines = 5 @@ -342,7 +349,7 @@ func (m Model) viewObservationDetail() string { } for i := m.DetailScroll; i < end; i++ { - b.WriteString(detailContentStyle.Render(contentLines[i])) + b.WriteString(contentLines[i]) b.WriteString("\n") } diff --git a/internal/tui/wrap_test.go b/internal/tui/wrap_test.go new file mode 100644 index 0000000..1d6701c --- /dev/null +++ b/internal/tui/wrap_test.go @@ -0,0 +1,45 @@ +package tui + +import ( + "strings" + "testing" + + "github.com/Gentleman-Programming/engram/internal/store" +) + +func TestViewObservationDetailWrapping(t *testing.T) { + m := Model{ + Width: 40, + Height: 20, + Screen: ScreenObservationDetail, + SelectedObservation: &store.Observation{ + ID: 1, + Type: "note", + Title: "Test", + Content: "This is a very long line of text that should definitely be wrapped when the width is only forty characters wide.", + }, + } + + view := m.viewObservationDetail() + + // The line "This is a very long line of text that should definitely be wrapped when the width is only forty characters wide." + // is much longer than 40 chars. With wrapWidth = Width - 6 = 34, it should split. + + lines := strings.Split(view, "\n") + contentStarted := false + contentLines := 0 + + for _, line := range lines { + if strings.Contains(line, "Content") { + contentStarted = true + continue + } + if contentStarted && strings.TrimSpace(line) != "" && !strings.Contains(line, "scroll") { + contentLines++ + } + } + + if contentLines <= 1 { + t.Errorf("Expected content to be wrapped into multiple lines, but got %d content lines", contentLines) + } +}