fix(mpv-plugin): restore Lua parser compatibility

This commit is contained in:
2026-04-11 14:49:46 -07:00
parent 05cf4a6fe5
commit c71482cb44
5 changed files with 184 additions and 50 deletions

View File

@@ -55,33 +55,26 @@ function M.create(ctx)
if not image then
image = line:match('^"([^"]+)"')
end
if not image then
goto continue
end
if image == "subminer" or image == "subminer.exe" or image == "subminer.appimage" or image == "subminer.app" then
return true
end
if image:find("subminer", 1, true) and not image:find(".lua", 1, true) then
return true
if image then
if image == "subminer" or image == "subminer.exe" or image == "subminer.appimage" or image == "subminer.app" then
return true
end
if image:find("subminer", 1, true) and not image:find(".lua", 1, true) then
return true
end
end
else
local argv0 = line:match('^"([^"]+)"') or line:match("^%s*([^%s]+)")
if not argv0 then
goto continue
end
if argv0:find("subminer.lua", 1, true) or argv0:find("subminer.conf", 1, true) then
goto continue
end
local exe = argv0:match("([^/\\]+)$") or argv0
if exe == "SubMiner" or exe == "SubMiner.AppImage" or exe == "SubMiner.exe" or exe == "subminer" or exe == "subminer.appimage" or exe == "subminer.exe" then
return true
end
if exe:find("subminer", 1, true) and exe:find("%.lua", 1, true) == nil and exe:find("%.app", 1, true) == nil then
return true
if argv0 and not argv0:find("subminer.lua", 1, true) and not argv0:find("subminer.conf", 1, true) then
local exe = argv0:match("([^/\\]+)$") or argv0
if exe == "SubMiner" or exe == "SubMiner.AppImage" or exe == "SubMiner.exe" or exe == "subminer" or exe == "subminer.appimage" or exe == "subminer.exe" then
return true
end
if exe:find("subminer", 1, true) and exe:find("%.lua", 1, true) == nil and exe:find("%.app", 1, true) == nil then
return true
end
end
end
::continue::
end
return false
end

View File

@@ -189,41 +189,37 @@ function M.create(ctx)
local source_len = #plain
local cursor = 1
for _, token in ipairs(payload.tokens or {}) do
if type(token) ~= "table" or type(token.text) ~= "string" or token.text == "" then
goto continue
end
if type(token) == "table" and type(token.text) == "string" and token.text ~= "" then
local token_text = token.text
local start_pos = nil
local end_pos = nil
local token_text = token.text
local start_pos = nil
local end_pos = nil
if type(token.startPos) == "number" and type(token.endPos) == "number" then
if token.startPos >= 0 and token.endPos >= token.startPos then
local candidate_start = token.startPos + 1
local candidate_stop = token.endPos
if candidate_start >= 1 and candidate_stop <= source_len and candidate_stop >= candidate_start and plain:sub(candidate_start, candidate_stop) == token_text then
start_pos = candidate_start
end_pos = candidate_stop
if type(token.startPos) == "number" and type(token.endPos) == "number" then
if token.startPos >= 0 and token.endPos >= token.startPos then
local candidate_start = token.startPos + 1
local candidate_stop = token.endPos
if candidate_start >= 1 and candidate_stop <= source_len and candidate_stop >= candidate_start and plain:sub(candidate_start, candidate_stop) == token_text then
start_pos = candidate_start
end_pos = candidate_stop
end
end
end
end
if not start_pos or not end_pos then
local fallback_start, fallback_stop = plain:find(token_text, cursor, true)
if not fallback_start then
fallback_start, fallback_stop = plain:find(token_text, 1, true)
if not start_pos or not end_pos then
local fallback_start, fallback_stop = plain:find(token_text, cursor, true)
if not fallback_start then
fallback_start, fallback_stop = plain:find(token_text, 1, true)
end
start_pos, end_pos = fallback_start, fallback_stop
end
start_pos, end_pos = fallback_start, fallback_stop
end
if start_pos and end_pos then
if token.index == payload.hoveredTokenIndex then
return start_pos, end_pos
if start_pos and end_pos then
if token.index == payload.hoveredTokenIndex then
return start_pos, end_pos
end
cursor = end_pos + 1
end
cursor = end_pos + 1
end
::continue::
end
return nil