Switch from Asuka to MyGo, keeping the API client and the feature set: - servers: saved servers, passwordless and password login, proxy, self-signed certificates, per-server device tokens (Keystore), connect form, instance list sheet with switch/disconnect - sessions: virtualized list, search, new session, rename/archive/delete, running indicator, event stream keeps it live - chat: pushed window with system back bar, streaming Markdown via ui/markdown, reasoning and tool rows with image previews, footer menu (read aloud via a Kotlin TTS plugin, copy, fork), user message menu (copy, revert, fork), context usage ring and detail sheet, attachments (photos/files via the document picker), permissions - release builds allow plain http:// LAN servers (Go's net/http dials directly, no cleartext manifest needed) - a local fork of MyGo (third_party/mygo) lowers the Android host's minSdk to 24 (Android 7.0); Go 1.27.4 via mise Version 0.3.0.
82 lines
2.1 KiB
Go
82 lines
2.1 KiB
Go
package ui
|
|
|
|
import (
|
|
"slices"
|
|
"testing"
|
|
)
|
|
|
|
func TestSelectableText(t *testing.T) {
|
|
const sentence = "Order 12345 shipped"
|
|
tt := coreNewTester(func(c *context) {
|
|
coreColumn(c).Padding(20).Gap(10).AlignItems(Start).Children(func() {
|
|
coreText(c, sentence).Selectable()
|
|
coreText(c, "Plain text")
|
|
})
|
|
}, 400, 200)
|
|
var ed *editor
|
|
for _, s := range tt.rt.states {
|
|
if s.editor != nil && s.editor.readOnly {
|
|
ed = s.editor
|
|
}
|
|
}
|
|
if ed == nil || ed.layout == nil {
|
|
t.Fatal("the selectable text has no editor laid out")
|
|
}
|
|
r, _ := tt.Find(sentence)
|
|
// at returns where rune i of the sentence is, in the window.
|
|
at := func(i int) (float32, float32) {
|
|
x, y, h := ed.layout.Caret(i)
|
|
return r.X + ed.originX + x, r.Y + ed.originY + y + h/2
|
|
}
|
|
|
|
// Double-clicking a word selects it, which Cmd+C copies.
|
|
x, y := at(8)
|
|
tt.ClickAt(x, y)
|
|
tt.ClickAt(x, y)
|
|
tt.Key(Cmd, KeyC)
|
|
if tt.Clipboard() != "12345" {
|
|
t.Errorf("a double click copies %q", tt.Clipboard())
|
|
}
|
|
// Dragging selects what it goes over.
|
|
x0, y0 := at(0)
|
|
x1, _ := at(5)
|
|
tt.Press(x0, y0)
|
|
tt.Move(x1, y0)
|
|
tt.Release(x1, y0)
|
|
tt.Key(Cmd, KeyC)
|
|
if tt.Clipboard() != "Order" {
|
|
t.Errorf("a drag copies %q", tt.Clipboard())
|
|
}
|
|
tt.Key(Cmd, KeyA)
|
|
tt.Key(Cmd, KeyC)
|
|
if tt.Clipboard() != sentence {
|
|
t.Errorf("Cmd+A then Cmd+C copies %q", tt.Clipboard())
|
|
}
|
|
// It cannot be edited.
|
|
tt.Type("x")
|
|
tt.Key(0, KeyBackspace)
|
|
tt.SetClipboard("pasted")
|
|
tt.Key(Cmd, KeyV)
|
|
if !tt.HasText(sentence) || ed.buf.s != sentence {
|
|
t.Errorf("typing changed the text to %q", ed.buf.s)
|
|
}
|
|
if tt.Move(x, y); tt.Cursor() != CursorText {
|
|
t.Errorf("the pointer is %v over selectable text", tt.Cursor())
|
|
}
|
|
tt.RightClickAt(x, y)
|
|
if m := tt.Menu(); !slices.Equal(m, []string{"Copy", "-", "Select All"}) {
|
|
t.Errorf("the context menu is %q", m)
|
|
}
|
|
tt.CloseMenu()
|
|
|
|
// A click elsewhere takes the focus, and copying leaves the clipboard.
|
|
if p, ok := tt.Find("Plain text"); ok {
|
|
tt.ClickAt(p.X+p.W/2, p.Y+p.H/2)
|
|
}
|
|
tt.SetClipboard("kept")
|
|
tt.Key(Cmd, KeyC)
|
|
if tt.Clipboard() != "kept" {
|
|
t.Errorf("Cmd+C away from the selection copies %q", tt.Clipboard())
|
|
}
|
|
}
|