Skip to content

feat: add config option for a tree indent width #1505

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

Merged
merged 8 commits into from
Aug 29, 2022

Conversation

mivort
Copy link
Contributor

@mivort mivort commented Aug 13, 2022

This PR adds 'indent_width' option to configure visible indent for tree nesting levels (default is 2). Both enabled and disabled indent markers are supported.

A little context: 9a02ded seemingly removed the ability to have a compact 1-symbol width indentations (and also without indent markers it was only possible to have a fixed 2-space indents, no more, no less). This PR adds ability to have a both smaller and larger (3+) indentations.

@mivort mivort force-pushed the configurable_indent_width branch from 42fbf37 to 632e56f Compare August 15, 2022 08:19
@mivort mivort marked this pull request as draft August 15, 2022 08:30
@mivort mivort force-pushed the configurable_indent_width branch from 632e56f to fdca4e7 Compare August 15, 2022 08:59
@mivort mivort marked this pull request as ready for review August 15, 2022 09:13
@mivort mivort requested a review from alex-courtis August 15, 2022 09:18
@alex-courtis
Copy link
Member

This is looking good; everything appears functional.

This is a complex piece of functionality that has experienced difficulties in the past.

I will:

  • exhaustively test manually
  • soak it for a week or so in a variety of configurations

@alex-courtis
Copy link
Member

alex-courtis commented Aug 16, 2022

When we have two character icons the bottom is indented too far. That is a result of the assumption that glyphs are a single character, which is reasonable.

20220816_104244 565x871

This is an edge case however we should deal with it.

Please:

  • in padding setup: trim icons to the first character; set to a single space if they are length 0.
  • add to the documentation: Icons shown before the file/directory. Length 1.

@alex-courtis
Copy link
Member

indent_width = 0 is "working" when indent markers enabled and disabled. What should we do when 0 and markers?

This is a questionable use case and adds complication e.g. local indent = string.rep(" ", M.config.indent_width - 1)

Let's remove it:

  • set to 1 when less than 1 in padding setup
  • add documentation Number of spaces for an each tree nesting level. Minimum 1.

@alex-courtis
Copy link
Member

alex-courtis commented Aug 16, 2022

Test Cases

indent_markers.enable = false

  • 1
  • 2
  • 3
  • 3 folder
  • 3 folder folder_arrow
  • 3 folder_arrow

indent_markers.enable = true

  • 1
  • 1 folder
  • 1 folder folder_arrow
  • 1 folder_arrow
  • 1 inline_arrows
  • 1 inline_arrows folder
  • 1 inline_arrows folder folder_arrow
  • 1 inline_arrows folder_arrow
  • 3
  • 3 folder
  • 3 folder folder_arrow
  • 3 folder_arrow
  • 3 inline_arrows
  • 3 inline_arrows folder
  • 3 inline_arrows folder folder_arrow
  • 3 inline_arrows folder_arrow

Copy link
Member

@alex-courtis alex-courtis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • minimum width 1
  • single character icons

@alex-courtis
Copy link
Member

This has worked well for a week in a variety of situations.

Discovered existing bug #1524 which can be fixed afterwards.

Will merge following changes #1505 (review)

@alex-courtis
Copy link
Member

alex-courtis commented Aug 27, 2022

  • minimum width 1
  • single character icons

Nudge @mivort

#1505 (comment)

@mivort mivort force-pushed the configurable_indent_width branch from 1d058df to 53cbba4 Compare August 29, 2022 09:08
@mivort
Copy link
Contributor Author

mivort commented Aug 29, 2022

@alex-courtis Sorry for the late update. I've updated doc and added checks for minimal indent width and marker symbol width.
Please take note I've used this solution to implement retrieval of the first UTF-8 character (since :sub(1, 1) doesn't properly handle multi-byte characters).

@alex-courtis
Copy link
Member

alex-courtis commented Aug 29, 2022

Retest da6a766

indent_markers.enable = false

  • 0
  • 1
  • 2
  • 3
  • 3 folder
  • 3 folder folder_arrow
  • 3 folder_arrow

indent_markers.enable = true

  • 0
  • 1
  • 1 folder
  • 1 folder folder_arrow
  • 1 folder_arrow
  • 1 inline_arrows
  • 1 inline_arrows folder
  • 1 inline_arrows folder folder_arrow
  • 1 inline_arrows folder_arrow
  • 3
  • 3 folder
  • 3 folder folder_arrow
  • 3 folder_arrow
  • 3 inline_arrows
  • 3 inline_arrows folder
  • 3 inline_arrows folder folder_arrow
  • 3 inline_arrows folder_arrow

@alex-courtis
Copy link
Member

@alex-courtis Sorry for the late update. I've updated doc and added checks for minimal indent width and marker symbol width. Please take note I've used this solution to implement retrieval of the first UTF-8 character (since :sub(1, 1) doesn't properly handle multi-byte characters).

Nice work.

Please add a comment, something like:
-- return the first character from the UTF-8 encoded string; we may use utf8.codes from Lua 5.3 when available

Testing now...

@mivort mivort force-pushed the configurable_indent_width branch from 712b7a3 to 05db624 Compare August 29, 2022 23:28
@alex-courtis
Copy link
Member

The recent update to nerd hack font has change the glyphs and they don't line up nicely any more:

20220830_094137 521x766

Fortunately that's unrelated to this change and everything here is working nicely.

@alex-courtis alex-courtis merged commit e8bf3d7 into nvim-tree:master Aug 29, 2022
@alex-courtis
Copy link
Member

Many thanks @mivort

We can now customise the tree to look exactly as we want.

@alex-courtis
Copy link
Member

The recent update to nerd hack font has change the glyphs and they don't line up nicely any more:

Resolution: #1561

Almo7aya pushed a commit to Almo7aya/nvim-tree.lua that referenced this pull request Oct 11, 2022
* feat: add config option for a tree indent width

add 'indent_width' option to configure visible indent for tree nesting
levels (default is 2).

* add 'bottom' char for a corner extension

* apply stylua formatting

* provide value constraints in documentation

* limit minimal indent width

* make marker symbols have one utf8 char width

* match stylua formatting

* add the commentary regarding utf-8 first symbol match
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants