Improve performance and fix index_event parsing
This commit is contained in:
parent
df9e9e93a5
commit
d1ba059652
|
@ -47,6 +47,10 @@ all attributes are lowercase.
|
|||
While I try to reduce backwards incompatibilities, sometimes they are necessary
|
||||
to either fix bugs in formspec_ast or for implementing new formspec features.
|
||||
|
||||
#### March 2021
|
||||
|
||||
- The `index_event` value for `dropdown` is now a boolean instead of a string.
|
||||
|
||||
#### February 2021
|
||||
|
||||
- The `close_on_enter` value for `field_close_on_enter` is now a boolean
|
||||
|
|
22
core.lua
22
core.lua
|
@ -401,22 +401,34 @@ end
|
|||
local compare_blanks
|
||||
do
|
||||
local function get_nonempty(a)
|
||||
local nonempty = 0
|
||||
if a.nonempty then
|
||||
return a.nonempty, a.strings
|
||||
end
|
||||
local nonempty, strings = 0, 0
|
||||
for _, i in ipairs(a) do
|
||||
if type(i) == 'string' and i ~= '' then
|
||||
nonempty = nonempty + 1
|
||||
strings = strings + 1
|
||||
elseif type(i) == 'table' then
|
||||
nonempty = nonempty + get_nonempty(i)
|
||||
end
|
||||
end
|
||||
a.nonempty = nonempty
|
||||
return nonempty
|
||||
a.nonempty, a.strings = nonempty, strings
|
||||
return nonempty, strings
|
||||
end
|
||||
|
||||
function compare_blanks(a, b)
|
||||
local a_n, b_n = get_nonempty(a), get_nonempty(b)
|
||||
local a_n, a_strings = get_nonempty(a)
|
||||
local b_n, b_strings = get_nonempty(b)
|
||||
if a_n == b_n then
|
||||
return #a < #b
|
||||
local a_l = #a
|
||||
local b_l = #b
|
||||
if a_l == b_l then
|
||||
-- Prefer elements with less tables
|
||||
return a_strings > b_strings
|
||||
else
|
||||
return a_l < b_l
|
||||
end
|
||||
end
|
||||
return a_n >= b_n
|
||||
end
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -114,7 +114,7 @@ dropdown:
|
|||
- - - [item, string]
|
||||
- '...'
|
||||
- [selected_idx, number]
|
||||
- [index_event, string]
|
||||
- [index_event, boolean]
|
||||
- - - [x, number]
|
||||
- [y, number]
|
||||
- [w, number]
|
||||
|
@ -122,7 +122,7 @@ dropdown:
|
|||
- - - [item, string]
|
||||
- '...'
|
||||
- [selected_idx, number]
|
||||
- [index_event, string]
|
||||
- [index_event, boolean]
|
||||
- - - [x, number]
|
||||
- [y, number]
|
||||
- - [w, number]
|
||||
|
|
|
@ -19,7 +19,7 @@ _known = _make_known(
|
|||
'frame_duration', 'frame_start'),
|
||||
boolean=('auto_clip', 'fixed_size', 'transparent', 'draw_border', 'bool',
|
||||
'noclip', 'drawborder', 'selected', 'force', 'close_on_enter',
|
||||
'continuous', 'mouse_control'),
|
||||
'continuous', 'mouse_control', 'index_event'),
|
||||
fullscreen=('fullscreen',),
|
||||
table=('param', 'opt', 'prop'),
|
||||
null=('',),
|
||||
|
|
11
tests.lua
11
tests.lua
|
@ -80,6 +80,7 @@ local fs = [[
|
|||
image[0,1;1,1;air.png]
|
||||
set_focus[name;true]
|
||||
dropdown[0,0;1;test;abc,def,ghi,jkl;2]
|
||||
dropdown[0,0;1;test;abc,def,ghi,jkl;2;true]
|
||||
field_close_on_enter[my-field;false]
|
||||
bgcolor[blue]
|
||||
bgcolor[blue;true]
|
||||
|
@ -168,6 +169,16 @@ test_parse_unparse(fs, {
|
|||
item = {"abc", "def", "ghi", "jkl"},
|
||||
selected_idx = 2,
|
||||
},
|
||||
{
|
||||
type = "dropdown",
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 1,
|
||||
name = "test",
|
||||
item = {"abc", "def", "ghi", "jkl"},
|
||||
selected_idx = 2,
|
||||
index_event = true,
|
||||
},
|
||||
{
|
||||
type = "field_close_on_enter",
|
||||
name = "my-field",
|
||||
|
|
Loading…
Reference in New Issue