Merge branch 'lite-xl:master' into lite-xl-windows-dark-theme-title-bar-support

This commit is contained in:
Nikolai Sinyov 2021-11-15 00:10:53 +03:00 committed by GitHub
commit 85fce63215
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 45 deletions

View File

@ -675,16 +675,18 @@ function core.load_plugins()
userdir = {dir = USERDIR, plugins = {}}, userdir = {dir = USERDIR, plugins = {}},
datadir = {dir = DATADIR, plugins = {}}, datadir = {dir = DATADIR, plugins = {}},
} }
local files = {} local files, ordered = {}, {}
for _, root_dir in ipairs {DATADIR, USERDIR} do for _, root_dir in ipairs {DATADIR, USERDIR} do
local plugin_dir = root_dir .. "/plugins" local plugin_dir = root_dir .. "/plugins"
for _, filename in ipairs(system.list_dir(plugin_dir) or {}) do for _, filename in ipairs(system.list_dir(plugin_dir) or {}) do
if not files[filename] then table.insert(ordered, filename) end
files[filename] = plugin_dir -- user plugins will always replace system plugins files[filename] = plugin_dir -- user plugins will always replace system plugins
end end
end end
table.sort(ordered)
for filename, plugin_dir in pairs(files) do for _, filename in ipairs(ordered) do
local basename = filename:match("(.-)%.lua$") or filename local plugin_dir, basename = files[filename], filename:match("(.-)%.lua$") or filename
local is_lua_file, version_match = check_plugin_version(plugin_dir .. '/' .. filename) local is_lua_file, version_match = check_plugin_version(plugin_dir .. '/' .. filename)
if is_lua_file then if is_lua_file then
if not version_match then if not version_match then

View File

@ -620,56 +620,32 @@ static int f_exec(lua_State *L) {
return 0; return 0;
} }
static int f_fuzzy_match(lua_State *L) { static int f_fuzzy_match(lua_State *L) {
size_t strLen, ptnLen; size_t strLen, ptnLen;
const char *str = luaL_checklstring(L, 1, &strLen); const char *str = luaL_checklstring(L, 1, &strLen);
const char *ptn = luaL_checklstring(L, 2, &ptnLen); const char *ptn = luaL_checklstring(L, 2, &ptnLen);
bool files = false; // If true match things *backwards*. This allows for better matching on filenames than the above
if (lua_gettop(L) > 2 && lua_isboolean(L,3))
files = lua_toboolean(L, 3);
int score = 0;
int run = 0;
// Match things *backwards*. This allows for better matching on filenames than the above
// function. For example, in the lite project, opening "renderer" has lib/font_render/build.sh // function. For example, in the lite project, opening "renderer" has lib/font_render/build.sh
// as the first result, rather than src/renderer.c. Clearly that's wrong. // as the first result, rather than src/renderer.c. Clearly that's wrong.
if (files) { bool files = lua_gettop(L) > 2 && lua_isboolean(L,3) && lua_toboolean(L, 3);
const char* strEnd = str + strLen - 1; int score = 0, run = 0, increment = files ? -1 : 1;
const char* ptnEnd = ptn + ptnLen - 1; const char* strTarget = files ? str + strLen - 1 : str;
while (strEnd >= str && ptnEnd >= ptn) { const char* ptnTarget = files ? ptn + ptnLen - 1 : ptn;
while (*strEnd == ' ') { strEnd--; } while (strTarget >= str && ptnTarget >= ptn && *strTarget && *ptnTarget) {
while (*ptnEnd == ' ') { ptnEnd--; } while (strTarget >= str && *strTarget == ' ') { strTarget += increment; }
if (tolower(*strEnd) == tolower(*ptnEnd)) { while (ptnTarget >= ptn && *ptnTarget == ' ') { ptnTarget += increment; }
score += run * 10 - (*strEnd != *ptnEnd); if (tolower(*strTarget) == tolower(*ptnTarget)) {
run++; score += run * 10 - (*strTarget != *ptnTarget);
ptnEnd--; run++;
} else { ptnTarget += increment;
score -= 10; } else {
run = 0; score -= 10;
} run = 0;
strEnd--;
} }
if (ptnEnd >= ptn) { return 0; } strTarget += increment;
} else {
while (*str && *ptn) {
while (*str == ' ') { str++; }
while (*ptn == ' ') { ptn++; }
if (tolower(*str) == tolower(*ptn)) {
score += run * 10 - (*str != *ptn);
run++;
ptn++;
} else {
score -= 10;
run = 0;
}
str++;
}
if (*ptn) { return 0; }
} }
if (ptnTarget >= ptn && *ptnTarget) { return 0; }
lua_pushnumber(L, score - (int)strLen); lua_pushnumber(L, score - (int)strLen * 10);
return 1; return 1;
} }