diff options
| author | Luke Kershaw <35707277+l-kershaw@users.noreply.github.com> | 2021-07-02 07:50:55 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-02 08:50:55 +0200 |
| commit | 50001d4965af3c95614b1423ab6d130068319cd9 (patch) | |
| tree | 9120d114b4713259ba9ab10a70261a98fe9c0b3f /lua | |
| parent | 5a53ec5c2fdab10ca8775d3979b1a85e63d57953 (diff) | |
fix: table number option extend (#947)
* fix: prevent error when overriding tables with numbers
Fixes #944
- refactor `config.smarter_depth_2_extend`
- use `config.smarter_depth_2_extend` for setting `layout_config` in `Picker:new`
* test: check that can override a table with a number for layout configuration
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/telescope/config.lua | 9 | ||||
| -rw-r--r-- | lua/telescope/pickers.lua | 2 | ||||
| -rw-r--r-- | lua/tests/automated/layout_strategies_spec.lua | 10 |
3 files changed, 19 insertions, 2 deletions
diff --git a/lua/telescope/config.lua b/lua/telescope/config.lua index aecfcc6..847f067 100644 --- a/lua/telescope/config.lua +++ b/lua/telescope/config.lua @@ -35,7 +35,13 @@ local smarter_depth_2_extend = function(priority, base) end end end - result = vim.tbl_deep_extend("keep", priority, result) + for key, val in pairs(priority) do + if type(val) ~= "table" then + result[key] = first_non_null(val,result[key]) + else + result[key] = vim.tbl_extend("keep",val,result[key] or {}) + end + end return result end @@ -43,6 +49,7 @@ end -- selection_strategy local config = {} +config.smarter_depth_2_extend = smarter_depth_2_extend config.values = _TelescopeConfigurationValues config.descriptions = {} diff --git a/lua/telescope/pickers.lua b/lua/telescope/pickers.lua index 28046e5..f8a0eea 100644 --- a/lua/telescope/pickers.lua +++ b/lua/telescope/pickers.lua @@ -99,7 +99,7 @@ function Picker:new(opts) selection_strategy = get_default(opts.selection_strategy, config.values.selection_strategy), layout_strategy = layout_strategy, - layout_config = vim.tbl_deep_extend("keep", opts.layout_config or {}, config.values.layout_config or {}), + layout_config = config.smarter_depth_2_extend(opts.layout_config or {}, config.values.layout_config or {}), window = { winblend = get_default(opts.winblend, config.values.winblend), diff --git a/lua/tests/automated/layout_strategies_spec.lua b/lua/tests/automated/layout_strategies_spec.lua index a4d2c50..f8f8b02 100644 --- a/lua/tests/automated/layout_strategies_spec.lua +++ b/lua/tests/automated/layout_strategies_spec.lua @@ -89,4 +89,14 @@ describe('layout_strategies', function() {horizontal={height=50}}, {horizontal={height=100}}, {height=120} ) + test_defaults_key("should handle user config overriding a table with a number", + 'height','horizontal',120, + {height={padding=5}},{height=120},{} + ) + + test_defaults_key("should handle user oneshot overriding a table with a number", + 'height','horizontal',120, + {},{height={padding=5}},{height=120} + ) + end) |
