-
-
Notifications
You must be signed in to change notification settings - Fork 610
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat(#2598): Implemented API `tree.resize` * rely on when resize * Fix docs --------- Co-authored-by: Alexander Courtis <[email protected]>
- Loading branch information
1 parent
12a9a99
commit 2ede0de
Showing
5 changed files
with
107 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
local view = require "nvim-tree.view" | ||
|
||
local M = {} | ||
|
||
---Resize the tree, persisting the new size. | ||
---@param opts ApiTreeResizeOpts|nil | ||
function M.fn(opts) | ||
if opts == nil then | ||
-- reset to config values | ||
view.configure_width() | ||
view.resize() | ||
return | ||
end | ||
|
||
local options = opts or {} | ||
local width_cfg = options.width | ||
|
||
if width_cfg ~= nil then | ||
view.configure_width(width_cfg) | ||
view.resize() | ||
return | ||
end | ||
|
||
if not view.is_width_determined() then | ||
-- {absolute} and {relative} do nothing when {width} is a function. | ||
return | ||
end | ||
|
||
local absolute = options.absolute | ||
if type(absolute) == "number" then | ||
view.resize(absolute) | ||
return | ||
end | ||
|
||
local relative = options.relative | ||
if type(relative) == "number" then | ||
local relative_size = tostring(relative) | ||
if relative > 0 then | ||
relative_size = "+" .. relative_size | ||
end | ||
|
||
view.resize(relative_size) | ||
return | ||
end | ||
end | ||
|
||
function M.setup(opts) | ||
M.config = opts or {} | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters