T1 移动包同步(internal/app/movepkg.go + renameentry.go)
gopls 不声明 willRename,改用 go/parser 精确定位 ImportSpec.Path,
目录移动改全仓 import 路径、单文件跨目录移动改 package 声明。
写盘失败整体恢复并回滚 rename;已打开且无改动的缓冲区用 Reset 同步。
集成测试在临时 Go 模块里移目录后直接跑 go build ./... 通过。
T2 输出/问题面板右键(panel_menu.go + output.go + popmenu.go)
新增 openPopAt 让菜单贴指针弹出;复制选中行/复制全部/清空输出。
真窗口截图确认位置正确、无裁切。
**范围缩窄**:终端从 mygo v0.7.4 起就自带原生 ContextMenu,原判断是误报。
T3 snippet 补全(completion_snippet.go + lsp/protocol.go)
snippetSupport 改 true;实测 gopls v0.23 返回 insertTextFormat=2、
textEdit.newText="Print(${1:})",接上 mygo v0.9.0 的 ParseSnippet。
解析失败降级成纯文本(支持嵌套占位/choices 剥离),结果按模板缓存。
端到端 Tester 验证接受补全后得到 fmt.Print() 且光标停在括号内。
T4 本地历史超限可见(history.go)
静默 return 改为返回 histSkipped,输出面板提示;每文件整个会话只提一次。
T5 全局搜索并发(palette.go)
NumCPU(上限 8)个 worker 并发读盘,结果按文件序合并保证顺序稳定;
命中上限停止派发;512KB 以上被跳过的文件数显示成面板底部提示。
T6 清理根目录残留;4 个 0 字节 .sock 被环境安全守卫拦住未删(已 gitignore)。
验证:gofmt 空、build/vet OK、go test -count=1 ./... 全绿(282 个测试)、
新增并发/剪贴板/回滚用例 go test -race 无数据竞争。
docs/MyGoland-待办与规划.md 已清空待办,只剩 6 项规划与完成索引。
185 lines
4.7 KiB
Go
185 lines
4.7 KiB
Go
package app
|
||
|
||
import (
|
||
"github.com/egoist/mygo"
|
||
"github.com/egoist/mygo/ui"
|
||
)
|
||
|
||
// menuEntry 是自绘菜单里的一项。
|
||
//
|
||
// 为什么不用系统菜单:mygo 的 Menu/ContextMenu 在 Windows 上是**原生菜单**,
|
||
// 字号、行高、圆角全由系统画(150% 缩放下 9pt 显得又大又粗),应用改不了。
|
||
// 想跟 IDE 其他部分(12px 文字、8px 圆角、深色卡片)协调,只能自绘。
|
||
type menuEntry struct {
|
||
label string
|
||
shortcut string
|
||
disabled bool
|
||
divider bool
|
||
action func()
|
||
}
|
||
|
||
// entriesFromMenu 把 mygo 的菜单项翻译成自绘项。子菜单只支持一层。
|
||
func entriesFromMenu(items []*mygo.MenuItem) []menuEntry {
|
||
out := make([]menuEntry, 0, len(items))
|
||
for _, it := range items {
|
||
if it == nil || it.Hidden {
|
||
continue
|
||
}
|
||
if it.Type == mygo.MenuItemSeparator {
|
||
out = append(out, menuEntry{divider: true})
|
||
continue
|
||
}
|
||
e := menuEntry{
|
||
label: it.Label,
|
||
shortcut: shortcutText(it.Accelerator),
|
||
disabled: it.Disabled,
|
||
}
|
||
if it.Click != nil {
|
||
item, click := it, it.Click
|
||
e.action = func() { click(item, nil) }
|
||
}
|
||
out = append(out, e)
|
||
}
|
||
return out
|
||
}
|
||
|
||
// shortcutText 把 "CmdOrCtrl+Shift+M" 缩写成本平台的样子。
|
||
func shortcutText(acc string) string {
|
||
if acc == "" {
|
||
return ""
|
||
}
|
||
repl := map[string]string{
|
||
"CmdOrCtrl+": "Ctrl+", "CommandOrControl+": "Ctrl+",
|
||
"Cmd+": "Win+", "Command+": "Win+",
|
||
}
|
||
out := acc
|
||
for k, v := range repl {
|
||
if len(out) >= len(k) && out[:len(k)] == k {
|
||
out = v + out[len(k):]
|
||
break
|
||
}
|
||
}
|
||
return out
|
||
}
|
||
|
||
// openPop 在 anchor 下沿弹出自绘面板。
|
||
//
|
||
// 只记矩形、不记元素:ui.Element 只能在本帧使用(跨帧会 panic:
|
||
// "element from pass N used in pass N+1"),而面板是下一帧才画的。
|
||
func (a *App) openPop(anchor ui.Element, entries []menuEntry) {
|
||
if len(entries) == 0 || a.win == nil {
|
||
return
|
||
}
|
||
a.openPopAt(anchor.Bounds(), entries)
|
||
}
|
||
|
||
// openPopAt 在给定矩形下沿弹出菜单。
|
||
//
|
||
// 用在整块列表上:列表的 Bounds 是一大片,直接拿它当锚点会把菜单顶到
|
||
// 屏幕外面。右键时传一个零宽的小矩形(指针位置)就能贴着鼠标弹。
|
||
func (a *App) openPopAt(r ui.Rect, entries []menuEntry) {
|
||
if len(entries) == 0 || a.win == nil {
|
||
return
|
||
}
|
||
a.popRect = r
|
||
a.popEntries = entries
|
||
a.popOpen = true
|
||
a.popJustOpened = true
|
||
a.win.Update(func() {})
|
||
}
|
||
|
||
// closePop 收起菜单。
|
||
func (a *App) closePop() {
|
||
a.popOpen = false
|
||
a.popEntries = nil
|
||
}
|
||
|
||
// popMenu 画当前打开的菜单。要挂在根级(Popover 是覆盖层)。
|
||
func (a *App) popMenu(c *ui.Context) {
|
||
if !a.popOpen || len(a.popEntries) == 0 {
|
||
return
|
||
}
|
||
t := c.Theme()
|
||
|
||
// 位置:优先贴锚点下沿;超出窗口就往回收,避免面板被裁掉。
|
||
const panelW float32 = 190
|
||
x, y := a.popRect.X, a.popRect.Y+a.popRect.H+2
|
||
if w, h := c.Size(); w > 0 {
|
||
if x+panelW > w-6 {
|
||
x = w - panelW - 6
|
||
}
|
||
if x < 6 {
|
||
x = 6
|
||
}
|
||
// 高度按项数估:每项约 24,分隔线 11。
|
||
est := float32(8)
|
||
for _, en := range a.popEntries {
|
||
if en.divider {
|
||
est += 11
|
||
} else {
|
||
est += 24
|
||
}
|
||
}
|
||
if y+est > h-6 {
|
||
y = a.popRect.Y - est - 2
|
||
}
|
||
if y < 6 {
|
||
y = 6
|
||
}
|
||
}
|
||
|
||
ui.Overlay(c, func() {
|
||
// 遮罩:点它关闭。但打开的那一帧要跳过——判定会把这次点击当成
|
||
// 「点了外面」,面板刚出来就被收回去(表现为「点了没反应」)。
|
||
back := ui.Box(c).Absolute().Left(0).Top(0).Right(0).Bottom(0).Modal()
|
||
if a.popJustOpened {
|
||
a.popJustOpened = false
|
||
} else if back.Clicked() {
|
||
a.closePop()
|
||
a.win.Update(func() {})
|
||
return
|
||
}
|
||
|
||
ui.Column(c).Absolute().Left(x).Top(y).Width(panelW).
|
||
Padding(5).Gap(1).Radius(t.Radius).
|
||
Background(t.Surface).BorderWidth(1).BorderColor(t.Border).
|
||
Shadow(0, 8, 24, 0, ui.RGBA(0, 0, 0, 0.35)).
|
||
Children(func() {
|
||
for _, en := range a.popEntries {
|
||
en := en
|
||
if en.divider {
|
||
ui.Box(c).FillWidth().Height(1).Background(t.Border).
|
||
Margin(4, 0)
|
||
continue
|
||
}
|
||
fg := t.Text
|
||
if en.disabled {
|
||
fg = t.TextMuted
|
||
}
|
||
btn := ui.ButtonBase(c).FillWidth().Padding(4, 8).Radius(4).
|
||
Justify(ui.Start).Cursor(ui.CursorPointer)
|
||
btn.Children(func() {
|
||
ui.Row(c).FillWidth().Gap(14).AlignItems(ui.Center).Children(func() {
|
||
ui.Text(c, en.label).FontSize(12).TextColor(fg).SingleLine()
|
||
ui.Box(c).Grow(1)
|
||
if en.shortcut != "" {
|
||
ui.Text(c, en.shortcut).FontSize(10).
|
||
TextColor(t.TextMuted).SingleLine()
|
||
}
|
||
})
|
||
})
|
||
if en.disabled {
|
||
continue
|
||
}
|
||
if btn.Clicked() {
|
||
a.closePop()
|
||
if en.action != nil {
|
||
en.action()
|
||
}
|
||
a.win.Update(func() {})
|
||
}
|
||
}
|
||
})
|
||
})
|
||
}
|