Skip to content

Commit 9f8d18b

Browse files
committed
fix: patch tpl values to convert empty strings to nil
1 parent a7c4506 commit 9f8d18b

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

lua/simplegpt/tpl.lua

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,19 @@ function M.RegQAUI:get_special()
359359
return res
360360
end
361361

362+
-- NOTE: jijia.nvim has some bug when rendering if logic. {% if p %} will be rendered as true if p == "";
363+
-- So we need to patch it to convert empty string
364+
-- - you can test by `print(require"jinja".lupa.expand("| {% if p %}GOOD{% endif %} |", {p=""}))`
365+
function M.patch_tpl_values(tpl_values)
366+
for k, v in pairs(tpl_values) do
367+
-- Convert empty string or whitespace-only values to nil
368+
if v == "" then
369+
tpl_values[k] = nil
370+
end
371+
end
372+
return tpl_values
373+
end
374+
362375

363376
function M.RegQAUI:get_tpl_values()
364377
local tpl_values = {}
@@ -388,7 +401,8 @@ function M.RegQAUI:get_q()
388401
-- return require('jinja').lupa.expand(s, t)
389402
return require('jinja').lupa.expand(s, tab)
390403
end
391-
return interp(M.get_tpl(), self:get_tpl_values())
404+
405+
return interp(M.get_tpl(), M.patch_tpl_values(self:get_tpl_values()))
392406
end
393407

394408
--- register common keys for dialogs

0 commit comments

Comments
 (0)