修复: 技能面板视口按行收口与截断尾部乱码
- 技能列表视口改按行数切片(含描述行),修复变长条目撑爆面板 - 大文件截断改按 rune 边界回退,修复中文内容尾部乱码 - 补视口与截断边界测试
This commit is contained in:
+28
-7
@@ -65,10 +65,16 @@ func (m *Model) skillsListLines(w, listH int) []string {
|
||||
if len(skills) == 0 {
|
||||
return []string{style.DimFg.Render(fitWidth(" empty", w))}
|
||||
}
|
||||
start, end := viewport(m.Skills.SkillCur, len(skills), listH)
|
||||
var lines []string
|
||||
for i := start; i < end; i++ {
|
||||
sk := skills[i]
|
||||
// 先为所有技能累积全部行(含描述行),再按行数视口切片,
|
||||
// 避免按条目数计算视口导致变长行撑爆面板
|
||||
type skillBlock struct {
|
||||
lines []string
|
||||
}
|
||||
var blocks []skillBlock
|
||||
totalLines := 0
|
||||
curLineOffset := 0
|
||||
|
||||
for i, sk := range skills {
|
||||
cur := " "
|
||||
if i == m.Skills.SkillCur {
|
||||
cur = "▸"
|
||||
@@ -78,7 +84,7 @@ func (m *Model) skillsListLines(w, listH int) []string {
|
||||
if i == m.Skills.SkillCur && m.Skills.FocusPanel == 0 {
|
||||
sty = style.SelStyle
|
||||
}
|
||||
lines = append(lines, sty.Render(padRightByWidth(truncateByWidth(line, w), w)))
|
||||
blockLines := []string{sty.Render(padRightByWidth(truncateByWidth(line, w), w))}
|
||||
// 如果有描述,追加一行
|
||||
if sk.Description != "" {
|
||||
descLine := " " + sk.Description
|
||||
@@ -86,10 +92,25 @@ func (m *Model) skillsListLines(w, listH int) []string {
|
||||
if i == m.Skills.SkillCur && m.Skills.FocusPanel == 0 {
|
||||
descSty = style.SelStyle
|
||||
}
|
||||
lines = append(lines, descSty.Render(padRightByWidth(truncateByWidth(descLine, w), w)))
|
||||
blockLines = append(blockLines, descSty.Render(padRightByWidth(truncateByWidth(descLine, w), w)))
|
||||
}
|
||||
if i == m.Skills.SkillCur {
|
||||
curLineOffset = totalLines
|
||||
}
|
||||
totalLines += len(blockLines)
|
||||
blocks = append(blocks, skillBlock{lines: blockLines})
|
||||
}
|
||||
return lines
|
||||
|
||||
start, end := viewport(curLineOffset, totalLines, listH)
|
||||
|
||||
var allLines []string
|
||||
for _, b := range blocks {
|
||||
allLines = append(allLines, b.lines...)
|
||||
}
|
||||
if end > len(allLines) {
|
||||
end = len(allLines)
|
||||
}
|
||||
return allLines[start:end]
|
||||
}
|
||||
|
||||
func (m *Model) skillsFileLines(w, listH int) []string {
|
||||
|
||||
Reference in New Issue
Block a user