on main help sign in
fix: improve long text detection to account for long text in a single line (#2442)
0c6fb42Andrey Nering
internal/ui/model/ui.go+21−2
@@ -66,9 +66,12 @@ const (
66 compactModeHeightBreakpoint = 30
66 compactModeHeightBreakpoint = 30
67)
67)
68
68
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.
70const pasteLinesThreshold = 10
70const pasteLinesThreshold = 10
71
71
72+// If pasted text has more than 1000 columns, treat it as a file attachment.
73+const pasteColsThreshold = 1000
74+
72// Session details panel max height.
75// Session details panel max height.
73const sessionDetailsMaxHeight = 20
76const sessionDetailsMaxHeight = 20
74
77
@@ -3160,7 +3163,7 @@ func (m *UI) handlePasteMsg(msg tea.PasteMsg) tea.Cmd {
3160 return nil
3163 return nil
3161 }
3164 }
3162
3165
3163− if strings.Count(msg.Content, "\n") > pasteLinesThreshold {
3166+ if hasPasteExceededThreshold(msg) {
3164 return func() tea.Msg {
3167 return func() tea.Msg {
3165 content := []byte(msg.Content)
3168 content := []byte(msg.Content)
3166 if int64(len(content)) > common.MaxAttachmentSize {
3169 if int64(len(content)) > common.MaxAttachmentSize {
@@ -3218,6 +3221,22 @@ func (m *UI) handlePasteMsg(msg tea.PasteMsg) tea.Cmd {
3218 return tea.Batch(cmds...)
3221 return tea.Batch(cmds...)
3219}
3222}
3220
3223
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+
3221// handleFilePathPaste handles a pasted file path.
3240// handleFilePathPaste handles a pasted file path.
3222func (m *UI) handleFilePathPaste(path string) tea.Cmd {
3241func (m *UI) handleFilePathPaste(path string) tea.Cmd {
3223 return func() tea.Msg {
3242 return func() tea.Msg {