Wire up the new subseq match code
This commit is contained in:
parent
29dd2438c9
commit
6794ec1de7
@ -22,8 +22,6 @@ from kitty.fast_data_types import Color
|
||||
from kitty.options.types import Options as KittyOptions
|
||||
from kitty.utils import reload_conf_in_all_kitties
|
||||
|
||||
from ..choose.match import match
|
||||
|
||||
MARK_BEFORE = '\033[33m'
|
||||
MARK_AFTER = '\033[39m'
|
||||
|
||||
|
||||
5
setup.py
5
setup.py
@ -819,11 +819,6 @@ def compile_kittens(compilation_database: CompilationDatabase) -> None:
|
||||
files('unicode_input', 'unicode_names'),
|
||||
files('diff', 'diff_speedup'),
|
||||
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.cflags.extend(f'-I{x}' for x in includes)
|
||||
|
||||
@ -20,6 +20,7 @@ import (
|
||||
|
||||
"kitty/tools/cli"
|
||||
"kitty/tools/config"
|
||||
"kitty/tools/tui/subseq"
|
||||
"kitty/tools/utils"
|
||||
"kitty/tools/utils/style"
|
||||
|
||||
@ -819,8 +820,10 @@ func (self *Themes) ThemeByName(name string) *Theme {
|
||||
return ans
|
||||
}
|
||||
|
||||
func match(expression string, items []string) []string {
|
||||
return nil
|
||||
func match(expression string, items []string) []*subseq.Match {
|
||||
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 {
|
||||
@ -831,13 +834,10 @@ func (self *Themes) ApplySearch(expression string, marks ...string) []string {
|
||||
results := match(expression, maps.Keys(self.name_map))
|
||||
name_map := make(map[string]*Theme, len(results))
|
||||
ans := make([]string, 0, len(results))
|
||||
for _, r := range results {
|
||||
pos, k, _ := strings.Cut(r, ":")
|
||||
positions := []int{}
|
||||
for _, q := range strings.Split(pos, ",") {
|
||||
i, _ := strconv.Atoi(q)
|
||||
positions = append(positions, i)
|
||||
text := k
|
||||
for _, m := range results {
|
||||
k := m.Text
|
||||
text := m.Text
|
||||
positions := m.Positions
|
||||
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:]
|
||||
@ -845,7 +845,6 @@ func (self *Themes) ApplySearch(expression string, marks ...string) []string {
|
||||
name_map[k] = self.name_map[k]
|
||||
ans = append(ans, text)
|
||||
}
|
||||
}
|
||||
self.name_map = name_map
|
||||
self.index_map = maps.Keys(name_map)
|
||||
return ans
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user