Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
c2fd6ad
fix(components): stop menu rows tinting under caller content
t8y2 Nov 13, 2026
0edcd90
fix(ui): let a tooltip open on a chosen side
xiaoyumuxi Nov 13, 2026
9305ef2
fix(tooltip): regenerate the installer recipe
t8y2 Nov 13, 2026
74ddd65
feat(web): allow a page to bypass system proxies
imjakey Nov 13, 2026
3c025a1
feat(app): scale macOS traffic lights in a custom titlebar
imjakey Nov 13, 2026
50a25e3
feat(app): request a native window content size
Ezreal-byte Nov 13, 2026
fb7300d
fix(gfx): draw cell glyphs with the font's underline weight
t8y2 Nov 13, 2026
30a91db
ci: run the underline metric test on Windows
t8y2 Nov 13, 2026
d1252da
feat(table): expose last-painted row identities
t8y2 Nov 13, 2026
5bee0d3
feat: add editor gutter actions and directory paths
t8y2 Nov 13, 2026
e419237
Merge remote-tracking branch 'origin/main' into lane/rowidentity
t8y2 Nov 13, 2026
8239839
feat(table): scroll wide tables left and right under a fixed header
t8y2 Nov 13, 2026
a6f6e5d
feat(gfx): stroke dashed borders through the path pipeline
t8y2 Nov 13, 2026
20d160a
feat(app): add the grabbing cursor to every backend
t8y2 Nov 13, 2026
a7345fa
feat(components): optional text alignment for InputSnapshot
t8y2 Nov 13, 2026
e1a04ae
feat(ui): dashed element borders and injected dashed frames
t8y2 Nov 13, 2026
6bfd5e2
fix(ui): keep a table's horizontal scrollbar inside its reserved gutter
t8y2 Nov 13, 2026
9a72c12
feat(app): write HTML and plain text to the clipboard in one copy
t8y2 Nov 13, 2026
9d0abef
feat(ui): frozen table columns pinned to a scrolling body's left edge
t8y2 Nov 13, 2026
449079b
fix(components): refresh the scroll-area recipe for the frozen band
t8y2 Nov 13, 2026
d621712
fix(components): keep long tooltip text whole when wrapping
t8y2 Nov 14, 2026
be5d296
fix(ui): hide duplicate anonymous table hover bars
t8y2 Nov 14, 2026
39c770a
fix(components): tint the caret's row in an empty CodeEditor
t8y2 Nov 14, 2026
0a4e756
feat(ui): TextEnd places an Input's text at the end of its direction
t8y2 Nov 14, 2026
5cce5aa
fix(instance): claim with a named pipe on Windows
t8y2 Nov 14, 2026
b8ae437
fix(instance): keep the claim off the browser target
t8y2 Nov 14, 2026
11a62ef
fix(components): wrap tooltip labels through a stack scratch
t8y2 Nov 14, 2026
2382a5a
fix(components): regenerate the stale code-editor recipe
t8y2 Nov 14, 2026
b5cd71e
docs(release): v0.6.3 notes
t8y2 Nov 14, 2026
4510c70
docs: point at v0.6.3
t8y2 Nov 14, 2026
ef9f0bd
feat(app): report a content window's frame and minimize state
t8y2 Nov 14, 2026
ba876bc
fix(gfx): draw cell glyphs with the font's own box stroke
t8y2 Nov 14, 2026
4e01052
feat(package): write a PKGBUILD for Arch Linux
t8y2 Nov 14, 2026
27429b5
feat(update): apply signed delta updates to the installed payload
t8y2 Nov 14, 2026
7daaafe
feat(ui): give Select an icon per option
t8y2 Nov 14, 2026
b63e4a0
feat(headless): add a test clock, accessibility queries and notificat…
t8y2 Nov 14, 2026
e703e62
feat(update): patch a Windows installation from the portable payload
t8y2 Nov 14, 2026
83f5a45
fix(feed): patch only the portable Windows zip
t8y2 Nov 14, 2026
5b177b7
feat(tools): teach iconcompile use elements and vertex markers
t8y2 Nov 14, 2026
878e446
feat(ui): report a table's painted cell rectangles
t8y2 Nov 14, 2026
819f1b5
feat(components): draw italic runs in the code editor
t8y2 Nov 14, 2026
479721c
fix(ui): float Select popups outside ancestor scroll clips
t8y2 Nov 14, 2026
a823813
feat(text): support multiple selections in an editor
t8y2 Nov 14, 2026
83fe4f5
fix(app): resolve a missing path's icon from its type on macOS
t8y2 Nov 14, 2026
cee05b9
fix(update): repair patch test portability and Windows payload paths
caichangqing1120 Nov 14, 2026
db50fd0
fix(ibus): preserve preedit mode and visibility provenance
caichangqing1120 Nov 14, 2026
190ecfe
fix(ibus): retire input contexts through the native service
caichangqing1120 Nov 14, 2026
dfc25d1
fix(linux): detach GTK input methods before window destruction
caichangqing1120 Nov 14, 2026
7c5f74b
fix(components): size menu rows by the theme's control height
xiaoyumuxi Nov 14, 2026
6347593
fix(linux): preserve text state across callback reentry
caichangqing1120 Nov 14, 2026
7a00b92
fix(textcache): protect reused lines from sketch collisions
caichangqing1120 Nov 14, 2026
9301d11
fix(update): stage the macOS payload under the running bundle name
xiaoyumuxi Nov 14, 2026
7edc953
fix(linux): restore clipboard and graphics contract gates
caichangqing1120 Nov 14, 2026
ca3f6df
docs(release): v0.6.4 notes
t8y2 Nov 14, 2026
77c8ba3
docs: point at v0.6.4
t8y2 Nov 14, 2026
ebe264a
feat(app): keep the machine awake while work needs it
t8y2 Nov 14, 2026
94c3710
fix(windows): color the window border to match the window edge
t8y2 Nov 14, 2026
477614e
feat(api): enforce the typed page boundary
t8y2 Nov 14, 2026
1687747
feat(ui): let a page replace its recipes and paint its menus
t8y2 Nov 14, 2026
83c0ec8
feat(app): read the desktop's proxy settings
t8y2 Nov 14, 2026
cef9044
fix(windows): answer direct when proxy auto-detection finds nothing
t8y2 Nov 14, 2026
3a0c050
fix(viva): regenerate the component installer templates
t8y2 Nov 14, 2026
134a178
refactor(app): move the proxy reader into its own package
t8y2 Nov 14, 2026
0fc452c
fix(proxy): skip the child-process test under the wasm runtime
t8y2 Nov 14, 2026
53de03c
feat(text): select the word or line a multi-click press lands on
t8y2 Nov 14, 2026
87c3a87
feat(ui): open a context menu at a point the application captured
t8y2 Nov 14, 2026
60223b6
fix(viva): regenerate the popover installer template
t8y2 Nov 14, 2026
c1bcfe6
feat(app): run posted work on the event-loop thread
t8y2 Nov 14, 2026
fa315df
feat(app): give an application its own macOS menu bar
t8y2 Nov 14, 2026
0f7305c
feat(document): save a file atomically and detect outside changes
t8y2 Nov 14, 2026
167de96
docs: record the macOS application menu bar in conformance
t8y2 Nov 14, 2026
cd4a624
docs(testenv): describe the Linux desktop container
t8y2 Nov 15, 2026
31251d1
test(conformance): assert wake coalescing, not a display rate
t8y2 Nov 15, 2026
1887f03
fix(windows): repair the CF_HTML header and the grabbing cursor cache
t8y2 Nov 15, 2026
1eacfe2
fix(input): name shifted Control chords by their base character
t8y2 Nov 15, 2026
f465bad
feat(text): retain optional LF labels through undo history
caichangqing1120 Nov 15, 2026
e88cee5
feat(text): expose opt-in complete history metadata
caichangqing1120 Nov 15, 2026
a91cb75
feat(text): add opt-in tentative composition transactions
caichangqing1120 Nov 15, 2026
4c47ada
feat(app): bridge opt-in composition phases and native input ownership
caichangqing1120 Nov 15, 2026
856ff66
fix(ibus): preserve daemon order during native engine selection
caichangqing1120 Nov 15, 2026
5301d46
fix(linux): bind GTK input contexts to focused targets
caichangqing1120 Nov 15, 2026
c611576
feat(app): open a local file in the default browser
xiaoyumuxi Nov 15, 2026
68ce694
fix(ui): scroll TextArea content with the mouse wheel
xiaoyumuxi Nov 15, 2026
4de3c5d
fix(components): regenerate the TextArea recipe for wheel support
t8y2 Nov 15, 2026
e2c8db2
feat(package): write .rpm packages for Fedora, RHEL and openSUSE
xiaoyumuxi Nov 15, 2026
1fc6444
test(rpmpkg): read the rpm summary with a query format
t8y2 Nov 15, 2026
1fc84f6
feat(darwin): keep the input method off surfaces that disable it
t8y2 Nov 15, 2026
07550af
Merge vivaui/viva main (1fc84f6) into the fork
xiaoyumuxi Nov 15, 2026
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
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ jobs:
# targets this repository ships for.
- name: vet
run: go vet ./...
# The page-facing packages keep reflection and untyped containers out of
# their exported API; the layout, input, scene and render paths depend on
# it, and a symbol that needs one usually needs a typed one instead.
- name: API discipline
run: go run ./tools/apicheck ./ui ./components ./app ./gfx

