Files
ZacharyZhang-NYandClaude Opus 5.5 03e1f91706 Upgrade MyGo to v0.5.5
Elements are now pass-scoped value handles: tests that read bounds
after a frame bind a ui.Handle. pixel tells frames apart by the build
pass's root, since the Tester clock no longer moves on its own.

Fix the regressions the upgrade brought:
- Clipboard reads in input handlers go through c.Services().
- MyGo notes an overlay's opener after building it, so AutoFocus
  inside lost it; pixel.AutoFocus focuses through a Handle, and
  archtest bans the raw call. Dialogs hand the focus back again.
- Elements around a press stay hovered: Tooltip tells a press-given
  focus by focus arriving under the pointer.
- The web host moves the Tester clock with real time, at most 500 ms
  a call, and gives components the real clock.

The gallery's source index also accepts CRLF checkouts.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-17 01:31:08 -04:00

61 lines
1.9 KiB
Go

package chat
import (
"log/slog"
"strings"
"unicode/utf8"
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/input"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
)
type MentionInputOptions struct {
Placeholder string
// Width is in dots; zero means 160.
Width int
Disabled bool
}
type MentionInputResult struct {
Element ui.Element
Changed, Submitted, Accepted bool
// Mentioned is the member just completed, else empty.
Mentioned string
}
// MentionInput suggests members after @; Tab or Enter completes.
func MentionInput(c *ui.Context, text string, value *string, members []string, o MentionInputOptions) MentionInputResult {
k := pixel.K(c)
w := pixel.Or("MentionInput Width", o.Width, 160)
// The word after the last @ picks matching members.
var whole, names []string
if at := strings.LastIndex(*value, "@"); at >= 0 && !strings.ContainsAny((*value)[at:], " \n") {
typed := strings.ToLower((*value)[at+1:])
for _, m := range members {
if strings.HasPrefix(strings.ToLower(m), typed) {
whole, names = append(whole, (*value)[:at+1]+m+" "), append(names, m)
}
}
}
var res MentionInputResult
res.Element = ui.Column(c).Gap(k.D(1)).Children(func() {
r := input.Autocomplete(c, text, value, whole, input.AutocompleteOptions{Placeholder: o.Placeholder, Width: w, Disabled: o.Disabled})
res.Changed, res.Submitted, res.Accepted = r.Changed, r.Submitted, r.Accepted
if r.Changed {
slog.Debug("8bit: mention input changed", "label", text, "runes", utf8.RuneCountInString(*value))
}
for i, s := range whole {
if r.Accepted && s == *value {
res.Mentioned = names[i]
slog.Debug("8bit: mention", "label", text, "member", names[i])
}
}
if len(names) > 0 && !r.Accepted {
pixel.Text(c, line("@"+strings.Join(names, " @"), w), pixel.TextOptions{Slot: pixel.Faint})
}
})
return res
}