Skip to content

Commit efd5b90

Browse files
authored
Merge pull request #715 from rumpl/fix-single-line-selection
Handle the case whre startLine == endLine
2 parents 7cc6463 + acb8ee6 commit efd5b90

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

pkg/tui/components/messages/messages.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,14 @@ func (m *model) extractSelectedText() string {
859859
var lineText string
860860
switch i {
861861
case startLine:
862+
if startLine == endLine {
863+
startIdx := displayWidthToRuneIndex(line, startCol)
864+
endIdx := min(displayWidthToRuneIndex(line, endCol), len(runes))
865+
if startIdx < len(runes) && startIdx < endIdx {
866+
lineText = strings.TrimSpace(string(runes[startIdx:endIdx]))
867+
}
868+
break
869+
}
862870
// First line: from startCol to end
863871
startIdx := displayWidthToRuneIndex(line, startCol)
864872
if startIdx < len(runes) {
@@ -888,7 +896,7 @@ func (m *model) copySelectionToClipboard() tea.Cmd {
888896
return nil
889897
}
890898

891-
selectedText := m.extractSelectedText()
899+
selectedText := strings.TrimSpace(m.extractSelectedText())
892900
if selectedText == "" {
893901
return nil
894902
}

0 commit comments

Comments
 (0)