# Every target Viva ships for must at least type-check, tests included. The
# targets do not depend on each other, so they run at the same time on one
Expand Down
43 changes: 43 additions & 0 deletions .github/workflows/text-input.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@ on:
push:
paths:
- 'app/**'
- 'internal/iconshape/**'
- 'internal/dbus/**'
- 'internal/platform/**'
- 'internal/ibus/**'
- 'internal/render/**'
- '.github/workflows/text-input.yml'
pull_request:
paths:
- 'app/**'
- 'internal/iconshape/**'
- 'internal/dbus/**'
- 'internal/platform/**'
- 'internal/ibus/**'
- 'internal/render/**'
- '.github/workflows/text-input.yml'
workflow_dispatch:

Expand Down Expand Up @@ -42,6 +50,35 @@ jobs:
cache: true
- name: Application input lifecycle
run: go test ./app -count=1
- name: GTK native probe dependencies
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends libgtk-3-0t64 xvfb xauth dbus-x11
dpkg-query -W libgtk-3-0t64 xvfb xauth dbus-x11
- name: GTK native composition lifecycle
if: runner.os == 'Linux'
run: dbus-run-session -- xvfb-run -a env VIVA_GTK_IME_NATIVE=1 GTK_IM_MODULE=gtk-im-context-simple GDK_BACKEND=x11 NO_AT_BRIDGE=1 G_DEBUG=fatal-criticals go test -tags vivagtk ./internal/platform/linux -run '^TestGTKNativeComposition$' -count=1 -v -timeout=90s
- name: Linux IME protocol lifecycle
if: runner.os == 'Linux'
run: go test ./internal/ibus ./internal/platform/linux -run 'Test(IME|Preedit|CommitAndPreedit|MalformedPreedit)' -count=1 -timeout=90s
- name: Install Linux input service test dependencies
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends libgtk-3-0t64 xvfb xauth dbus-x11 ibus ibus-libpinyin ibus-hangul python3-gi gir1.2-ibus-1.0 gir1.2-gtk-3.0 libglib2.0-bin dconf-cli
dpkg-query -W libgtk-3-0t64 xvfb xauth dbus-x11 ibus ibus-libpinyin ibus-hangul python3-gi gir1.2-ibus-1.0 gir1.2-gtk-3.0 libglib2.0-bin dconf-cli
- name: IBus native engine lifecycle
if: runner.os == 'Linux'
run: |
go test -c -o "$RUNNER_TEMP/viva-ibus-native.test" ./internal/ibus
xvfb-run -a env VIVA_IBUS_TEST_BINARY="$RUNNER_TEMP/viva-ibus-native.test" VIVA_IBUS_REFERENCE=1 sh internal/ibus/testdata/native-service.sh libpinyin hangul
- name: Linux text callback ordering
if: runner.os == 'Linux'
run: go test -race ./internal/platform/linux -run '^TestLinuxTextCallback' -count=1 -timeout=90s
- name: GTK text callback ordering
if: runner.os == 'Linux'
run: go test -tags vivagtk ./internal/platform/linux -run '^TestLinuxTextCallback' -count=1 -timeout=90s
- name: Windows IME lifecycle
if: runner.os == 'Windows'
run: go test ./internal/platform/windows -run 'TestComposition|TestDynamicTextInput' -count=1
Expand All @@ -51,6 +88,12 @@ jobs:
- name: Linux aligned text input
if: runner.os == 'Linux'
run: go test ./internal/platform/linux -run '^TestLinux(TextInputAlignmentMatchesGlyphCaretUnderlineAndPointer|RightToLeftAlignmentUsesLineWidthNotLogicalEndCaret|CandidateWindowFollowsAlignmentWhenNativeOverlaysAreHidden)$' -count=1
- name: GTK input method teardown ordering
if: runner.os == 'Linux'
run: go test -tags vivagtk ./internal/platform/linux -run '^TestGTKDestroyDetachesInputMethodBeforeNativeWidget$' -count=1 -v
- name: Linux clipboard, compositing and icon contracts
if: runner.os == 'Linux'
run: go test -tags vivagtk ./internal/platform/linux -run '^Test(AClipboardHTML|SetClipboardHTML|GTKClipboardHTML|CompositingLayers|NetWMIcon)' -count=1 -v
# A terminal input is a preedit surface with a cursor of its own: the native
# editor must draw no caret or selection over it, and blink none.
- name: Windows terminal preedit draws no native caret
Expand Down
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Viva reaches Cocoa and Metal through cgo; on Linux, X11 with the system XCB and
Vulkan loaders; on Windows, Win32 with Direct3D 11 and DirectWrite. Viva loads
the system libraries at runtime and bundles none of them.

