Files
MujicaUI/docs/components/228-context-mention-menu.md
T

45 lines
1.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 228 ContextMentionMenu 上下文提及菜单
## 用途
输入“@”选择文件、文档、网页等上下文;分组;异步结果。
## 最小示例
```go
var prompt string
var found []mujica.ContextItem
view := func(c *ui.Context) {
mujica.Use(c, mujica.Settings{})
composer := mujica.PromptComposer(c, &prompt, mujica.PromptComposerOptions{})
r := mujica.ContextMentionMenu(c, composer, &prompt, found, mujica.ContextMentionOptions{})
if r.QueryChanged() {
found = []mujica.ContextItem{{ID: "f1", Label: r.Query() + ".md", Kind: mujica.ContextFile}}
}
if item, ok := r.Chosen(); ok {
fmt.Println("attach", item.ID)
}
}
ui.Render(view, 400, 300, 1)
```
## 参数
`composer` 与 `value` 关联当前编辑器;`items` 每项 `ID`、`Label` 必填,`Detail` 可选,`Kind` 为 ContextFile、ContextDoc 或 ContextWeb;`Loading=false`。
## 状态
默认、悬停、键盘焦点与祖先禁用;业务状态由调用方提供。
## 事件
QueryChanged() 请求新查询;Query() 返回查询文本;Chosen() 返回上下文并移除尾部提及文字。
## 键盘操作
编辑器内 Up/Down 选择,Enter 或 Tab 附加,Escape 关闭。
## 限制
异步结果由调用方提供并调用 c.Invalidate(),调用方负责淘汰过期请求。