Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/tui/components/fuzzyselect/mentions.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (src *UserMentionSource) ExtractContext(input string, cursorPos tea.Positio
}

if userStart >= len(runes)+1 ||
(userStart > 0 && userStart < len(runes) && src.WithAtSymbol && runes[userStart-1] != '@') {
(userStart > 0 && userStart <= len(runes) && src.WithAtSymbol && runes[userStart-1] != '@') {
return Context{}
}

Expand Down
35 changes: 35 additions & 0 deletions internal/tui/components/fuzzyselect/source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,41 @@ func TestUserMentionSource(t *testing.T) {
require.Equal(t, tea.Position{X: 12}, newCursor)
}

func TestUserMentionSourceCursorBetweenBoundaries(t *testing.T) {
testCases := []struct {
name string
input string
cursorPos tea.Position
}{
{
name: "cursor between two trailing spaces",
input: "hello ",
cursorPos: tea.Position{X: 6},
},
{
name: "cursor before the only char, which is a boundary",
input: " ",
cursorPos: tea.Position{X: 0},
},
{
name: "cursor between a space and a trailing punctuation mark",
input: "hello @octo .",
cursorPos: tea.Position{X: 12},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
for _, withAt := range []bool{true, false} {
source := UserMentionSource{WithAtSymbol: withAt}
require.NotPanics(t, func() {
source.ExtractContext(tc.input, tc.cursorPos)
})
}
})
}
}

func TestUserMentionSourceWithoutAtSymbol(t *testing.T) {
source := UserMentionSource{WithAtSymbol: false}
require.Equal(
Expand Down
Loading