feat!: allow full height, width by resolving 1 as a percentage rather than absolute val (#2525)

this is technically a breaking change but i doubt anyone uses height/width 1 (absolute value). It makes more sense to treat 1 as 100%
This commit is contained in:
Simon Hauser
2023-05-24 12:27:19 +02:00
committed by GitHub
parent 80eefd8ff0
commit 066bda8ea4
2 changed files with 18 additions and 18 deletions

View File

@@ -2160,14 +2160,14 @@ Provides "resolver functions" to allow more customisable inputs for options.
resolver.resolve_height() *telescope.resolve.resolve_height()* resolver.resolve_height() *telescope.resolve.resolve_height()*
Converts input to a function that returns the height. The input must take Converts input to a function that returns the height. The input must take
one of five forms: one of five forms:
1. 0 <= number < 1 1. 0 <= number <= 1
This means total height as a percentage. This means total height as a percentage.
2. 1 <= number 2. 1 < number
This means total height as a fixed number. This means total height as a fixed number.
3. function 3. function
Must have signature: function(self, max_columns, max_lines): number Must have signature: function(self, max_columns, max_lines): number
4. table of the form: { val, max = ..., min = ... } 4. table of the form: { val, max = ..., min = ... }
val has to be in the first form 0 <= val < 1 and only one is given, val has to be in the first form 0 <= val <= 1 and only one is given,
`min` or `max` as fixed number `min` or `max` as fixed number
5. table of the form: {padding = `foo`} 5. table of the form: {padding = `foo`}
where `foo` has one of the previous three forms. where `foo` has one of the previous three forms.
@@ -2183,14 +2183,14 @@ resolver.resolve_height() *telescope.resolve.resolve_height()*
resolver.resolve_width() *telescope.resolve.resolve_width()* resolver.resolve_width() *telescope.resolve.resolve_width()*
Converts input to a function that returns the width. The input must take Converts input to a function that returns the width. The input must take
one of five forms: one of five forms:
1. 0 <= number < 1 1. 0 <= number <= 1
This means total width as a percentage. This means total width as a percentage.
2. 1 <= number 2. 1 < number
This means total width as a fixed number. This means total width as a fixed number.
3. function 3. function
Must have signature: function(self, max_columns, max_lines): number Must have signature: function(self, max_columns, max_lines): number
4. table of the form: { val, max = ..., min = ... } 4. table of the form: { val, max = ..., min = ... }
val has to be in the first form 0 <= val < 1 and only one is given, val has to be in the first form 0 <= val <= 1 and only one is given,
`min` or `max` as fixed number `min` or `max` as fixed number
5. table of the form: {padding = `foo`} 5. table of the form: {padding = `foo`}
where `foo` has one of the previous three forms. where `foo` has one of the previous three forms.

View File

@@ -38,10 +38,10 @@ Result of `resolve` should be a table with:
!!NOT IMPLEMENTED YET!! !!NOT IMPLEMENTED YET!!
height = height =
1. 0 <= number < 1 1. 0 <= number <= 1
This means total height as a percentage This means total height as a percentage
2. 1 <= number 2. 1 < number
This means total height as a fixed number This means total height as a fixed number
3. function(picker, columns, lines) 3. function(picker, columns, lines)
@@ -109,7 +109,7 @@ end
-- Percentages -- Percentages
_resolve_map[function(val) _resolve_map[function(val)
return type(val) == "number" and val >= 0 and val < 1 return type(val) == "number" and val >= 0 and val <= 1
end] = function(selector, val) end] = function(selector, val)
return function(...) return function(...)
local selected = select(selector, ...) local selected = select(selector, ...)
@@ -119,7 +119,7 @@ end
-- Numbers -- Numbers
_resolve_map[function(val) _resolve_map[function(val)
return type(val) == "number" and val >= 1 return type(val) == "number" and val > 1
end] = function(selector, val) end] = function(selector, val)
return function(...) return function(...)
local selected = select(selector, ...) local selected = select(selector, ...)
@@ -139,7 +139,7 @@ end] = function(_, val)
end end
_resolve_map[function(val) _resolve_map[function(val)
return type(val) == "table" and val["max"] ~= nil and val[1] ~= nil and val[1] >= 0 and val[1] < 1 return type(val) == "table" and val["max"] ~= nil and val[1] ~= nil and val[1] >= 0 and val[1] <= 1
end] = function( end] = function(
selector, selector,
val val
@@ -151,7 +151,7 @@ end] = function(
end end
_resolve_map[function(val) _resolve_map[function(val)
return type(val) == "table" and val["min"] ~= nil and val[1] ~= nil and val[1] >= 0 and val[1] < 1 return type(val) == "table" and val["min"] ~= nil and val[1] ~= nil and val[1] >= 0 and val[1] <= 1
end] = function( end] = function(
selector, selector,
val val
@@ -184,15 +184,15 @@ end
--- Converts input to a function that returns the height. --- Converts input to a function that returns the height.
--- The input must take one of five forms: --- The input must take one of five forms:
--- 1. 0 <= number < 1 <br> --- 1. 0 <= number <= 1 <br>
--- This means total height as a percentage. --- This means total height as a percentage.
--- 2. 1 <= number <br> --- 2. 1 < number <br>
--- This means total height as a fixed number. --- This means total height as a fixed number.
--- 3. function <br> --- 3. function <br>
--- Must have signature: --- Must have signature:
--- function(self, max_columns, max_lines): number --- function(self, max_columns, max_lines): number
--- 4. table of the form: { val, max = ..., min = ... } <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, --- val has to be in the first form 0 <= val <= 1 and only one is given,
--- `min` or `max` as fixed number --- `min` or `max` as fixed number
--- 5. table of the form: {padding = `foo`} <br> --- 5. table of the form: {padding = `foo`} <br>
--- where `foo` has one of the previous three forms. <br> --- where `foo` has one of the previous three forms. <br>
@@ -213,15 +213,15 @@ end
--- Converts input to a function that returns the width. --- Converts input to a function that returns the width.
--- The input must take one of five forms: --- The input must take one of five forms:
--- 1. 0 <= number < 1 <br> --- 1. 0 <= number <= 1 <br>
--- This means total width as a percentage. --- This means total width as a percentage.
--- 2. 1 <= number <br> --- 2. 1 < number <br>
--- This means total width as a fixed number. --- This means total width as a fixed number.
--- 3. function <br> --- 3. function <br>
--- Must have signature: --- Must have signature:
--- function(self, max_columns, max_lines): number --- function(self, max_columns, max_lines): number
--- 4. table of the form: { val, max = ..., min = ... } <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, --- val has to be in the first form 0 <= val <= 1 and only one is given,
--- `min` or `max` as fixed number --- `min` or `max` as fixed number
--- 5. table of the form: {padding = `foo`} <br> --- 5. table of the form: {padding = `foo`} <br>
--- where `foo` has one of the previous three forms. <br> --- where `foo` has one of the previous three forms. <br>