on main help sign in
fix: improve long text detection to account for long text in a single line (#2442)
commit0c6fb42a0359d381085e531f4fcec6e0af07c988 authorAndrey Nering <andreynering@users.noreply.github.com> dateMon 23 Mar 2026, 17:19 (7 months ago) parent91bec12
1 file changed+21−2
internal/ui/model/ui.go+21−2
internal/ui/model/ui.go+21−2
@@ -66,9 +66,12 @@ const (
6666 compactModeHeightBreakpoint = 30
6767)
6868
69−// If pasted text has more than 2 newlines, treat it as a file attachment.
69+// If pasted text has more than 10 newlines, treat it as a file attachment.
7070const pasteLinesThreshold = 10
7171
72+// If pasted text has more than 1000 columns, treat it as a file attachment.
73+const pasteColsThreshold = 1000
74+
7275// Session details panel max height.
7376const sessionDetailsMaxHeight = 20
7477
@@ -3160,7 +3163,7 @@ func (m *UI) handlePasteMsg(msg tea.PasteMsg) tea.Cmd {
31603163 return nil
31613164 }
31623165
3163− if strings.Count(msg.Content, "\n") > pasteLinesThreshold {
3166+ if hasPasteExceededThreshold(msg) {
31643167 return func() tea.Msg {
31653168 content := []byte(msg.Content)
31663169 if int64(len(content)) > common.MaxAttachmentSize {
@@ -3218,6 +3221,22 @@ func (m *UI) handlePasteMsg(msg tea.PasteMsg) tea.Cmd {
32183221 return tea.Batch(cmds...)
32193222}
32203223
3224+func hasPasteExceededThreshold(msg tea.PasteMsg) bool {
3225+ var (
3226+ lineCount = 0
3227+ colCount = 0
3228+ )
3229+ for line := range strings.SplitSeq(msg.Content, "\n") {
3230+ lineCount++
3231+ colCount = max(colCount, len(line))
3232+
3233+ if lineCount > pasteLinesThreshold || colCount > pasteColsThreshold {
3234+ return true
3235+ }
3236+ }
3237+ return false
3238+}
3239+
32213240// handleFilePathPaste handles a pasted file path.
32223241func (m *UI) handleFilePathPaste(path string) tea.Cmd {
32233242 return func() tea.Msg {