Wire up the new subseq match code

This commit is contained in:
Kovid Goyal 2023-03-12 21:34:54 +05:30
parent 29dd2438c9
commit 6794ec1de7
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 14 additions and 22 deletions

View File

@ -22,8 +22,6 @@ from kitty.fast_data_types import Color
from kitty.options.types import Options as KittyOptions from kitty.options.types import Options as KittyOptions
from kitty.utils import reload_conf_in_all_kitties from kitty.utils import reload_conf_in_all_kitties
from ..choose.match import match
MARK_BEFORE = '\033[33m' MARK_BEFORE = '\033[33m'
MARK_AFTER = '\033[39m' MARK_AFTER = '\033[39m'

View File

@ -819,11 +819,6 @@ def compile_kittens(compilation_database: CompilationDatabase) -> None:
files('unicode_input', 'unicode_names'), files('unicode_input', 'unicode_names'),
files('diff', 'diff_speedup'), files('diff', 'diff_speedup'),
files('transfer', 'rsync', libraries=('rsync',)), files('transfer', 'rsync', libraries=('rsync',)),
files(
'choose', 'subseq_matcher',
extra_headers=('kitty/charsets.h',),
extra_sources=('kitty/charsets.c',),
filter_sources=lambda x: 'windows_compat.c' not in x),
): ):
final_env = kenv.copy() final_env = kenv.copy()
final_env.cflags.extend(f'-I{x}' for x in includes) final_env.cflags.extend(f'-I{x}' for x in includes)

View File

@ -20,6 +20,7 @@ import (
"kitty/tools/cli" "kitty/tools/cli"
"kitty/tools/config" "kitty/tools/config"
"kitty/tools/tui/subseq"
"kitty/tools/utils" "kitty/tools/utils"
"kitty/tools/utils/style" "kitty/tools/utils/style"
@ -819,8 +820,10 @@ func (self *Themes) ThemeByName(name string) *Theme {
return ans return ans
} }
func match(expression string, items []string) []string { func match(expression string, items []string) []*subseq.Match {
return nil matches := subseq.ScoreItems(expression, items, subseq.Options{Level1: " "})
matches = utils.StableSort(matches, func(a, b *subseq.Match) bool { return a.Score > b.Score })
return matches
} }
func (self *Themes) ApplySearch(expression string, marks ...string) []string { func (self *Themes) ApplySearch(expression string, marks ...string) []string {
@ -831,20 +834,16 @@ func (self *Themes) ApplySearch(expression string, marks ...string) []string {
results := match(expression, maps.Keys(self.name_map)) results := match(expression, maps.Keys(self.name_map))
name_map := make(map[string]*Theme, len(results)) name_map := make(map[string]*Theme, len(results))
ans := make([]string, 0, len(results)) ans := make([]string, 0, len(results))
for _, r := range results { for _, m := range results {
pos, k, _ := strings.Cut(r, ":") k := m.Text
positions := []int{} text := m.Text
for _, q := range strings.Split(pos, ",") { positions := m.Positions
i, _ := strconv.Atoi(q) for i := len(positions) - 1; i >= 0; i-- {
positions = append(positions, i) p := positions[i]
text := k text = text[:p] + mark_before + text[p:p+1] + mark_after + text[p+1:]
for i := len(positions) - 1; i >= 0; i-- {
p := positions[i]
text = text[:p] + mark_before + text[p:p+1] + mark_after + text[p+1:]
}
name_map[k] = self.name_map[k]
ans = append(ans, text)
} }
name_map[k] = self.name_map[k]
ans = append(ans, text)
} }
self.name_map = name_map self.name_map = name_map
self.index_map = maps.Keys(name_map) self.index_map = maps.Keys(name_map)