From 0c6fb42a0359d381085e531f4fcec6e0af07c988 Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Mon, 23 Mar 2026 17:19:36 -0300 Subject: [PATCH] fix: improve long text detection to account for long text in a single line (#2442) --- internal/ui/model/ui.go | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/internal/ui/model/ui.go b/internal/ui/model/ui.go index 5b0c0350998a28b3490a7445d832bfbdec1fd3db..9742db2456dd4945a6f83b828d1cd95bd16819b8 100644 --- a/internal/ui/model/ui.go +++ b/internal/ui/model/ui.go @@ -66,9 +66,12 @@ const ( compactModeHeightBreakpoint = 30 ) -// If pasted text has more than 2 newlines, treat it as a file attachment. +// If pasted text has more than 10 newlines, treat it as a file attachment. const pasteLinesThreshold = 10 +// If pasted text has more than 1000 columns, treat it as a file attachment. +const pasteColsThreshold = 1000 + // Session details panel max height. const sessionDetailsMaxHeight = 20 @@ -3160,7 +3163,7 @@ func (m *UI) handlePasteMsg(msg tea.PasteMsg) tea.Cmd { return nil } - if strings.Count(msg.Content, "\n") > pasteLinesThreshold { + if hasPasteExceededThreshold(msg) { return func() tea.Msg { content := []byte(msg.Content) if int64(len(content)) > common.MaxAttachmentSize { @@ -3218,6 +3221,22 @@ func (m *UI) handlePasteMsg(msg tea.PasteMsg) tea.Cmd { return tea.Batch(cmds...) } +func hasPasteExceededThreshold(msg tea.PasteMsg) bool { + var ( + lineCount = 0 + colCount = 0 + ) + for line := range strings.SplitSeq(msg.Content, "\n") { + lineCount++ + colCount = max(colCount, len(line)) + + if lineCount > pasteLinesThreshold || colCount > pasteColsThreshold { + return true + } + } + return false +} + // handleFilePathPaste handles a pasted file path. func (m *UI) handleFilePathPaste(path string) tea.Cmd { return func() tea.Msg {