The current release is `v0.6.3`; name it explicitly (`@v0.6.3`) to pin it. Guides,
The current release is `v0.6.4`; name it explicitly (`@v0.6.4`) to pin it. Guides,
the API reference, and a component catalog with live previews live in
[`website/`](website/); run it with `npm run dev` there, or read them on
[vivaui.dev](https://vivaui.dev/en/), which is also available in
Expand Down Expand Up @@ -115,6 +115,21 @@ WebView and no bundled rendering runtime.
corner of the application's Dock tile, and an empty label removes it.
- `app.StoreSecret`/`LoadSecret`/`DeleteSecret` keep a small secret in the
system's own store (Keychain, Credential Manager, Secret Service).
- `app.PreventSleep` keeps the machine out of idle sleep while a transfer or a
remote session runs, naming the work in the system's own power diagnostics
(`pmset`, `powercfg`, `systemd-inhibit`). It holds no timer or goroutine, and
releasing it ends the request.
- `Application.SetMenuBar` puts the application's own File, Edit and View menus
between the system's application menu and Window menu on macOS, with key
equivalents, enablement, check marks, submenus and loop-thread callbacks; the
other desktop targets build their menus in the window with `components.Menubar`.
- `Application.Post` hands work a background goroutine finished to the window
thread: accepted functions run there in order, with no goroutine, timer or
blocking wait added, and no "call the loop and wait" form that could deadlock.
- `app/proxy.SystemProxy` reports the proxy the desktop selects for an HTTP URL:
CFNetwork on macOS, WinHTTP's automatic proxy on Windows (PAC, WPAD and the
static settings), and the environment on Linux. A policy the platform cannot
evaluate is an error, never a silent direct connection.
- `gfx.MonoFamily` draws fixed-pitch text in any installed family and
`app.MonospaceFamilies` lists them.
- `Config.OnFileDrop` receives files dragged from the file manager, with the hit
Expand Down
2 changes: 1 addition & 1 deletion README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ viva dev . # hot reload: save a file, the window updates and keeps its st

