Fix sorting of features in UI

This commit is contained in:
Kovid Goyal 2024-05-30 10:58:13 +05:30
parent a2b296d73e
commit 6e29561486
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
2 changed files with 35 additions and 11 deletions

View file

@ -133,29 +133,33 @@ func (self *face_panel) draw_font_features(_ loop.ScreenSize, start_y int, previ
return
}
formatted := make([]string, 0, len(preview.Features))
sort_keys := make(map[string]string)
for feat_tag, data := range preview.Features {
var text string
var text, sort_key string
if preview.Applied_features[feat_tag] != "" {
text = preview.Applied_features[feat_tag]
sort_key = text
if sort_key[0] == '-' || sort_key[1] == '+' {
sort_key = sort_key[1:]
}
text = strings.Replace(text, "+", lp.SprintStyled("fg=green", "+"), 1)
text = strings.Replace(text, "-", lp.SprintStyled("fg=red", "-"), 1)
text = strings.Replace(text, "=", lp.SprintStyled("fg=cyan", "="), 1)
if data.Name != "" {
text = fmt.Sprintf("%s: %s", data.Name, text)
text = data.Name + ": " + text
sort_key = data.Name
}
} else {
text = utils.IfElse(data.Name == "", feat_tag, data.Name)
sort_key = text
text = lp.SprintStyled("dim", text)
}
formatted = append(formatted, tui.InternalHyperlink(text, "feature:"+feat_tag))
f := tui.InternalHyperlink(text, "feature:"+feat_tag)
sort_keys[f] = strings.ToLower(sort_key)
formatted = append(formatted, f)
}
utils.SortWithKey(formatted, func(a string) string {
ans := strings.ToLower(wcswidth.StripEscapeCodes(a))
if ans[0] == '-' || ans[0] == '+' {
ans = ans[1:]
}
return ans
})
utils.SortWithKey(formatted, func(a string) string { return sort_keys[a] })
line := lp.SprintStyled(control_name_style, `Features`) + ": " + strings.Join(formatted, ", ")
y = self.render_lines(start_y, ``, line)
return

View file

@ -5,6 +5,7 @@ import (
"strconv"
"strings"
"kitty/tools/tui"
"kitty/tools/tui/loop"
"kitty/tools/tui/readline"
"kitty/tools/utils"
@ -49,6 +50,15 @@ func (self *if_panel) draw_screen() (err error) {
}
lines = append(lines, "")
cursor_y := self.render_lines(2, lines...)
if len(self.feature_data.Params) > 0 {
lp.MoveCursorTo(1, cursor_y+3)
num := 1
strings.Join(utils.Map(func(x string) string {
ans := tui.InternalHyperlink(x, fmt.Sprintf("fval:%d", num))
num++
return ans
}, self.feature_data.Params), ", ")
}
lp.MoveCursorTo(1, cursor_y+1)
lp.ClearToEndOfLine()
self.rl.RedrawNonAtomic()
@ -67,7 +77,17 @@ func (self *if_panel) on_wakeup() error {
}
func (self *if_panel) on_click(id string) (err error) {
return
scheme, val, _ := strings.Cut(id, ":")
if scheme != "fval" {
return
}
v, _ := strconv.ParseUint(val, 10, 64)
if err = self.handler.face_pane.change_feature_value(self.feat_tag, uint(v), false); err != nil {
return err
}
self.handler.current_pane = &self.handler.face_pane
return self.handler.draw_screen()
}
func (self *if_panel) on_key_event(event *loop.KeyEvent) (err error) {