Skip to content

Commit

Permalink
feat: search first character of each word
Browse files Browse the repository at this point in the history
  • Loading branch information
christoph-heinrich committed Sep 23, 2023
1 parent 9628d32 commit 92821ce
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 5 additions & 2 deletions scripts/uosc/elements/Menu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -649,8 +649,11 @@ end
function Menu:search_internal(menu)
local query = menu.search.query:lower()
menu.items = query ~= '' and itable_filter(menu.search.source.items, function(item)
return item.title and item.title:lower():find(query, 1, true) or
item.hint and item.hint:lower():find(query, 1, true)
local title = item.title and item.title:lower()
local hint = item.hint and item.hint:lower()
return title and title:find(query, 1, true) or hint and hint:find(query, 1, true) or
title and table.concat(first_word_chars(title)):find(query, 1, true) or
hint and table.concat(first_word_chars(hint)):find(query, 1, true)
end) or menu.search.source.items
self:search_update_items()
end
Expand Down
8 changes: 8 additions & 0 deletions scripts/uosc/lib/text.lua
Original file line number Diff line number Diff line change
Expand Up @@ -460,3 +460,11 @@ function wrap_text(text, opts, target_line_length)
end
return table.concat(lines, '\n'), #lines
end

function first_word_chars(str)
local first_chars = {}
for w in str:gmatch('%w+') do
first_chars[#first_chars + 1] = w:sub(1, utf8_char_bytes(w, 1))
end
return first_chars
end

0 comments on commit 92821ce

Please sign in to comment.