Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API: tree.resize #2598

Open
alex-courtis opened this issue Dec 24, 2023 · 2 comments · May be fixed by #2811
Open

API: tree.resize #2598

alex-courtis opened this issue Dec 24, 2023 · 2 comments · May be fixed by #2811
Labels
API API or Event feature request PR please nvim-tree team does not have the bandwidth to implement; a PR will be gratefully appreciated

Comments

@alex-courtis
Copy link
Member

alex-courtis commented Dec 24, 2023

Background: #2595

Add API similar to :NvimTreeResize.

tree.resize({opts})                              *nvim-tree-api.tree.resize()*
    Resize the tree, persisting the new size.
    Resets to |nvim-tree.view.width| when no {opts} provided.
    See |:NvimTreeResize|

    Parameters: ~{opts} (table) optional parameters

    Options: ~{width}    (table)  new |nvim-tree.view.width| value
      • {absolute} (number) set the width
      • {relative} (number) increase or decrease the width

    Only one option is supported, in the priority order above.
    {absolute} and {relative} do nothing when {width} is a function.

It may be best to have 3 methods due to the exclusive nature of the options. Look at api.txt and lua.txt for guidance.

@alex-courtis alex-courtis added feature request PR please nvim-tree team does not have the bandwidth to implement; a PR will be gratefully appreciated API API or Event labels Dec 24, 2023
@alex-courtis alex-courtis changed the title API: tree.width API: tree.resize Dec 25, 2023
@aminnairi
Copy link

If I'm correct, the type of the width option should reflect the one that is used in the nvim-tree.view.width as below.

      • {width} (string | number | table | function())  new |nvim-tree.view.width| value

Feel free to correct me if I'm being wrong here!

Also, I think the delta would be easier to work with if it is a number, since numbers can also be signed, and it will be much easier to apply a positive or negative delta if this is a number (IMO).

From my local tests, adding a string with a number works, but adding a non-number string would throw an error.

> "a" + 1
stdin:1: attempt to add a 'string' with a 'number'
stack traceback:
        [C]: in metamethod 'add'
        stdin:1: in main chunk
        [C]: in ?

Whereas adding a string-number with a number does work as intended.

> "-10" + 30
20

But this feels safer and more natural to do this with numbers. Your call here!

Also, I would have called this option offset since this is more of a widerly used term to talk about absolute/relative units. And after some brainstorming with myself, I think absolute and relative would make a lot more sense for a beginner trying to use this API, or even when reading back our code after some time.

require("nvim-tree.api").resize({absolute = 30}) -- For a width that is equal to 30

require("nvim-tree.api").resize({relative = -10}) -- For a width that is decreased by 10

require("nvim-tree.api").resize({relative = +5}) -- For a width that is increased by 5

require("nvim-tree.api").resize({relative = 5}) -- Same thing, since positive numbers do not need signs

Other than that, this looks good to me for a future PR. Thank you for your valuable work!

@alex-courtis
Copy link
Member Author

If I'm correct, the type of the width option should reflect the one that is used in the nvim-tree.view.width as below.

Thank you.

Also, I think the delta would be easier to work with if it is a number, since numbers can also be signed, and it will be much easier to apply a positive or negative delta if this is a number (IMO).

Of course.

I think absolute and relative would make a lot more sense for a beginner trying to use this API, or even when reading back our code after some time.

That could work. It's not necessary, however it would be easier.

opa-oz added a commit to opa-oz/nvim-tree.lua that referenced this issue Jun 24, 2024
@opa-oz opa-oz linked a pull request Jun 24, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API API or Event feature request PR please nvim-tree team does not have the bandwidth to implement; a PR will be gratefully appreciated
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants