Add metadata to Command_Open and move the logic that denies the NextGotoBuild to lua

This commit is contained in:
Krzosa Karol
2025-05-09 09:17:45 +02:00
parent c57eedce49
commit d2ca655178
5 changed files with 86 additions and 36 deletions

View File

@@ -54,6 +54,15 @@ SDLK_X = 0x00000078
SDLK_Y = 0x00000079
SDLK_Z = 0x0000007a
function IsAlpha(a)
if a == nil then
return false
end
local x = string.byte(a)
local result = (x >= string.byte('a') and x <= string.byte('z')) or (x >= string.byte('A') and x <= string.byte('Z'))
return result
end
function SkipLineAndColumn(s)
local line, col = "1", "1"
@@ -163,7 +172,7 @@ function SkipPath(s)
return s, path, drive, cells
end
function MatchWindowsPath(_s)
function MatchWindowsPath(_s, meta)
local s, file_path, drive = SkipPath(_s)
if not file_path and FileExists(drive) then
@@ -186,7 +195,7 @@ function MatchWindowsPath(_s)
return {kind = "text", file_path = file_path, line = line, col = col}
end
function MatchGitCommit(s)
function MatchGitCommit(s, meta)
local i, j = string.find(s, "^commit ([a-zA-Z0-9]+)")
if i then
s = s:sub(8)
@@ -196,7 +205,7 @@ function MatchGitCommit(s)
return nil
end
function MatchURL(s)
function MatchURL(s, meta)
local i, j = string.find(s, "^https://")
if i then
return {kind = "exec_console", cmd = '"'..INTERNET_BROWSER..'" '..s, working_dir = GetMainDir()}
@@ -204,16 +213,34 @@ function MatchURL(s)
return nil
end
Rules = {
function MatchGotoBuild(s, meta)
if meta ~= "goto_build" then
return nil
end
local windows_path = IsAlpha(s:sub(1,1)) and s:sub(2,2) == ':'
local windows_rela = s:sub(1,1) == '.' and s:sub(2,2) == '\\'
local unix_path = s:sub(1,1) == '/'
local unix_rela = s:sub(1,1) == '.' and s:sub(2,2) == '/'
if not windows_path and not windows_rela and not unix_path and not windows_rela then
return {kind = "skip"}
end
return nil
end
OnOpenMatchers = {
MatchWindowsPath,
MatchGitCommit,
MatchURL,
MatchGotoBuild,
}
function OnOpen(s)
for i = #Rules,1,-1 do
rule = Rules[i]
result = rule(s)
function OnOpen(path, meta)
for i = #OnOpenMatchers,1,-1 do
rule = OnOpenMatchers[i]
result = rule(path, meta)
if result then
return result
end