新增: skills 视图与标题编辑测试(未落库功能批量入库)

This commit is contained in:
lxy
2026-08-23 18:25:02 +08:00
parent 95f349bcd7
commit d54d0c4c63
12 changed files with 985 additions and 37 deletions
+47 -4
View File
@@ -200,10 +200,53 @@ func (m *Model) detailColumnLines(w, listH int) []string {
}
// 标题行:编辑模式显示输入框,否则显示普通标题
if m.editTitleMode {
editLine := " ✏ " + m.editTitleBuf
editW := w - 4
if lipgloss.Width(editLine) > editW {
editLine = truncateByWidth(editLine, editW-2) + "…"
prefix := " ✏ "
prefixW := stringWidth(prefix)
contentW := w - prefixW // 内容区可用宽度
text := m.editTitleBuf
textRunes := []rune(text)
cursor := m.editTitleCursor
if cursor > len(textRunes) {
cursor = len(textRunes)
}
// 计算可见窗口 [start, end):文本超宽时以光标为中心滚动,保证光标可见
start, end := 0, len(textRunes)
if stringWidth(text) > contentW && contentW > 0 {
halfW := contentW / 2
start = cursor
acc := 0
for start > 0 && acc < halfW {
start--
acc += runeWidth(textRunes[start])
}
end = start
acc = 0
for end < len(textRunes) {
rw := runeWidth(textRunes[end])
if acc+rw > contentW {
break
}
acc += rw
end++
}
for cursor >= end && end > start {
start++
end++
}
}
// 将 ▏ 光标嵌入到文本中(同一行),不单独占一行
visible := string(textRunes[start:end])
relCursor := cursor - start
var editLine string
vr := []rune(visible)
if relCursor <= 0 {
editLine = prefix + "▏" + visible
} else if relCursor >= len(vr) {
editLine = prefix + visible + "▏"
} else {
editLine = prefix + string(vr[:relCursor]) + "▏" + string(vr[relCursor:])
}
lines = append(lines, style.InputStyle.Render(fitWidth(editLine, w)))
lines = append(lines, style.DimFg.Render(fitWidth(" [Enter]save [Esc]cancel", w)))