Skip to content
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Stop resolving and emitting the whole tree when the platform reports only a new window frame, maximized state, lifecycle or title bar, as on every step of a window drag; what reads them through `Env` still updates (#178 by @houko).
- Convert macOS `nsgotest` captures and screenshots to sRGB, so their pixels no longer depend on whether the Mac's display is Display P3 (#311 by @houko).
- Stop a `tsx.View` that renders an `Export` from also running what the package's entry module mounts, with its effects, handlers, timers and animation frames (#923 by @houko).
- Search a `ui/chat` transcript from Mod+F in a find bar that unfolds folded turns and reasoning, marks the matches in `ui.TextView` and reasoning, reveals each match clear of the bar and the composer and gives the focus back as it closes, with `core.FocusedRef` to read the focused view (#47 by @houko).
- Add `TabStyle` and `IndicatorStyle` to `ui.Tabs` to restyle its tabs, the selected tab and the indicator (#958 by @houko).
- Reload a TSX `<WebView>` in place with the new script when `injectedJavaScriptBeforeContentLoaded` changes, as `core.WebView.InjectedJavaScriptBeforeContentFunc` does, rather than replacing the web view (#895 by @houko).
- Keep partial borders above Apple backdrop, material and glass layers while leaving app children above the border (#935 by @houko).
Expand Down
12 changes: 12 additions & 0 deletions core/element.go
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,18 @@ func (r *Ref) HoldsFocus() bool {
return false
}

// FocusedRef returns a reference to the element with the keyboard focus in cx's tree, as the platform last reported it, or nil when none has it; it is not tracked. The reference works while that element stays mounted, so what takes the focus without a trigger, such as a find bar a key opens, can give it back as it closes.
func FocusedRef(cx *Scope) *Ref {
if cx == nil {
return nil
}
t := cx.tree()
if t == nil || t.focus == nil {
return nil
}
return &Ref{t: t, n: t.focus}
}

// Before reports whether r's view comes before other's in tree order,
// the order Tab goes through them; views not mounted come last.
func (r *Ref) Before(other *Ref) bool {
Expand Down
6 changes: 3 additions & 3 deletions docs/architecture/text-search.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Text-level search

This is the shared design for issue [#47](https://github.com/nsgo-dev/nsgo/issues/47). `base/textview` and core's box reveal implement it; its [chat integration](#chat-integration) is still a goal. Chat transcript search will consume this capability; the matching rules and highlights belong to `base/textview`, so another document viewer can use them without importing `ui/chat`. Where it follows one of its [decisions](#decisions), confirmed by the user on 2026-11-15, the decision's number marks it.
This is the shared design for issue [#47](https://github.com/nsgo-dev/nsgo/issues/47). `base/textview`, core's box reveal and `ui/chat` implement it. The matching rules and highlights belong to `base/textview`, so another document viewer can use them without importing `ui/chat`. Where it follows one of its [decisions](#decisions), confirmed by the user on 2026-11-15, the decision's number marks it.

## What a view searches

Expand Down Expand Up @@ -66,9 +66,9 @@ A `TextView` joins the search in its `Search` field, else the one `ProvideSearch

## Chat integration

`ui/chat` then supplies a find bar with a field, count, previous/next and close actions. `Conversation` and `FloatingConversation` provide one search state to the text views for their turns, open it from Mod+F (Ctrl+F elsewhere) and focus the field; Escape in the bar closes it. Closing gives the focus back to where it was when the bar opened, unless it already left the bar, as a popover gives it back to its trigger ([components](components.md)); core cannot read the focused view today, so the implementation adds a way to record it. Each sets the reveal margin to the find bar's height, and `FloatingConversation` adds its composer's and `TopInset`, so a match lands clear of them. Revealing a match stops a following transcript from following (`ConversationState`'s `pause`), so a streaming reply does not pull it back to the end. The bar's words, through `ui/chat/locales` in ICU MessageFormat ([languages](languages.md)), are “Find”, “Previous”, “Next”, “Close”, “No results” and “{selected, number} of {count, number}”. It does not implement matching, span splitting or cross-view counting.
`ui/chat` supplies a find bar with a field, count, previous/next and close actions. `Conversation` and `FloatingConversation` provide one search state to the text views for their turns, open it from Mod+F (Ctrl+F elsewhere) and focus the field; Escape closes it. Closing gives the focus back to where it was when the bar opened, unless it already left the bar, as a popover gives it back to its trigger ([components](components.md)); `core.FocusedRef` records that element for the overlay. Each sets the reveal margin to the find bar's height, and `FloatingConversation` adds its `TopInset` and its composer's height at the bottom, so a match lands clear of both. Revealing a match stops a following transcript from following (`ConversationState`'s `pause`), so a streaming reply does not pull it back to the end. The bar's words, through `ui/chat/locales` in ICU MessageFormat ([languages](languages.md)), are “Find”, “Previous”, “Next”, “Close”, “No results” and “{selected, number} of {count, number}”. It does not implement matching, span splitting or cross-view counting.

A completed turn folds its steps and a completed reasoning block its detail, building nothing hidden, so their text views do not exist to register. While the search is open with a query, a turn and a reasoning block that share the transcript's `ConversationState` unfold without recording a choice of the user's, and fold again by their own rules when it closes (decision 5); the transcript does not virtualize, so this mounts no more than a transcript the user unfolded. A reasoning block's default body is a plain `core.Text`, so it becomes a one-paragraph `TextView` to be searched. Only text views register: what a step or a prompt shows with other components is not searched.
A completed turn folds its steps and a completed reasoning block its detail, building nothing hidden, so their text views do not exist to register. While the search is open with a query, a turn and a reasoning block that share the transcript's `ConversationState` unfold without recording a choice of the user's, and fold again by their own rules when it closes (decision 5); the transcript does not virtualize, so this mounts no more than a transcript the user unfolded. A reasoning block's default body is a one-paragraph `TextView` of its text, which it does not read as Markdown, so it is searched. Only text views register: what a step or a prompt shows with other components is not searched.

## Verification

Expand Down
2 changes: 1 addition & 1 deletion docs/public/en/accessibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Tooltips describe their trigger before it receives focus. `View.Tooltip`, `base.

A `base.DataTable` exposes its named grid as the keyboard and accessibility focus stop; the pointer hit layer is hidden from assistive technology.

On desktops, the web and an Apple TV, views that take presses are Tab stops beside text fields; `NoFocus` keeps one out and `Focusable` makes a view without presses a stop. `Style.FocusVisible` draws the focus ring only when the keyboard moved the focus (`focus-visible:`), `Style.Focus` any focus and `Style.FocusWithin` the focus inside a view, `OnFocus` and `OnBlur` hear it, `OnBlur` also as the focused view leaves the tree, and `Ref.Focus()` and `Ref.SetAccessibilityFocus()` move it. Return and Space press the focused view, and arrow keys move through tab lists, radio groups and menus. A view's `Tooltip` shows at once when the keyboard moves the focus to it, until the focus leaves or Escape is pressed. A popup's `OnOpen` runs once its content is there, so a `Focus` there moves the focus in, as a non-modal dialog's should; a popover's content follows its trigger in the Tab order, and the focus goes back to the trigger as the popup closes.
On desktops, the web and an Apple TV, views that take presses are Tab stops beside text fields; `NoFocus` keeps one out and `Focusable` makes a view without presses a stop. `Style.FocusVisible` draws the focus ring only when the keyboard moved the focus (`focus-visible:`), `Style.Focus` any focus and `Style.FocusWithin` the focus inside a view, `OnFocus` and `OnBlur` hear it, `OnBlur` also as the focused view leaves the tree, and `Ref.Focus()` and `Ref.SetAccessibilityFocus()` move it; `core.FocusedRef(cx)` is a ref to the view that has it, for what opens without a trigger, such as a find bar from a key, to give it back as it closes. Return and Space press the focused view, and arrow keys move through tab lists, radio groups and menus. A view's `Tooltip` shows at once when the keyboard moves the focus to it, until the focus leaves or Escape is pressed. A popup's `OnOpen` runs once its content is there, so a `Focus` there moves the focus in, as a non-modal dialog's should; a popover's content follows its trigger in the Tab order, and the focus goes back to the trigger as the popup closes.

`cx.Env().ScreenReader()` says whether one runs, `cx.Env().ReduceMotion()` whether the user asked for less motion, `cx.Env().IncreaseContrast()` whether the user asked for more contrast (Increase Contrast on macOS, iOS and watchOS, a Windows contrast theme, GNOME's High Contrast, GTK 4.20's contrast setting or a high-contrast GTK theme, Android 14's contrast setting above standard, `prefers-contrast: more` or `forced-colors: active` on the web), `cx.Env().FontScale()` the text size, and `cx.Env().RTL()` the layout direction. Texts follow the text size unless `NoFontScaling` is set, and a layout that is right to left mirrors its physical edges when it uses the logical ones.

Expand Down
2 changes: 2 additions & 0 deletions docs/public/en/ui/text.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ textview.TextView{Markdown: "## Notes\n\nA **native** document.", Styles: ui.Tex
OnLinkPress: func(e textview.LinkPressEvent) { open(e.URL) }}
```

`textview.NewSearch` searches the text a `TextView` shows and highlights its matches. Give several views the same search with `textview.ProvideSearch`, then call `Open`, `SetQuery`, `Next` and `Previous`; `Count` and `Selected` report the result. Search parts are styled with `textview.PartSearch` and `textview.PartSearchSelected`.

## Selection and accessibility

`SelectableOn` lets the user select and copy a text. A `core.View` with `Selectable` makes its texts select together in document order. A `Role` such as `RoleHeader` tells assistive technology what the text is, and `Label` replaces it when the words are not the label.
Expand Down
2 changes: 1 addition & 1 deletion docs/public/zh/accessibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ core.Text{ContentFunc: func() string { return fmt.Sprintf("购物车里有 %d

`base.DataTable` 将带标签的网格作为键盘和辅助功能的焦点停靠点;指针命中层对辅助技术隐藏。

在桌面、Web 和 Apple TV 上,可按压的视图和文本框一起成为 Tab 停靠点;`NoFocus` 让一个视图退出,`Focusable` 让没有按压的视图成为停靠点。`Style.FocusVisible` 只在键盘移动焦点时绘制焦点环(`focus-visible:`),`Style.Focus` 对应任何焦点,`Style.FocusWithin` 对应视图内的焦点,`OnFocus` 和 `OnBlur` 听到焦点变化(获得焦点的视图离开树时也会收到 `OnBlur`),`Ref.Focus()` 和 `Ref.SetAccessibilityFocus()` 移动焦点。Return 和空格按下获得焦点的视图,方向键在标签列表、单选组和菜单中移动。键盘把焦点移到视图上时,它的 `Tooltip` 立即显示,直到焦点离开或按下 Escape。弹出层的 `OnOpen` 在内容就绪后运行,在其中调用 `Focus` 就能把焦点移进去,非模态对话框应当这样做;popover 的内容在 Tab 顺序中紧跟触发器,弹出层关闭时焦点回到触发器。
在桌面、Web 和 Apple TV 上,可按压的视图和文本框一起成为 Tab 停靠点;`NoFocus` 让一个视图退出,`Focusable` 让没有按压的视图成为停靠点。`Style.FocusVisible` 只在键盘移动焦点时绘制焦点环(`focus-visible:`),`Style.Focus` 对应任何焦点,`Style.FocusWithin` 对应视图内的焦点,`OnFocus` 和 `OnBlur` 听到焦点变化(获得焦点的视图离开树时也会收到 `OnBlur`),`Ref.Focus()` 和 `Ref.SetAccessibilityFocus()` 移动焦点;`core.FocusedRef(cx)` 返回指向当前焦点视图的 ref,供没有触发器、由按键打开的界面(例如查找栏)在关闭时把焦点交还。Return 和空格按下获得焦点的视图,方向键在标签列表、单选组和菜单中移动。键盘把焦点移到视图上时,它的 `Tooltip` 立即显示,直到焦点离开或按下 Escape。弹出层的 `OnOpen` 在内容就绪后运行,在其中调用 `Focus` 就能把焦点移进去,非模态对话框应当这样做;popover 的内容在 Tab 顺序中紧跟触发器,弹出层关闭时焦点回到触发器。

`cx.Env().ScreenReader()` 说明是否有屏幕阅读器运行,`cx.Env().ReduceMotion()` 说明用户是否要求减少动态效果,`cx.Env().IncreaseContrast()` 说明用户是否要求增强对比度(macOS、iOS 和 watchOS 的“增强对比度”、Windows 的对比度主题、GNOME 的高对比度、GTK 4.20 的对比度设置或高对比度 GTK 主题、Android 14 高于标准的对比度设置,Web 上的 `prefers-contrast: more` 或 `forced-colors: active`),`cx.Env().FontScale()` 是文本大小,`cx.Env().RTL()` 是布局方向。除非设置 `NoFontScaling`,文本会跟随文本大小;从右到左的布局使用逻辑边时会镜像物理边。

Expand Down
2 changes: 2 additions & 0 deletions docs/public/zh/ui/text.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ textview.TextView{Markdown: "## 笔记\n\n一份 **原生** 文档。", Styles:
OnLinkPress: func(e textview.LinkPressEvent) { open(e.URL) }}
```

`textview.NewSearch` 搜索 `TextView` 显示的文字并高亮匹配项。将同一个 search 通过 `textview.ProvideSearch` 提供给多个视图,然后调用 `Open`、`SetQuery`、`Next` 和 `Previous`;`Count` 和 `Selected` 返回结果。用 `textview.PartSearch` 和 `textview.PartSearchSelected` 设置搜索部分的样式。

## 选择与无障碍

`SelectableOn` 让用户选择和复制文本。带 `Selectable` 的 `core.View` 让其中的文本按文档顺序一起选择。`RoleHeader` 之类的 `Role` 告诉辅助技术这段文字是什么,`Label` 在原文不适合朗读时替换它。
Expand Down
8 changes: 0 additions & 8 deletions docs/roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,6 @@ What `base/terminal` still lacks of a terminal app's features, Ghostty's the ref
| Drawn box characters, blinking and contrast | `cursor-style-blink`, `minimum-contrast`, `window-padding-color` | Box drawing, blocks and Powerline's separators are drawn so lines join, the cursor blinks, and minimum contrast and padding colors apply |
| Search, images and shell integration | Find, the Kitty graphics protocol, `shell-integration` | A search highlights matches, programs show images, and OSC 133 prompts take Option+click to move the cursor |

## Text views

What `base/textview` and `ui/chat` still lack, from NSGo's own issues ([text view](architecture/textview.md)).

| Item | Reference | Done when |
| --- | --- | --- |
| Transcript search | NSGo's [#47](https://github.com/nsgo-dev/nsgo/issues/47), [text-level search](architecture/text-search.md#chat-integration) | `ui/chat` adds a transcript find bar on `textview.Search`, opened with Mod+F, unfolding folded turns and reasoning while it is open and giving the focus back as it closes |

## Widgets

What package `widget` lacks of WidgetKit and ActivityKit, and of widgets and Live Activities elsewhere ([tool](architecture/tool.md#widgets)).
Expand Down
4 changes: 4 additions & 0 deletions ui/chat/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ func (t Turn) Render(cx *core.Scope) core.Node {
choice := core.NewSignal(cx, uint8(0))
folded := false
open := core.NewMemo(cx, func() bool {
// A search unfolds the turn without a choice of the user's, which its rules take up again once it closes.
if t.Conversation != nil && t.Conversation.searching() {
return true
}
held := hold()
if c := choice.Get(); c != 0 {
return c == 1
Expand Down
85 changes: 85 additions & 0 deletions ui/chat/chat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"github.com/nsgo-dev/nsgo/base"
"github.com/nsgo-dev/nsgo/base/textview"
"github.com/nsgo-dev/nsgo/core"
"github.com/nsgo-dev/nsgo/icons/lucide"
"github.com/nsgo-dev/nsgo/internal/driver"
Expand Down Expand Up @@ -77,6 +78,90 @@ func startChat(t *testing.T, e core.Environment) (*nsgotest.App, *chatStage) {
return app, s
}

// TestConversationSearch searches folded steps and reasoning across turns from Mod+F, reveals each selected match clear of the find bar and the floating composer, and closes with Escape, the focus back in the composer and the turns folded again.
func TestConversationSearch(t *testing.T) {
var state *ConversationState
app := start(t, desktopEnv, func(cx *core.Scope) core.Node {
state = NewConversationState(cx)
draft := core.NewSignal(cx, "")
turn := func(n int) core.Node {
id := strconv.Itoa(n)
word := "hay"
if n%4 == 0 {
word = "needle"
}
return Turn{Status: func() Status { return Completed }, HasFinal: func() bool { return true }, Conversation: state,
Summary: func() string { return "Worked " + id }, Prompt: func(*core.Scope) core.Node { return core.Text{Content: "Prompt " + id} },
Reasoning: func(*core.Scope) core.Node {
return Reasoning{Text: func() string { return "reason " + id + " " + word }, Status: func() Status { return Completed }, Conversation: state}
},
Steps: func() []Step {
return []Step{{ID: "step", Message: func(*core.Scope) core.Node {
return textview.TextView{Markdown: "step " + id + " " + word}
}}}
},
Final: func(*core.Scope) core.Node {
return core.View{Style: core.Style{Height: core.Pt(240)}, Children: []core.Node{core.Text{Content: "Answer " + id}}}
}}
}
var turns []core.Node
for n := range 12 {
turns = append(turns, turn(n+1))
}
return core.View{Style: core.Style{Height: core.Pt(700)}, Children: []core.Node{FloatingConversation{State: state, JumpLabel: "Latest", TopInset: 20, Children: turns,
Composer: []core.Node{Composer{Draft: draft.Get, OnDraftChange: draft.Set, Label: "Message", SendLabel: "Send", StopLabel: "Stop", Glass: true, State: state}}}}}
})
if app.Exists("text:reason 4 needle") {
t.Fatal("a completed turn's reasoning should start folded")
}
app.Focus("id:composer")
app.Key("mod+f")
if !app.Find("id:chat-find-input").Focused {
t.Fatal("Mod+F did not focus the find field")
}
if app.Exists("text:reason 4 needle") {
t.Fatal("the find bar unfolded the transcript before a query")
}
app.Type("id:chat-find-input", "needle")
if !app.Exists("text:1 of 6") {
t.Fatalf("the count is not 1 of 6\n%s", app.Dump())
}
if !app.Exists("text:reason 4 needle") || !app.Exists("text:step 12 needle") {
t.Fatal("the search did not unfold the transcript's reasoning and steps")
}
clear := func(n int) {
t.Helper()
match, ok := state.Search().SelectedBounds()
bar, composer := app.Find("id:chat-find-input").Parent.Bounds(), app.Find("id:chat-composer").Bounds()
if !ok || match.Origin.Y < bar.Origin.Y+bar.Size.Height || match.Origin.Y+match.Size.Height > composer.Origin.Y {
t.Fatalf("match %d at %v is not clear of the bar %v and the composer %v", n, match, bar, composer)
}
}
clear(1)
for n := 2; n <= 6; n++ {
app.Press("id:chat-find-next")
if !app.Exists("text:" + strconv.Itoa(n) + " of 6") {
t.Fatalf("after next the count is not %d of 6", n)
}
clear(n)
}
app.Press("id:chat-find-previous")
if !app.Exists("text:5 of 6") {
t.Fatal("previous did not go back to 5 of 6")
}
app.Focus("id:chat-find-input")
app.Key("escape")
if app.Exists("id:chat-find-input") {
t.Fatal("Escape left the find bar open")
}
if !app.Find("id:composer").Focused {
t.Fatal("closing the find bar did not give the focus back to the composer")
}
if app.Exists("text:reason 4 needle") {
t.Fatal("the reasoning stayed unfolded after the search closed")
}
}

// TestTurnFolds checks a live group, then the fold a completed turn
// takes with its final response, and that a choice outlives updates.
func TestTurnFolds(t *testing.T) {
Expand Down
Loading