环境要求:Go 1.26 或更新版本(缺失时 viva 会自己下载)。macOS 上需要 Xcode 命令行工具,因为 Viva 通过 cgo 访问 Cocoa 和 Metal;Linux 上需要带系统 XCB 和 Vulkan 加载库的 X11;Windows 上需要 Win32、Direct3D 11 和 DirectWrite。Viva 在运行时加载系统库,自身不捆绑任何一个。

当前版本是 `v0.6.3`;要固定版本就写明(`@v0.6.3`)。指南、API 参考和带实时预览的组件目录在 [`website/`](website/) 里,本地用 `npm run dev` 运行;也已经发布在 [vivaui.dev](https://vivaui.dev/zh/)。
当前版本是 `v0.6.4`;要固定版本就写明(`@v0.6.4`)。指南、API 参考和带实时预览的组件目录在 [`website/`](website/) 里,本地用 `npm run dev` 运行;也已经发布在 [vivaui.dev](https://vivaui.dev/zh/)。

下面的一切描述的都是这个仓库:它的测量、它自己的程序,以及如何开发框架本身,而不是如何用框架。

Expand Down
9 changes: 9 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ type Config struct {
// supplied it. Without one the panel is centered on the screen.
Anchor StatusAnchor
ClearColor Color
// WindowBorderColor is read at every paint and names the color of the
// border Windows 11 draws around a custom-titlebar window. The system
// composites that border against what is behind the window rather than
// against the window's own pixels, so the desktop shows through it as a
// seam about a pixel wide at 100% scale and proportionally wider at higher
// scale. Return the color the window's own edge is painted with to make it
// continuous. Nil uses ClearColor; a transparent color leaves the system's
// border. Other platforms ignore it.
WindowBorderColor func() Color
// WindowBackdrop is read on the window thread after each paint. Windows
// 11 22H2+ supports all materials; Windows 10 1809 through 11 21H2 supports
// Acrylic through an undocumented accent policy. Other cases use ClearColor.
Expand Down
23 changes: 23 additions & 0 deletions app/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,29 @@ type Host interface {
// Quit closes every window, close requests notwithstanding, and ends the
// loop. It is safe to call from any goroutine.
Quit()
// Post runs fn on the application's event-loop thread. It is safe from any
// goroutine and never blocks.
Post(fn func())
}

// Post runs fn on the application's event-loop thread. Use it to hand work a
// background goroutine finished to the thread that owns the windows, the pages
// and the retained scene. It is safe from any goroutine, never blocks, and the
// functions it accepts run in the order Post accepted them; a function posted
// after the loop has ended may not run.
//
// A posted function runs on the loop thread and must not wait for the loop: it
// is the same thread that would have to run the work it waits on. Viva provides
// no "call the loop and wait" form for that reason; a result is published where
// the next Window wake or Paint reads it, as Config.OnWake and
// Invalidator.Invalidate already arrange.
//
// It starts no goroutine: the adapter wakes the loop it already has.
func (application *Application) Post(fn func()) {
if application == nil || application.host == nil || fn == nil {
return
}
application.host.Post(fn)
}

// Window is one independently retained native window. Close is idempotent and
Expand Down
15 changes: 15 additions & 0 deletions app/application_native.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package app

import (
"fmt"
"runtime"

"github.com/vivaui/viva/gfx"
Expand Down Expand Up @@ -128,8 +129,22 @@ func (host nativeHost) SetDockBadge(text string) { host.native.SetDockBadge(text

func (host nativeHost) SetProgress(fraction float32) { host.native.SetProgress(fraction) }

// SetMenuBar installs the application's own menus where the adapter has an
// application menu bar; the adapters without one report ErrUnsupported.
func (host nativeHost) SetMenuBar(menus []Menu) error {
setter, ok := host.native.(interface {
SetMenuBar([]platform.MenuBarMenu) error
})
if !ok {
return fmt.Errorf("%w: the application menu bar", ErrUnsupported)
}
return setter.SetMenuBar(platformMenuBar(menus))
}

func (host nativeHost) Quit() { host.native.Quit() }

func (host nativeHost) Post(fn func()) { host.native.Post(fn) }

type nativeStatusItem struct{ item platform.StatusItem }

func (item nativeStatusItem) SetIcon(icon StatusIcon) error {
Expand Down
21 changes: 21 additions & 0 deletions app/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ func (host *fakeHost) SetDockBadge(text string) { host.badge = text }

func (host *fakeHost) SetProgress(fraction float32) { host.progress = fraction }

func (host *fakeHost) Post(fn func()) {
if fn != nil {
fn()
}
}

func (host *fakeHost) Quit() { host.quits++ }

func useHost(t *testing.T, host *fakeHost) {
Expand Down Expand Up @@ -513,3 +519,18 @@ func TestCaptureSystemShortcutsReachesThePlatformThatCanTakeThem(t *testing.T) {
t.Fatal("a closed window was still asked")
}
}

// Post hands the work to the host's event loop: the Application does not run it
// on the caller's goroutine itself.
func TestPostDelegatesToTheHost(t *testing.T) {
host := &fakeHost{}
application := &Application{host: host}
ran := false
application.Post(func() { ran = true })
if !ran {
t.Fatal("the host did not run the posted work")
}
application.Post(nil) // harmless
var nilApplication *Application
nilApplication.Post(func() { t.Fatal("a nil application ran work") })
}
7 changes: 7 additions & 0 deletions app/capabilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ const (
CapabilityReduceMotion
CapabilitySecretStoreAsync
CapabilityFontRegistrationAsync
// CapabilityPreventSleep means PreventSleep can hold the system out of
// idle sleep. It does not promise a Linux session has logind to ask.
CapabilityPreventSleep
// CapabilitySystemProxy means app/proxy.SystemProxy can read the desktop's
// proxy settings. Linux reads the environment only, and macOS reports a
// PAC policy as an error.
CapabilitySystemProxy
)

// Capabilities is a set of platform integrations.
Expand Down
4 changes: 3 additions & 1 deletion app/capabilities_native.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ func nativeCapabilities() Capabilities {
CapabilityFullscreen |
CapabilityWindowFrame |
CapabilityWindowMinimize |
CapabilityReduceMotion
CapabilityReduceMotion |
CapabilityPreventSleep |
CapabilitySystemProxy
if runtime.GOOS == "darwin" {
capabilities |= CapabilityNativeAppearance
} else {
Expand Down
115 changes: 115 additions & 0 deletions app/composition_dispatch_reentry_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package app

import (
"testing"

"github.com/vivaui/viva/gfx"
"github.com/vivaui/viva/internal/platform"
"github.com/vivaui/viva/text"
)

func TestPainterReentrantTextEventKeepsLatestAcknowledgment(t *testing.T) {
for _, mode := range []string{"nested edit", "ignored newline"} {
t.Run(mode, func(t *testing.T) {
editor := text.NewEditor("a")
editor.MoveTo(1, false)
owner := &painter{nativeText: platform.TextInput{Multiline: mode == "nested edit"}}
owner.nativeText.State = platform.EditorState(editor)
owner.activeText = &TextInput{State: TextStateOf(editor)}
owner.activeText.OnEvent = func(event TextEvent) (TextState, error) {
event.Apply(editor)
ack := TextStateOf(editor)
if event.Text == "r" {
nested := platform.TextEvent{Kind: platform.TextInsert, Text: "z"}
if mode == "ignored newline" {
nested = platform.TextEvent{Kind: platform.TextCommandEvent, Command: platform.TextInsertNewline}
}
if _, err := owner.applyTextEvent(nested); err != nil {
t.Fatal(err)
}
}
return ack, nil
}
ack, err := owner.applyTextEvent(platform.TextEvent{Kind: platform.TextInsert, Text: "r"})
want := TextStateOf(editor)
wantValue := "arz"
if mode == "ignored newline" {
wantValue = "ar"
}
if err != nil || want.Value != wantValue || owner.activeText.State != want ||
owner.nativeText.State != platform.EditorState(editor) || ack.WithoutRedraw() != platform.EditorState(editor) {
t.Fatalf("nested text acknowledgment: editor=%+v active=%+v native=%+v ack=%+v err=%v", want, owner.activeText.State, owner.nativeText.State, ack, err)
}
})
}
}

func TestPainterTextCallbackSyncPreservesInputOwnership(t *testing.T) {
for _, mode := range []string{"same owner fresh provider", "same owner geometry", "replacement owner", "identical direct replacement", "removed owner"} {
t.Run(mode, func(t *testing.T) {
first, second := text.NewEditor("a"), text.NewEditor("other")
first.MoveTo(1, false)
if mode == "identical direct replacement" {
second = text.NewEditor("a")
second.MoveTo(1, false)
}
current := first
extraWidth := float32(0)
var canvas gfx.Canvas
config := Config{Title: "reentrant provider", Width: 200, Height: 80}
config.Paint = func(canvas *gfx.Canvas, size gfx.Size) {
canvas.HitWithOptions(gfx.Item(11), gfx.Rect{Width: 120, Height: 24}, "Name", gfx.HitOptions{Role: gfx.RoleTextField})
}
var owner *painter
config.TextInput = func(context TextInputContext) *TextInput {
if current == nil {
return nil
}
editor := current
bounds := context.Bounds
bounds.Width += extraWidth
if mode == "identical direct replacement" && editor == second {
return &TextInput{Bounds: bounds, FontSize: 13, Editor: editor}
}
return &TextInput{Bounds: bounds, FontSize: 13, State: TextStateOf(editor), OnEvent: func(event TextEvent) (TextState, error) {
if mode == "replacement owner" || mode == "identical direct replacement" || mode == "removed owner" {
event.Apply(editor)
current = second
if mode == "removed owner" {
current = nil
}
owner.syncTextInput()
} else {
if mode == "same owner geometry" {
extraWidth = 10
}
owner.syncTextInput()
event.Apply(editor)
}
ack := TextStateOf(editor)
ack.Redraw = true
return ack, nil
}}
}
owner = newTestPainter(t, &canvas, config)
for _, kind := range []platform.PointerEventKind{platform.PointerMove, platform.PointerDown, platform.PointerUp} {
if _, err := owner.pointerEvent(platform.PointerEvent{Kind: kind, X: 10, Y: 10}); err != nil {
t.Fatal(err)
}
}
ack, err := owner.applyTextEvent(platform.TextEvent{Kind: platform.TextInsert, Text: "r"})
if mode == "removed owner" {
if err != nil || first.String() != "ar" || owner.activeText != nil || owner.textEnabled ||
ack.WithoutRedraw() != (platform.TextState{}) || !ack.Redraw {
t.Fatalf("removed provider acknowledgment: active=%+v enabled=%t ack=%+v error=%v", owner.activeText, owner.textEnabled, ack, err)
}
return
}
want := TextStateOf(current)
if err != nil || first.String() != "ar" || owner.activeText.State != want ||
owner.nativeText.State != platform.EditorState(current) || ack.WithoutRedraw() != platform.EditorState(current) || !ack.Redraw {
t.Fatalf("provider acknowledgment: editor=%+v active=%+v native=%+v ack=%+v err=%v", want, owner.activeText.State, owner.nativeText.State, ack, err)
}
})
}
}
Loading
Loading