fix(composer): expand every mention around code spans
This commit is contained in:
parent
91c0ee1a97
commit
837e615d1a
4 changed files with 22 additions and 7 deletions
2
go.mod
2
go.mod
|
|
@ -15,7 +15,7 @@ require (
|
|||
github.com/andybalholm/brotli v1.2.6
|
||||
github.com/ayn2op/arikawa/v3 v3.0.0-20260929021956-7d0802bf4d7c
|
||||
github.com/ayn2op/ningen/v3 v3.0.1-0.20260929010920-29794d5fa70e
|
||||
github.com/ayn2op/tview v0.0.0-20260930195008-a20956345053
|
||||
github.com/ayn2op/tview v0.0.0-20260930215038-4bb4ac90d11c
|
||||
github.com/bogdanfinn/fhttp v0.6.9
|
||||
github.com/bogdanfinn/tls-client v1.16.0
|
||||
github.com/gdamore/tcell/v3 v3.5.0
|
||||
|
|
|
|||
4
go.sum
4
go.sum
|
|
@ -14,8 +14,8 @@ github.com/ayn2op/arikawa/v3 v3.0.0-20260929021956-7d0802bf4d7c h1:Qkl3W5RXzUQUR
|
|||
github.com/ayn2op/arikawa/v3 v3.0.0-20260929021956-7d0802bf4d7c/go.mod h1:SHqcr+EmZKeNtVKZybHJn4HNz+ufA1XbeKNSTigBCEE=
|
||||
github.com/ayn2op/ningen/v3 v3.0.1-0.20260929010920-29794d5fa70e h1:QAei/IVEyZV7GcpkpcFUh37+QRqwrt57z7OT3ciHrhI=
|
||||
github.com/ayn2op/ningen/v3 v3.0.1-0.20260929010920-29794d5fa70e/go.mod h1:RsvYiMzi4Si1F7vmml5NCL2DaKIZXkNUQC7QlGTMtCw=
|
||||
github.com/ayn2op/tview v0.0.0-20260930195008-a20956345053 h1:cuiAx9jwMwy+fJfmLwWA5ONd3l3+YFrCIAHbIpHurJU=
|
||||
github.com/ayn2op/tview v0.0.0-20260930195008-a20956345053/go.mod h1:oRPTSZgaEJPhv3dmmNvo6grBq/BemrLG3wFQLMTZJkY=
|
||||
github.com/ayn2op/tview v0.0.0-20260930215038-4bb4ac90d11c h1:ABMNEaSusSM3FiOjIrrR8zz9JUgA+oXQCs6bpUgqsmI=
|
||||
github.com/ayn2op/tview v0.0.0-20260930215038-4bb4ac90d11c/go.mod h1:oRPTSZgaEJPhv3dmmNvo6grBq/BemrLG3wFQLMTZJkY=
|
||||
github.com/bdandy/go-errors v1.2.2 h1:WdFv/oukjTJCLa79UfkGmwX7ZxONAihKu4V0mLIs11Q=
|
||||
github.com/bdandy/go-errors v1.2.2/go.mod h1:NkYHl4Fey9oRRdbB1CoC6e84tuqQHiqrOcZpqFEkBxM=
|
||||
github.com/bdandy/go-socks4 v1.2.3 h1:Q6Y2heY1GRjCtHbmlKfnwrKVU/k81LS8mRGLRlmDlic=
|
||||
|
|
|
|||
|
|
@ -338,15 +338,15 @@ func (c *Model) processText(channel *discord.Channel, src []byte) string {
|
|||
canMention = !enter
|
||||
}
|
||||
case *ast.Text:
|
||||
if canMention {
|
||||
ranges = append(ranges, [2]int{node.Segment.Start,
|
||||
node.Segment.Stop})
|
||||
if enter && canMention {
|
||||
ranges = append(ranges, [2]int{node.Segment.Start, node.Segment.Stop})
|
||||
}
|
||||
}
|
||||
return ast.WalkContinue, nil
|
||||
})
|
||||
|
||||
for _, rng := range ranges {
|
||||
// Replace back to front so that expanding a mention does not shift the ranges before it.
|
||||
for _, rng := range slices.Backward(ranges) {
|
||||
src = slices.Replace(src, rng[0], rng[1], c.expandMentions(channel, src[rng[0]:rng[1]])...)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -145,3 +145,18 @@ func TestModelTabSuggest(t *testing.T) {
|
|||
t.Fatalf("suggested %d authors, want 2", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestModelProcessText(t *testing.T) {
|
||||
c, _ := newTestModel(t)
|
||||
channel := &discord.Channel{Type: discord.DirectMessage, DMRecipients: []discord.User{{ID: 1, Username: "alice"}, {ID: 2, Username: "bob"}}}
|
||||
for _, tt := range []struct{ name, in, want string }{
|
||||
{"mentions around code", "@alice `code` @bob", "<@1> `code` <@2>"},
|
||||
{"mention in code", "@alice `@bob`", "<@1> `@bob`"},
|
||||
} {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := c.processText(channel, []byte(tt.in)); got != tt.want {
|
||||
t.Fatalf("got %q, want %q", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue