feat: add min max boundary to width, hight resolver (#2002)
This commit is contained in:
committed by
Simon Hauser
parent
25b1bc8f17
commit
d1f3e12a35
@@ -1947,14 +1947,17 @@ Provides "resolver functions" to allow more customisable inputs for options.
|
||||
|
||||
resolver.resolve_height() *telescope.resolve.resolve_height()*
|
||||
Converts input to a function that returns the height. The input must take
|
||||
one of four forms:
|
||||
one of five forms:
|
||||
1. 0 <= number < 1
|
||||
This means total height as a percentage.
|
||||
2. 1 <= number
|
||||
This means total height as a fixed number.
|
||||
3. function
|
||||
Must have signature: function(self, max_columns, max_lines): number
|
||||
4. table of the form: {padding = `foo`}
|
||||
4. table of the form: { val, max = ..., min = ... }
|
||||
val has to be in the first form 0 <= val < 1 and only one is given,
|
||||
`min` or `max` as fixed number
|
||||
5. table of the form: {padding = `foo`}
|
||||
where `foo` has one of the previous three forms.
|
||||
The height is then set to be the remaining space after padding. For
|
||||
example, if the window has height 50, and the input is {padding = 5},
|
||||
@@ -1967,14 +1970,17 @@ resolver.resolve_height() *telescope.resolve.resolve_height()*
|
||||
|
||||
resolver.resolve_width() *telescope.resolve.resolve_width()*
|
||||
Converts input to a function that returns the width. The input must take
|
||||
one of four forms:
|
||||
one of five forms:
|
||||
1. 0 <= number < 1
|
||||
This means total width as a percentage.
|
||||
2. 1 <= number
|
||||
This means total width as a fixed number.
|
||||
3. function
|
||||
Must have signature: function(self, max_columns, max_lines): number
|
||||
4. table of the form: {padding = `foo`}
|
||||
4. table of the form: { val, max = ..., min = ... }
|
||||
val has to be in the first form 0 <= val < 1 and only one is given,
|
||||
`min` or `max` as fixed number
|
||||
5. table of the form: {padding = `foo`}
|
||||
where `foo` has one of the previous three forms.
|
||||
The width is then set to be the remaining space after padding. For
|
||||
example, if the window has width 100, and the input is {padding = 5},
|
||||
|
||||
@@ -127,9 +127,6 @@ end] = function(selector, val)
|
||||
end
|
||||
end
|
||||
|
||||
-- Tables TODO:
|
||||
-- ... {70, max}
|
||||
|
||||
-- function:
|
||||
-- Function must have same signature as get_window_layout
|
||||
-- function(self, max_columns, max_lines): number
|
||||
@@ -141,6 +138,26 @@ end] = function(_, val)
|
||||
return val
|
||||
end
|
||||
|
||||
_resolve_map[function(val)
|
||||
return type(val) == "table" and val[1] >= 0 and val[1] < 1 and val["max"] ~= nil
|
||||
end] =
|
||||
function(selector, val)
|
||||
return function(...)
|
||||
local selected = select(selector, ...)
|
||||
return math.min(math.floor(val[1] * selected), val["max"])
|
||||
end
|
||||
end
|
||||
|
||||
_resolve_map[function(val)
|
||||
return type(val) == "table" and val[1] >= 0 and val[1] < 1 and val["min"] ~= nil
|
||||
end] =
|
||||
function(selector, val)
|
||||
return function(...)
|
||||
local selected = select(selector, ...)
|
||||
return math.max(math.floor(val[1] * selected), val["min"])
|
||||
end
|
||||
end
|
||||
|
||||
-- Add padding option
|
||||
_resolve_map[function(val)
|
||||
return type(val) == "table" and val["padding"] ~= nil
|
||||
@@ -162,7 +179,7 @@ end] = function(selector, val)
|
||||
end
|
||||
|
||||
--- Converts input to a function that returns the height.
|
||||
--- The input must take one of four forms:
|
||||
--- The input must take one of five forms:
|
||||
--- 1. 0 <= number < 1 <br>
|
||||
--- This means total height as a percentage.
|
||||
--- 2. 1 <= number <br>
|
||||
@@ -170,7 +187,10 @@ end
|
||||
--- 3. function <br>
|
||||
--- Must have signature:
|
||||
--- function(self, max_columns, max_lines): number
|
||||
--- 4. table of the form: {padding = `foo`} <br>
|
||||
--- 4. table of the form: { val, max = ..., min = ... } <br>
|
||||
--- val has to be in the first form 0 <= val < 1 and only one is given,
|
||||
--- `min` or `max` as fixed number
|
||||
--- 5. table of the form: {padding = `foo`} <br>
|
||||
--- where `foo` has one of the previous three forms. <br>
|
||||
--- The height is then set to be the remaining space after padding.
|
||||
--- For example, if the window has height 50, and the input is {padding = 5},
|
||||
@@ -188,7 +208,7 @@ resolver.resolve_height = function(val)
|
||||
end
|
||||
|
||||
--- Converts input to a function that returns the width.
|
||||
--- The input must take one of four forms:
|
||||
--- The input must take one of five forms:
|
||||
--- 1. 0 <= number < 1 <br>
|
||||
--- This means total width as a percentage.
|
||||
--- 2. 1 <= number <br>
|
||||
@@ -196,7 +216,10 @@ end
|
||||
--- 3. function <br>
|
||||
--- Must have signature:
|
||||
--- function(self, max_columns, max_lines): number
|
||||
--- 4. table of the form: {padding = `foo`} <br>
|
||||
--- 4. table of the form: { val, max = ..., min = ... } <br>
|
||||
--- val has to be in the first form 0 <= val < 1 and only one is given,
|
||||
--- `min` or `max` as fixed number
|
||||
--- 5. table of the form: {padding = `foo`} <br>
|
||||
--- where `foo` has one of the previous three forms. <br>
|
||||
--- The width is then set to be the remaining space after padding.
|
||||
--- For example, if the window has width 100, and the input is {padding = 5},
|
||||
|
||||
@@ -75,6 +75,14 @@ describe("telescope.config.resolve", function()
|
||||
end
|
||||
end)
|
||||
|
||||
it("should handle percentages with min/max boundary", function()
|
||||
eq(20, resolve.resolve_width { 0.1, min = 20 }(nil, 40, 120))
|
||||
eq(30, resolve.resolve_height { 0.1, min = 20 }(nil, 40, 300))
|
||||
|
||||
eq(24, resolve.resolve_width { 0.4, max = 80 }(nil, 60, 60))
|
||||
eq(80, resolve.resolve_height { 0.4, max = 80 }(nil, 60, 300))
|
||||
end)
|
||||
|
||||
it("should handle fixed size", function()
|
||||
local fixed = { 5, 8, 13, 21, 34 }
|
||||
for _, s in ipairs(test_sizes) do
|
||||
|
||||
Reference in New Issue
Block a user