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.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'
|
||||||
|
|
||||||
|
|||||||
5
setup.py
5
setup.py
@ -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)
|
||||||
|
|||||||
@ -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,13 +834,10 @@ 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)
|
|
||||||
positions = append(positions, i)
|
|
||||||
text := k
|
|
||||||
for i := len(positions) - 1; i >= 0; i-- {
|
for i := len(positions) - 1; i >= 0; i-- {
|
||||||
p := positions[i]
|
p := positions[i]
|
||||||
text = text[:p] + mark_before + text[p:p+1] + mark_after + text[p+1:]
|
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]
|
name_map[k] = self.name_map[k]
|
||||||
ans = append(ans, text)
|
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)
|
||||||
return ans
|
return ans
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user