Skip to content

Conversation

opa-oz
Copy link
Contributor

@opa-oz opa-oz commented Jun 24, 2024

Resolved #2598

Testing environment

I slightly modified useState analogy to follow proposed API specification:

local resize = require("nvim-tree.api").tree.resize
local function use_nvim_tree_width(options)
	if type(options) ~= "table" then
		return
	end

	---@type number
	local offset = options.offset

	if type(offset) ~= "number" then
		offset = 10
	end

	---@type number|table
	local width = 30

	local function get_width()
		return width
	end

	local function increment_width()
		resize({ relative = offset }) -- <==== here
	end

	local function decrement_width()
		resize({ relative = -offset }) -- <==== here
	end

	local function dynamic_width()
		width = {}
		resize({ width = width }) -- <==== here
	end

	return get_width, increment_width, decrement_width, dynamic_width
end

Small showcase:
ScreenRecording2024-06-24at13 13 30-ezgif com-video-to-gif-converter

GIF explanation:

  1. Increase
  2. Increase
  3. Increase
  4. Decrease
  5. Dynamic width

@opa-oz opa-oz marked this pull request as ready for review June 24, 2024 04:19
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.

Apologies for the delay.

Works beautifully.

Tested base cases and changing width from and to function.

A couple of small questions and you'll need to update help.

Many thanks for your contribution!

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.

Many thanks for your contribution!

@alex-courtis alex-courtis changed the title feat(#2598): Implemented API tree.resize feat(#2598): add api.tree.resize Jul 11, 2024
@alex-courtis alex-courtis merged commit 2ede0de into nvim-tree:master Jul 11, 2024
@opa-oz opa-oz deleted the 2598-resize-api branch July 12, 2024 05:16
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.

API: tree.resize

2 participants